Search in sources :

Example 31 with MouseButtonTrigger

use of com.jme3.input.controls.MouseButtonTrigger 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

MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)27 KeyTrigger (com.jme3.input.controls.KeyTrigger)12 ActionListener (com.jme3.input.controls.ActionListener)9 Material (com.jme3.material.Material)9 Vector3f (com.jme3.math.Vector3f)9 Geometry (com.jme3.scene.Geometry)9 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)7 Box (com.jme3.scene.shape.Box)7 Quaternion (com.jme3.math.Quaternion)5 Node (com.jme3.scene.Node)5 BulletAppState (com.jme3.bullet.BulletAppState)4 Sphere (com.jme3.scene.shape.Sphere)4 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)3 AnalogListener (com.jme3.input.controls.AnalogListener)3 DirectionalLight (com.jme3.light.DirectionalLight)3 ColorRGBA (com.jme3.math.ColorRGBA)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 JmeUtil (com.cas.sim.tis.util.JmeUtil)2 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)2 BitmapText (com.jme3.font.BitmapText)2