com.jme3.input.controls.ActionListener Java Examples
The following examples show how to use
com.jme3.input.controls.ActionListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestBloom.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { if(active){ active=false; viewPort.removeProcessor(fpp); }else{ active=true; viewPort.addProcessor(fpp); } } } }; inputManager.addListener(acl, "toggle"); }
Example #2
Source File: MaterialDebugAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void bind(final Binding binding) { if (binding.getTrigger() instanceof FileChangedTrigger) { FileChangedTrigger t = (FileChangedTrigger) binding.getTrigger(); List<Binding> b = fileTriggers.get(t); if(b == null){ t.init(); b = new ArrayList<Binding>(); fileTriggers.put(t, b); } b.add(binding); } else { final String actionName = binding.getActionName(); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if (actionName.equals(name) && isPressed) { //reloading the material binding.reload(); } } }, actionName); inputManager.addMapping(actionName, binding.getTrigger()); } }
Example #3
Source File: TestCinematic.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initInputs() { inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN)); ActionListener acl = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("togglePause") && keyPressed) { if (cinematic.getPlayState() == PlayState.Playing) { cinematic.pause(); } else { cinematic.play(); } } } }; inputManager.addListener(acl, "togglePause"); }
Example #4
Source File: TestPosterization.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { if(active){ active=false; viewPort.removeProcessor(fpp); }else{ active=true; viewPort.addProcessor(fpp); } } } }; inputManager.addListener(acl, "toggle"); }
Example #5
Source File: TestBloom.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { if(active){ active=false; viewPort.removeProcessor(fpp); }else{ active=true; viewPort.addProcessor(fpp); } } } }; inputManager.addListener(acl, "toggle"); }
Example #6
Source File: TestCrossHatch.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { if(active){ active=false; viewPort.removeProcessor(fpp); }else{ active=true; viewPort.addProcessor(fpp); } } } }; inputManager.addListener(acl, "toggle"); }
Example #7
Source File: TestCrossHatch.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { if(active){ active=false; viewPort.removeProcessor(fpp); }else{ active=true; viewPort.addProcessor(fpp); } } } }; inputManager.addListener(acl, "toggle"); }
Example #8
Source File: TestIssue1283.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Configure the InputManager during startup. */ private void configureInputs() { final String launchActionName = "launch"; ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean ongoing, float tpf) { if (ongoing) { if (name.equals(launchActionName)) { launchProjectile(); } } } }; Trigger bTrigger = new KeyTrigger(KeyInput.KEY_B); Trigger rmbTrigger = new MouseButtonTrigger(MouseInput.BUTTON_RIGHT); inputManager.addMapping(launchActionName, bTrigger, rmbTrigger); inputManager.addListener(actionListener, launchActionName); }
Example #9
Source File: TestPosterization.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { pf.setEnabled(!pf.isEnabled()); } } }; inputManager.addListener(acl, "toggle"); }
Example #10
Source File: PbrSceneTest.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override public void simpleInitApp() { super.simpleInitApp(); SceneLoader.install(this, postProcessor); rootNode.attachChild(assetManager.loadModel("Scene/TestPbrScene.j3s")); getFlyByCamera().setMoveSpeed(5); getInputManager().addMapping("mouse", new KeyTrigger(KeyInput.KEY_SPACE)); getInputManager().addListener(new ActionListener() { @Override public void onAction(final String name, final boolean isPressed, final float tpf) { if (isPressed) { getFlyByCamera().setEnabled(!getFlyByCamera().isEnabled()); } } }, "mouse"); }
Example #11
Source File: TestIssue801.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { viewPort.setBackgroundColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1f)); Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geom.setMaterial(mat); rootNode.attachChild(geom); inputManager.addMapping("changeBpp", new KeyTrigger(KeyInput.KEY_P)); ActionListener listener = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("changeBpp") && keyPressed) { goWindowed(); } } }; inputManager.addListener(listener, "changeBpp"); }
Example #12
Source File: TestMovingParticle.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void simpleInitApp() { emit = new ParticleEmitter("Emitter", Type.Triangle, 300); emit.setGravity(0, 0, 0); emit.setVelocityVariation(1); emit.setLowLife(1); emit.setHighLife(1); emit.setInitialVelocity(new Vector3f(0, .5f, 0)); emit.setImagesX(15); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png")); emit.setMaterial(mat); rootNode.attachChild(emit); inputManager.addListener(new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { if ("setNum".equals(name) && isPressed) { emit.setNumParticles(1000); } } }, "setNum"); inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE)); }
Example #13
Source File: InputManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void invokeActions(int hash, boolean pressed) { ArrayList<Mapping> maps = bindings.get(hash); if (maps == null) { return; } int size = maps.size(); for (int i = size - 1; i >= 0; i--) { Mapping mapping = maps.get(i); ArrayList<InputListener> listeners = mapping.listeners; int listenerSize = listeners.size(); for (int j = listenerSize - 1; j >= 0; j--) { InputListener listener = listeners.get(j); if (listener instanceof ActionListener) { ((ActionListener) listener).onAction(mapping.name, pressed, frameTPF); } } } }
Example #14
Source File: TestJaime.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void setupInput() { inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE)); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if(name.equals("start") && isPressed){ if(cinematic.getPlayState() != PlayState.Playing){ cinematic.play(); }else{ cinematic.pause(); } } } }, "start"); }
Example #15
Source File: TestMatParamOverride.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { inputManager.setCursorVisible(true); createBox(-3, ColorRGBA.Red); createBox(0, ColorRGBA.Green); createBox(3, ColorRGBA.Blue); System.out.println("Press G, W, Y, or space bar ..."); inputManager.addMapping("overrideClear", new KeyTrigger(KeyInput.KEY_SPACE)); inputManager.addMapping("overrideGray", new KeyTrigger(KeyInput.KEY_G)); inputManager.addMapping("overrideWhite", new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping("overrideYellow", new KeyTrigger(KeyInput.KEY_Y)); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if (isPressed) { if (name.equals("overrideClear")) { rootNode.clearMatParamOverrides(); } else if (name.equals("overrideGray")) { rootNode.clearMatParamOverrides(); rootNode.addMatParamOverride(overrideGray); } else if (name.equals("overrideWhite")) { rootNode.clearMatParamOverrides(); rootNode.addMatParamOverride(overrideWhite); } else if (name.equals("overrideYellow")) { rootNode.clearMatParamOverrides(); rootNode.addMatParamOverride(overrideYellow); } System.out.println(rootNode.getLocalMatParamOverrides()); } } }, "overrideClear", "overrideGray", "overrideWhite", "overrideYellow"); }
Example #16
Source File: TestPointSprite.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000); emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f), new Vector3f(1.8f, 1.8f, 1.8f))); emit.setGravity(0, 0, 0); emit.setLowLife(60); emit.setHighLife(60); emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0)); emit.setImagesX(15); emit.setStartSize(0.05f); emit.setEndSize(0.05f); emit.setStartColor(ColorRGBA.White); emit.setEndColor(ColorRGBA.White); emit.setSelectRandomImage(true); emit.emitAllParticles(); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat.setBoolean("PointSprite", true); mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png")); emit.setMaterial(mat); rootNode.attachChild(emit); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if ("setNum".equals(name) && isPressed) { emit.setNumParticles(5000); emit.emitAllParticles(); } } }, "setNum"); inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE)); }
Example #17
Source File: PhysicsTestHelper.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * creates the necessary inputlistener and action to shoot balls from the camera * * @param app the application that's running * @param rootNode where ball geometries should be added * @param space where collision objects should be added */ public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) { ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { Sphere bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = app.getAssetManager().loadTexture(key2); mat2.setTexture("ColorMap", tex2); if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(app.getCamera().getLocation()); RigidBodyControl bulletControl = new RigidBodyControl(10); bulletg.addControl(bulletControl); bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); space.add(bulletControl); } } }; app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); app.getInputManager().addListener(actionListener, "shoot"); }
Example #18
Source File: TestMovingParticle.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { emit = new ParticleEmitter("Emitter", Type.Triangle, 300); emit.setGravity(0, 0, 0); emit.getParticleInfluencer().setVelocityVariation(1); emit.setLowLife(1); emit.setHighLife(1); emit.getParticleInfluencer() .setInitialVelocity(new Vector3f(0, .5f, 0)); emit.setImagesX(15); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png")); emit.setMaterial(mat); rootNode.attachChild(emit); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if ("setNum".equals(name) && isPressed) { emit.setNumParticles(1000); } } }, "setNum"); inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE)); }
Example #19
Source File: TestMovingParticle.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { emit = new ParticleEmitter("Emitter", Type.Triangle, 300); emit.setGravity(0, 0, 0); emit.setVelocityVariation(1); emit.setLowLife(1); emit.setHighLife(1); emit.setInitialVelocity(new Vector3f(0, .5f, 0)); emit.setImagesX(15); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png")); emit.setMaterial(mat); rootNode.attachChild(emit); AmbientLight al = new AmbientLight(); al.setColor(new ColorRGBA(0.84f, 0.80f, 0.80f, 1.0f)); rootNode.addLight(al); inputManager.addListener(new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { if ("setNum".equals(name) && isPressed) { emit.setNumParticles(1000); } } }, "setNum"); inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE)); }
Example #20
Source File: PhysicsTestHelper.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * creates the necessary inputlistener and action to shoot balls from teh camera * @param app * @param rootNode * @param space */ public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) { ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { Sphere bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = app.getAssetManager().loadTexture(key2); mat2.setTexture("ColorMap", tex2); if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(app.getCamera().getLocation()); RigidBodyControl bulletControl = new RigidBodyControl(1); bulletg.addControl(bulletControl); bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); space.add(bulletControl); } } }; app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); app.getInputManager().addListener(actionListener, "shoot"); }
Example #21
Source File: TestPointSprite.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000); emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f), new Vector3f(1.8f, 1.8f, 1.8f))); emit.setGravity(0, 0, 0); emit.setLowLife(60); emit.setHighLife(60); emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0)); emit.setImagesX(15); emit.setStartSize(0.05f); emit.setEndSize(0.05f); emit.setStartColor(ColorRGBA.White); emit.setEndColor(ColorRGBA.White); emit.setSelectRandomImage(true); emit.emitAllParticles(); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat.setBoolean("PointSprite", true); mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png")); emit.setMaterial(mat); rootNode.attachChild(emit); inputManager.addListener(new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { if ("setNum".equals(name) && isPressed) { emit.setNumParticles(5000); emit.emitAllParticles(); } } }, "setNum"); inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE)); }
Example #22
Source File: InputManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) { if (value < axisDeadZone) { invokeAnalogs(hash, value, !applyTpf); return; } ArrayList<Mapping> maps = bindings.get(hash); if (maps == null) { return; } boolean valueChanged = !axisValues.containsKey(hash); if (applyTpf) { value *= frameTPF; } int size = maps.size(); for (int i = size - 1; i >= 0; i--) { Mapping mapping = maps.get(i); ArrayList<InputListener> listeners = mapping.listeners; int listenerSize = listeners.size(); for (int j = listenerSize - 1; j >= 0; j--) { InputListener listener = listeners.get(j); if (listener instanceof ActionListener && valueChanged) { ((ActionListener) listener).onAction(mapping.name, true, frameTPF); } if (listener instanceof AnalogListener) { ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF); } } } }
Example #23
Source File: TestLineWidthRenderState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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)); }
Example #24
Source File: TestCinematic.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void initInputs() { inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN)); inputManager.addMapping("navFwd", new KeyTrigger(keyInput.KEY_RIGHT)); inputManager.addMapping("navBack", new KeyTrigger(keyInput.KEY_LEFT)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("togglePause") && keyPressed) { if (cinematic.getPlayState() == PlayState.Playing) { cinematic.pause(); time = cinematic.getTime(); } else { cinematic.play(); } } if (cinematic.getPlayState() != PlayState.Playing) { if (name.equals("navFwd") && keyPressed) { time += 0.25; FastMath.clamp(time, 0, cinematic.getInitialDuration()); cinematic.setTime(time); } if (name.equals("navBack") && keyPressed) { time -= 0.25; FastMath.clamp(time, 0, cinematic.getInitialDuration()); cinematic.setTime(time); } } } }; inputManager.addListener(acl, "togglePause", "navFwd", "navBack"); }
Example #25
Source File: TestBloomAlphaThreshold.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void initInputs() { inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("toggle") && keyPressed) { if (active) { active = false; viewPort.removeProcessor(fpp); } else { active = true; viewPort.addProcessor(fpp); } } } }; inputManager.addListener(acl, "toggle"); }
Example #26
Source File: TestShadowsPerf.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { flyCam.setMoveSpeed(50); flyCam.setEnabled(false); viewPort.setBackgroundColor(ColorRGBA.DarkGray); cam.setLocation(new Vector3f(-53.952988f, 27.15874f, -32.875023f)); cam.setRotation(new Quaternion(0.1564309f, 0.6910534f, -0.15713608f, 0.6879555f)); // cam.setLocation(new Vector3f(53.64627f, 130.56f, -11.247704f)); // cam.setRotation(new Quaternion(-6.5737107E-4f, 0.76819664f, -0.64021313f, -7.886125E-4f)); //// cam.setFrustumFar(500); mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); Box b = new Box(800, 1, 700); b.scaleTextureCoordinates(new Vector2f(50, 50)); Geometry ground = new Geometry("ground", b); ground.setMaterial(mat); rootNode.attachChild(ground); ground.setShadowMode(ShadowMode.Receive); Sphere sphMesh = new Sphere(32, 32, 1); sphMesh.setTextureMode(Sphere.TextureMode.Projected); sphMesh.updateGeometry(32, 32, 1, false, false); TangentBinormalGenerator.generate(sphMesh); sphere = new Geometry("Rock Ball", sphMesh); sphere.setLocalTranslation(0, 5, 0); sphere.setMaterial(mat); sphere.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(sphere); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); dl.setColor(ColorRGBA.White); rootNode.addLight(dl); AmbientLight al = new AmbientLight(); al.setColor(ColorRGBA.White.mult(0.7f)); rootNode.addLight(al); //rootNode.setShadowMode(ShadowMode.CastAndReceive); createballs(); final DirectionalLightShadowRenderer pssmRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 4); viewPort.addProcessor(pssmRenderer); // // final PssmShadowFilter pssmRenderer = new PssmShadowFilter(assetManager, 1024, 4); // FilterPostProcessor fpp = new FilterPostProcessor(assetManager); // fpp.addFilter(pssmRenderer); // viewPort.addProcessor(fpp); pssmRenderer.setLight(dl); pssmRenderer.setLambda(0.55f); pssmRenderer.setShadowIntensity(0.55f); pssmRenderer.setShadowCompareMode(com.jme3.shadow.CompareMode.Software); pssmRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4); //pssmRenderer.displayDebug(); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("display") && isPressed) { //pssmRenderer.debugFrustrums(); System.out.println("tetetetet"); } if (name.equals("add") && isPressed) { createballs(); } } }, "display", "add"); inputManager.addMapping("display", new KeyTrigger(KeyInput.KEY_SPACE)); inputManager.addMapping("add", new KeyTrigger(KeyInput.KEY_RETURN)); }
Example #27
Source File: TestCameraMotionPath.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void initInputs() { inputManager.addMapping("display_hidePath", new KeyTrigger(KeyInput.KEY_P)); inputManager.addMapping("SwitchPathInterpolation", new KeyTrigger(KeyInput.KEY_I)); inputManager.addMapping("tensionUp", new KeyTrigger(KeyInput.KEY_U)); inputManager.addMapping("tensionDown", new KeyTrigger(KeyInput.KEY_J)); inputManager.addMapping("play_stop", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("display_hidePath") && keyPressed) { if (active) { active = false; path.disableDebugShape(); } else { active = true; path.enableDebugShape(assetManager, rootNode); } } if (name.equals("play_stop") && keyPressed) { if (playing) { playing = false; cameraMotionControl.stop(); chaser.setEnabled(true); camNode.setEnabled(false); } else { playing = true; chaser.setEnabled(false); camNode.setEnabled(true); cameraMotionControl.play(); } } if (name.equals("SwitchPathInterpolation") && keyPressed) { if (path.getPathSplineType() == SplineType.CatmullRom) { path.setPathSplineType(SplineType.Linear); } else { path.setPathSplineType(SplineType.CatmullRom); } } if (name.equals("tensionUp") && keyPressed) { path.setCurveTension(path.getCurveTension() + 0.1f); System.err.println("Tension : " + path.getCurveTension()); } if (name.equals("tensionDown") && keyPressed) { path.setCurveTension(path.getCurveTension() - 0.1f); System.err.println("Tension : " + path.getCurveTension()); } } }; inputManager.addListener(acl, "display_hidePath", "play_stop", "SwitchPathInterpolation", "tensionUp", "tensionDown"); }
Example #28
Source File: TestMotionPath.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void initInputs() { inputManager.addMapping("display_hidePath", new KeyTrigger(KeyInput.KEY_P)); inputManager.addMapping("SwitchPathInterpolation", new KeyTrigger(KeyInput.KEY_I)); inputManager.addMapping("tensionUp", new KeyTrigger(KeyInput.KEY_U)); inputManager.addMapping("tensionDown", new KeyTrigger(KeyInput.KEY_J)); inputManager.addMapping("play_stop", new KeyTrigger(KeyInput.KEY_SPACE)); ActionListener acl = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("display_hidePath") && keyPressed) { if (active) { active = false; path.disableDebugShape(); } else { active = true; path.enableDebugShape(assetManager, rootNode); } } if (name.equals("play_stop") && keyPressed) { if (playing) { playing = false; motionControl.stop(); } else { playing = true; motionControl.play(); } } if (name.equals("SwitchPathInterpolation") && keyPressed) { if (path.getPathSplineType() == SplineType.CatmullRom){ path.setPathSplineType(SplineType.Linear); } else { path.setPathSplineType(SplineType.CatmullRom); } } if (name.equals("tensionUp") && keyPressed) { path.setCurveTension(path.getCurveTension() + 0.1f); System.err.println("Tension : " + path.getCurveTension()); } if (name.equals("tensionDown") && keyPressed) { path.setCurveTension(path.getCurveTension() - 0.1f); System.err.println("Tension : " + path.getCurveTension()); } } }; inputManager.addListener(acl, "display_hidePath", "play_stop", "SwitchPathInterpolation", "tensionUp", "tensionDown"); }
Example #29
Source File: TestPostWaterLake.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { this.flyCam.setMoveSpeed(10); cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f)); // cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f)); // load sky rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false)); File file = new File("wildhouse.zip"); if (file.exists()) { useHttp = false; } // create the geometry and attach it // load the level from zip or http zip if (useHttp) { assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName()); } else { assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName()); } Spatial scene = assetManager.loadModel("main.scene"); rootNode.attachChild(scene); DirectionalLight sun = new DirectionalLight(); Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f); sun.setDirection(lightDir); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); final WaterFilter water = new WaterFilter(rootNode, lightDir); water.setWaterHeight(-20); water.setUseFoam(false); water.setUseRipples(false); water.setDeepWaterColor(ColorRGBA.Brown); water.setWaterColor(ColorRGBA.Brown.mult(2.0f)); water.setWaterTransparency(0.2f); water.setMaxAmplitude(0.3f); water.setWaveScale(0.008f); water.setSpeed(0.7f); water.setShoreHardness(1.0f); water.setRefractionConstant(0.2f); water.setShininess(0.3f); water.setSunScale(1.0f); water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f)); fpp.addFilter(water); viewPort.addProcessor(fpp); inputManager.addListener(new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { if(isPressed){ if(water.isUseHQShoreline()){ water.setUseHQShoreline(false); }else{ water.setUseHQShoreline(true); } } } }, "HQ"); inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE)); }
Example #30
Source File: TestMultiplesFilters.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { File file = new File("wildhouse.zip"); if (!file.exists()) { useHttp = true; } this.flyCam.setMoveSpeed(10); cam.setLocation(new Vector3f(6.0344796f, 1.5054002f, 55.572033f)); cam.setRotation(new Quaternion(0.0016069f, 0.9810479f, -0.008143323f, 0.19358753f)); // load sky rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap)); // create the geometry and attach it // load the level from zip or http zip if (useHttp) { assetManager.registerLocator( "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class); } else { assetManager.registerLocator("wildhouse.zip", ZipLocator.class); } Spatial scene = assetManager.loadModel("main.scene"); DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f)); sun.setColor(ColorRGBA.White.clone().multLocal(2)); scene.addLight(sun); fpp = new FilterPostProcessor(assetManager); // fpp.setNumSamples(4); ssaoFilter = new SSAOFilter(0.92f, 2.2f, 0.46f, 0.2f); final WaterFilter water=new WaterFilter(rootNode,new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f)); water.setWaterHeight(-20); SSAOUI ui=new SSAOUI(inputManager,ssaoFilter); final BloomFilter bloom = new BloomFilter(); final ColorOverlayFilter overlay = new ColorOverlayFilter(ColorRGBA.LightGray); fpp.addFilter(ssaoFilter); fpp.addFilter(water); fpp.addFilter(bloom); fpp.addFilter(overlay); viewPort.addProcessor(fpp); rootNode.attachChild(scene); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) { if ("toggleSSAO".equals(name) && isPressed) { if (ssaoFilter.isEnabled()) { ssaoFilter.setEnabled(false); } else { ssaoFilter.setEnabled(true); } } if ("toggleWater".equals(name) && isPressed) { if (water.isEnabled()) { water.setEnabled(false); } else { water.setEnabled(true); } } if ("toggleBloom".equals(name) && isPressed) { if (bloom.isEnabled()) { bloom.setEnabled(false); } else { bloom.setEnabled(true); } } if ("toggleOverlay".equals(name) && isPressed) { if (overlay.isEnabled()) { overlay.setEnabled(false); } else { overlay.setEnabled(true); } } } }, "toggleSSAO", "toggleBloom", "toggleWater","toggleOverlay"); inputManager.addMapping("toggleSSAO", new KeyTrigger(KeyInput.KEY_1)); inputManager.addMapping("toggleWater", new KeyTrigger(KeyInput.KEY_2)); inputManager.addMapping("toggleBloom", new KeyTrigger(KeyInput.KEY_3)); inputManager.addMapping("toggleOverlay", new KeyTrigger(KeyInput.KEY_4)); }