⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omkeybehavior.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/j3d/com/bbn/openmap/tools/j3d/OMKeyBehavior.java,v $// $RCSfile: OMKeyBehavior.java,v $// $Revision: 1.3.2.2 $// $Date: 2005/08/11 21:03:15 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.tools.j3d;import java.awt.AWTEvent;import java.awt.event.*;import java.util.Enumeration;import javax.media.j3d.*;import javax.vecmath.*;import com.bbn.openmap.util.Debug;import com.bbn.openmap.proj.Projection;/** * OMKeyBehavior is a modified version of KeyBehavior, available from * http://www.J3D.org. The modifications include having a notion of * body position, and view position. You can modify a view, which can * be thought of as where your eyes are pointing. You can also modify * the position, which can be thought of where your body is pointing. * So, you can look in a different directin than your motion.This * allows the user to adjust the view angle to the map, but not have * it interfere with navigation - for instance, you can look down at * the ground, but not fly into it, instead keeping a constant * distance above it. *  * <P> * The controls are: *  * <pre> *  *  left - turn left *  right - turn right *  up - move forward *  down - move backward *  *  Cntl left - look down *  Cntl right - look up *  Cntl up - move up (elevation) *  Cntl down - move down (elevation) *  *  Alt right - move right *  Alt left - move left *  Alt up - rotate up (movement forward will increase elevation). *  Alt down - rotate down (movement forward will decrease elevation). *  *   * </pre> *  * From the original KeyBehavier header: *  * <pre> *  *   KeyBehavior is a generic behavior class to take key presses and move a *   TransformGroup through a Java3D scene. The actions resulting from the key strokes *   are modified by using the Ctrl, Alt and Shift keys. *  *   (version 1.0) reconstructed class to make more generic. *  *  MODIFIED: *  *  *  @author    Andrew AJ Cain, Swinburne University, *       Australia &lt;acain@it.swin.edu.au&gt; edited from code *       by: Gary S. Moss &lt;moss@arl.mil&gt; U. S. Army Research *       Laboratory * CLASS NAME: KeyBehavior PUBLIC *       FEATURES: // Data // Constructors // Methods: *       COLLABORATORS:  * </pre> *  * @version 1.0, 25 September 1998 aajc */public class OMKeyBehavior extends Behavior {    protected final static double FAST_SPEED = 2.0;    protected final static double NORMAL_SPEED = 1.0;    protected final static double SLOW_SPEED = 0.5;    private TransformGroup cameraTransformGroup;    private Transform3D transform3D;    private Transform3D locationTransform3D;    private Transform3D xRotLookTransform;    private Transform3D yRotLookTransform;    private Transform3D zRotLookTransform;    private WakeupCondition keyCriterion;    protected final static double TWO_PI = (2.0 * Math.PI);    protected double rotateXAmount = Math.PI / 16.0;    protected double rotateYAmount = Math.PI / 16.0;    protected double rotateZAmount = Math.PI / 16.0;    protected double moveRate = 0.3;    protected double speed = NORMAL_SPEED;    protected int forwardKey = KeyEvent.VK_UP;    protected int backKey = KeyEvent.VK_DOWN;    protected int leftKey = KeyEvent.VK_LEFT;    protected int rightKey = KeyEvent.VK_RIGHT;    protected boolean DEBUG = false;    protected Projection projection;    public OMKeyBehavior(TransformGroup cameraTG, Projection proj) {        this(cameraTG, proj, null);    }    public OMKeyBehavior(TransformGroup cameraTG, Projection proj,            Vector3d initialLocation) {        projection = proj;        DEBUG = Debug.debugging("3dkey");        cameraTransformGroup = cameraTG;        transform3D = new Transform3D();        locationTransform3D = new Transform3D();        // These are the looking transforms, for the view.        xRotLookTransform = new Transform3D();        yRotLookTransform = new Transform3D();        zRotLookTransform = new Transform3D();        setViewerLocation(initialLocation);        setEnable(true);    }    public void initialize() {        WakeupCriterion[] keyEvents = new WakeupCriterion[2];        keyEvents[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);        keyEvents[1] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);        keyCriterion = new WakeupOr(keyEvents);        wakeupOn(keyCriterion);    }    public void setViewerLocation(Vector3d initialLocation) {        cameraTransformGroup.getTransform(locationTransform3D);        // scale of < 1 shrinks the object. (.5) is the scale.        float scale = 1f;        if (initialLocation == null) {            initialLocation = new Vector3d();            // So, this lays out where the land is, in relation to the            // viewer. We should get the projection from the MapBean,            // and            // offset the transform to the middle of the map.            if (projection != null) {                float centerXOffset = projection.getWidth() / 2f * scale;                float centerYOffset = projection.getHeight() * 2 / 3f * scale;                Debug.message("3d", "OM3DViewer with projection " + projection                        + ", setting center of scene to " + centerXOffset                        + ", " + centerYOffset);                initialLocation.set((double) centerXOffset,                        (double) 50,                        (double) centerYOffset);            } else {                initialLocation.set(0.0, 50, 0.0);            }        }        Transform3D toMove = new Transform3D();        toMove.set(scale, initialLocation);        locationTransform3D.mul(toMove);        cameraTransformGroup.setTransform(locationTransform3D);    }    public void processStimulus(Enumeration criteria) {        if (DEBUG) {            Debug.output("OMKeyBehavior: processStimulus");        }        WakeupCriterion wakeup;        AWTEvent[] event;        while (criteria.hasMoreElements()) {            wakeup = (WakeupCriterion) criteria.nextElement();            if (!(wakeup instanceof WakeupOnAWTEvent)) {                continue;            }            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();            for (int i = 0; i < event.length; i++) {                if (event[i].getID() == KeyEvent.KEY_PRESSED) {                    processKeyEvent((KeyEvent) event[i]);                }            }        }        wakeupOn(keyCriterion);    }    protected void processKeyEvent(KeyEvent event) {        int keycode = event.getKeyCode();        if (event.isShiftDown()) {            speed = FAST_SPEED;        } else {            speed = NORMAL_SPEED;        }        if (event.isAltDown()) {            altMove(keycode);        } else if (event.isControlDown()) {            controlMove(keycode);        } else {            standardMove(keycode);        }    }    //moves forward backward or rotates left right    protected void standardMove(int keycode) {        if (keycode == forwardKey) {            moveForward();        } else if (keycode == backKey) {            moveBackward();        } else if (keycode == leftKey) {            rotLeft();        } else if (keycode == rightKey) {            rotRight();        }    }    //moves left right, rotate up down    protected void altMove(int keycode) {        if (DEBUG) {            Debug.output("altMove");        }        if (keycode == forwardKey) {            rotUp();        } else if (keycode == backKey) {            rotDown();        } else if (keycode == leftKey) {            moveLeft();        } else if (keycode == rightKey) {            moveRight();        }    }    //move up down, rot left right    protected void controlMove(int keycode) {        if (keycode == forwardKey) {            moveUp();        } else if (keycode == backKey) {            moveDown();        } else if (keycode == leftKey) {            //          rollLeft();            lookUp();        } else if (keycode == rightKey) {            //          rollRight();            lookDown();        }    }    public void moveForward() {        if (DEBUG) {            Debug.output("Moving forward +");        }        doMove(new Vector3d(0.0, 0.0, -getMovementRate()));    }    public void moveBackward() {        if (DEBUG) {            Debug.output("Moving Backward _");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -