Search in sources :

Example 1 with WASDListener

use of com.cas.sim.tis.app.listener.WASDListener in project TeachingInSimulation by ScOrPiOzzy.

the class SceneCameraState method initializeLocal.

@Override
public void initializeLocal() {
    // 初始化相机
    cam.setLocation(new Vector3f(0, 10, 10));
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
    // 添加鼠标监听事件
    inputManager.addMapping("MouseAxisX", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping("MouseAxisY", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("MouseAxisX-", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("MouseAxisY-", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("MouseWheel", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    inputManager.addMapping("MouseWheel-", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    inputManager.addMapping("MouseButtonLeft", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("MouseButtonMiddle", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addMapping("MouseButtonRight", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("ShiftModifier", new KeyTrigger(KeyInput.KEY_LSHIFT));
    // 注册监听
    inputManager.addListener(this, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight", "ShiftModifier");
    // 设置相机视锥
    float aspect = (float) cam.getWidth() / cam.getHeight();
    cam.setParallelProjection(false);
    cam.setFrustumPerspective(45f, aspect, 0.01f, 1000);
    camera = new WASDListener(cam);
    camera.registerWithInput(inputManager);
}
Also used : Vector3f(com.jme3.math.Vector3f) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) KeyTrigger(com.jme3.input.controls.KeyTrigger) WASDListener(com.cas.sim.tis.app.listener.WASDListener) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Aggregations

WASDListener (com.cas.sim.tis.app.listener.WASDListener)1 KeyTrigger (com.jme3.input.controls.KeyTrigger)1 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)1 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)1 Vector3f (com.jme3.math.Vector3f)1