Search in sources :

Example 16 with InputManager

use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.

the class TestAppStates method initialize.

@Override
public void initialize() {
    super.initialize();
    System.out.println("Initialize");
    RootNodeState state = new RootNodeState();
    viewPort.attachScene(state.getRootNode());
    stateManager.attach(state);
    Spatial model = assetManager.loadModel("Models/Teapot/Teapot.obj");
    model.scale(3);
    model.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m"));
    state.getRootNode().attachChild(model);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    niftyDisplay.getNifty().fromXml("Interface/Nifty/HelloJme.xml", "start");
    guiViewPort.addProcessor(niftyDisplay);
}
Also used : NiftyJmeDisplay(com.jme3.niftygui.NiftyJmeDisplay) Spatial(com.jme3.scene.Spatial)

Example 17 with InputManager

use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.

the class TestMotionPath method simpleInitApp.

@Override
public void simpleInitApp() {
    createScene();
    cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
    path = new MotionPath();
    path.addWayPoint(new Vector3f(10, 3, 0));
    path.addWayPoint(new Vector3f(10, 3, 10));
    path.addWayPoint(new Vector3f(-40, 3, 10));
    path.addWayPoint(new Vector3f(-40, 3, 0));
    path.addWayPoint(new Vector3f(-40, 8, 0));
    path.addWayPoint(new Vector3f(10, 8, 0));
    path.addWayPoint(new Vector3f(10, 8, 10));
    path.addWayPoint(new Vector3f(15, 8, 10));
    path.enableDebugShape(assetManager, rootNode);
    motionControl = new MotionEvent(teapot, path);
    motionControl.setDirectionType(MotionEvent.Direction.PathAndRotation);
    motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
    motionControl.setInitialDuration(10f);
    motionControl.setSpeed(2f);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    final BitmapText wayPointsText = new BitmapText(guiFont, false);
    wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
    guiNode.attachChild(wayPointsText);
    path.addListener(new MotionPathListener() {

        public void onWayPointReach(MotionEvent control, int wayPointIndex) {
            if (path.getNbWayPoints() == wayPointIndex + 1) {
                wayPointsText.setText(control.getSpatial().getName() + "Finished!!! ");
            } else {
                wayPointsText.setText(control.getSpatial().getName() + " Reached way point " + wayPointIndex);
            }
            wayPointsText.setLocalTranslation((cam.getWidth() - wayPointsText.getLineWidth()) / 2, cam.getHeight(), 0);
        }
    });
    flyCam.setEnabled(false);
    ChaseCamera chaser = new ChaseCamera(cam, teapot);
    //        motionControl.setSpeed(-3f);
    //        motionControl.setLoopMode(LoopMode.Loop);
    //        path.setCycle(true);
    // chaser.setEnabled(false);
    chaser.registerWithInput(inputManager);
    initInputs();
}
Also used : MotionPathListener(com.jme3.cinematic.MotionPathListener) BitmapText(com.jme3.font.BitmapText) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) ChaseCamera(com.jme3.input.ChaseCamera) MotionPath(com.jme3.cinematic.MotionPath) MotionEvent(com.jme3.cinematic.events.MotionEvent)

Example 18 with InputManager

use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.

the class TestHoveringTank method buildPlayer.

private void buildPlayer() {
    spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
    spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
    spaceCraft.setLocalTranslation(new Vector3f(-140, 50, -23));
    spaceCraft.setLocalRotation(new Quaternion(new float[] { 0, 0.01f, 0 }));
    hoverControl = new PhysicsHoverControl(colShape, 500);
    spaceCraft.addControl(hoverControl);
    rootNode.attachChild(spaceCraft);
    getPhysicsSpace().add(hoverControl);
    hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    spaceCraft.addControl(chaseCam);
    flyCam.setEnabled(false);
}
Also used : BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) ChaseCamera(com.jme3.input.ChaseCamera)

Example 19 with InputManager

use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.

the class BasicProfilerState method initialize.

@Override
protected void initialize(Application app) {
    graph = new Geometry("profiler", profiler.getMesh());
    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setBoolean("VertexColor", true);
    graph.setMaterial(mat);
    graph.setLocalTranslation(0, 300, 0);
    graph.setLocalScale(1, scale, 1);
    Mesh mesh = new Mesh();
    background = new Geometry("profiler.background", mesh);
    mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setBoolean("VertexColor", true);
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    background.setMaterial(mat);
    background.setLocalTranslation(0, 300, -1);
    background.setLocalScale(1, scale, 1);
    refreshBackground();
    InputManager inputManager = app.getInputManager();
    if (inputManager != null) {
        inputManager.addMapping(INPUT_MAPPING_PROFILER_TOGGLE, new KeyTrigger(KeyInput.KEY_F6));
        inputManager.addListener(keyListener, INPUT_MAPPING_PROFILER_TOGGLE);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) KeyTrigger(com.jme3.input.controls.KeyTrigger) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) InputManager(com.jme3.input.InputManager)

Example 20 with InputManager

use of com.jme3.input.InputManager in project jmonkeyengine by jMonkeyEngine.

the class BasicProfilerState method cleanup.

@Override
protected void cleanup(Application app) {
    InputManager inputManager = app.getInputManager();
    if (inputManager.hasMapping(INPUT_MAPPING_PROFILER_TOGGLE)) {
        inputManager.deleteMapping(INPUT_MAPPING_PROFILER_TOGGLE);
    }
    inputManager.removeListener(keyListener);
}
Also used : InputManager(com.jme3.input.InputManager)

Aggregations

Vector3f (com.jme3.math.Vector3f)16 Geometry (com.jme3.scene.Geometry)16 Material (com.jme3.material.Material)14 FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 DirectionalLight (com.jme3.light.DirectionalLight)13 ChaseCamera (com.jme3.input.ChaseCamera)11 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 Quaternion (com.jme3.math.Quaternion)11 Spatial (com.jme3.scene.Spatial)10 Box (com.jme3.scene.shape.Box)8 BitmapText (com.jme3.font.BitmapText)7 Node (com.jme3.scene.Node)7 ActionListener (com.jme3.input.controls.ActionListener)6 NiftyJmeDisplay (com.jme3.niftygui.NiftyJmeDisplay)6 AmbientLight (com.jme3.light.AmbientLight)5 SSAOFilter (com.jme3.post.ssao.SSAOFilter)5 InputManager (com.jme3.input.InputManager)4 BloomFilter (com.jme3.post.filters.BloomFilter)4 Quad (com.jme3.scene.shape.Quad)4 Sphere (com.jme3.scene.shape.Sphere)4