Search in sources :

Example 91 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestReadWrite method createControls.

/**
     * Create the save and load actions and add them to the input listener
     */
private void createControls() {
    flyCam.setMoveSpeed(50);
    cam.setLocation(new Vector3f(0, 100, 0));
    inputManager.addMapping("save", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(saveActionListener, "save");
    inputManager.addMapping("load", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addListener(loadActionListener, "load");
    inputManager.addMapping("clone", new KeyTrigger(KeyInput.KEY_C));
    inputManager.addListener(cloneActionListener, "clone");
}
Also used : Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 92 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestLodGeneration method simpleInitApp.

public void simpleInitApp() {
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.6f));
    rootNode.addLight(al);
    // model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
    BoundingBox b = ((BoundingBox) model.getWorldBound());
    model.setLocalScale(1.2f / (b.getYExtent() * 2));
    //  model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0);
    for (Spatial spatial : model.getChildren()) {
        if (spatial instanceof Geometry) {
            listGeoms.add((Geometry) spatial);
        }
    }
    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    model.addControl(chaseCam);
    chaseCam.setLookAtOffset(b.getCenter());
    chaseCam.setDefaultDistance(5);
    chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);
    chaseCam.setZoomSensitivity(0.5f);
    //           ch = model.getControl(AnimControl.class).createChannel();
    //          ch.setAnim("Wave");
    SkeletonControl c = model.getControl(SkeletonControl.class);
    if (c != null) {
        c.setEnabled(false);
    }
    reductionvalue = 0.80f;
    lodLevel = 1;
    for (final Geometry geometry : listGeoms) {
        LodGenerator lodGenerator = new LodGenerator(geometry);
        lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
        geometry.setLodLevel(lodLevel);
    }
    rootNode.attachChild(model);
    flyCam.setEnabled(false);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    hudText = new BitmapText(guiFont, false);
    hudText.setSize(guiFont.getCharSet().getRenderedSize());
    hudText.setText(computeNbTri() + " tris");
    hudText.setLocalTranslation(cam.getWidth() / 2, hudText.getLineHeight(), 0);
    guiNode.attachChild(hudText);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("plus")) {
                    //                        lodLevel++;
                    //                        for (Geometry geometry : listGeoms) {
                    //                            if (geometry.getMesh().getNumLodLevels() <= lodLevel) {
                    //                                lodLevel = 0;
                    //                            }
                    //                            geometry.setLodLevel(lodLevel);
                    //                        }
                    //                        jaimeText.setText(computeNbTri() + " tris");
                    reductionvalue += 0.05f;
                    updateLod();
                }
                if (name.equals("minus")) {
                    //                        lodLevel--;
                    //                        for (Geometry geometry : listGeoms) {
                    //                            if (lodLevel < 0) {
                    //                                lodLevel = geometry.getMesh().getNumLodLevels() - 1;
                    //                            }
                    //                            geometry.setLodLevel(lodLevel);
                    //                        }
                    //                        jaimeText.setText(computeNbTri() + " tris");
                    reductionvalue -= 0.05f;
                    updateLod();
                }
                if (name.equals("wireFrame")) {
                    wireFrame = !wireFrame;
                    for (Geometry geometry : listGeoms) {
                        geometry.getMaterial().getAdditionalRenderState().setWireframe(wireFrame);
                    }
                }
            }
        }

        private void updateLod() {
            reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f);
            makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1);
        }
    }, "plus", "minus", "wireFrame");
    inputManager.addMapping("plus", new KeyTrigger(KeyInput.KEY_ADD));
    inputManager.addMapping("minus", new KeyTrigger(KeyInput.KEY_SUBTRACT));
    inputManager.addMapping("wireFrame", new KeyTrigger(KeyInput.KEY_SPACE));
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) SkeletonControl(com.jme3.animation.SkeletonControl) Geometry(com.jme3.scene.Geometry) LodGenerator(jme3tools.optimize.LodGenerator) BitmapText(com.jme3.font.BitmapText) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) AmbientLight(com.jme3.light.AmbientLight)

Example 93 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestLineWidthRenderState method simpleInitApp.

@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    cam.setLocation(new Vector3f(5.5826545f, 3.6192513f, 8.016988f));
    cam.setRotation(new Quaternion(-0.04787097f, 0.9463123f, -0.16569641f, -0.27339742f));
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    mat.getAdditionalRenderState().setWireframe(true);
    mat.getAdditionalRenderState().setLineWidth(2);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("up") && isPressed) {
                mat.getAdditionalRenderState().setLineWidth(mat.getAdditionalRenderState().getLineWidth() + 1);
            }
            if (name.equals("down") && isPressed) {
                mat.getAdditionalRenderState().setLineWidth(Math.max(mat.getAdditionalRenderState().getLineWidth() - 1, 1));
            }
        }
    }, "up", "down");
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_J));
}
Also used : Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 94 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TerrainTest method setupKeys.

private void setupKeys() {
    flyCam.setMoveSpeed(50);
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(actionListener, "wireframe");
    inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addListener(actionListener, "triPlanar");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 95 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestAdvanced method setupKeys.

private void setupKeys() {
    flyCam.setMoveSpeed(50);
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(actionListener, "wireframe");
    inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addListener(actionListener, "triPlanar");
    inputManager.addMapping("WardIso", new KeyTrigger(KeyInput.KEY_9));
    inputManager.addListener(actionListener, "WardIso");
    inputManager.addMapping("DetachControl", new KeyTrigger(KeyInput.KEY_0));
    inputManager.addListener(actionListener, "DetachControl");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)93 ActionListener (com.jme3.input.controls.ActionListener)36 Vector3f (com.jme3.math.Vector3f)30 Geometry (com.jme3.scene.Geometry)23 Material (com.jme3.material.Material)22 DirectionalLight (com.jme3.light.DirectionalLight)21 Quaternion (com.jme3.math.Quaternion)18 Spatial (com.jme3.scene.Spatial)13 FilterPostProcessor (com.jme3.post.FilterPostProcessor)11 Box (com.jme3.scene.shape.Box)11 BitmapText (com.jme3.font.BitmapText)10 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)10 Node (com.jme3.scene.Node)10 AnalogListener (com.jme3.input.controls.AnalogListener)9 ColorRGBA (com.jme3.math.ColorRGBA)9 Sphere (com.jme3.scene.shape.Sphere)8 AmbientLight (com.jme3.light.AmbientLight)7 Quad (com.jme3.scene.shape.Quad)6 ChaseCamera (com.jme3.input.ChaseCamera)4 BulletAppState (com.jme3.bullet.BulletAppState)3