Search in sources :

Example 26 with InputManager

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

the class TestSpotLightShadows method setupLighting.

public void setupLighting() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    rootNode.setShadowMode(ShadowMode.CastAndReceive);
    spot = new SpotLight();
    spot.setSpotRange(1000);
    spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
    spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
    spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
    spot.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(spot);
    //        PointLight pl=new PointLight();
    //      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    //      pl.setRadius(1000);     
    //      pl.setColor(ColorRGBA.White.mult(2));
    //      rootNode.addLight(pl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    lightMdl.setLocalScale(5);
    rootNode.attachChild(lightMdl);
    //        DirectionalLight dl = new DirectionalLight();
    //        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
    //        dl.setColor(ColorRGBA.White.mult(0.7f));
    //        rootNode.addLight(dl);
    final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
    slsr.setLight(spot);
    slsr.setShadowIntensity(0.5f);
    slsr.setShadowZExtend(100);
    slsr.setShadowZFadeLength(5);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    viewPort.addProcessor(slsr);
    SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
    slsf.setLight(spot);
    slsf.setShadowIntensity(0.5f);
    slsf.setShadowZExtend(100);
    slsf.setShadowZFadeLength(5);
    slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    slsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(slsf);
    viewPort.addProcessor(fpp);
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stop") && isPressed) {
                stop = !stop;
                //   slsr.displayFrustum();
                System.out.println("pos : " + spot.getPosition());
                System.out.println("dir : " + spot.getDirection());
            }
        }
    }, "stop");
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
    flyCam.setDragToRotate(true);
}
Also used : SpotLightShadowFilter(com.jme3.shadow.SpotLightShadowFilter) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ActionListener(com.jme3.input.controls.ActionListener) AmbientLight(com.jme3.light.AmbientLight)

Example 27 with InputManager

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

the class HelloPhysics method initInputs.

/** Add InputManager action: Left click triggers shooting. */
private void initInputs() {
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
}
Also used : MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 28 with InputManager

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

the class TestPBRLighting method simpleInitApp.

@Override
public void simpleInitApp() {
    assetManager.registerLoader(KTXLoader.class, "ktx");
    viewPort.setBackgroundColor(ColorRGBA.White);
    modelNode = (Node) new Node("modelNode");
    model = (Geometry) assetManager.loadModel("Models/Tank/tank.j3o");
    MikktspaceTangentGenerator.generate(model);
    modelNode.attachChild(model);
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    dl.setColor(ColorRGBA.White);
    rootNode.attachChild(modelNode);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //        fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(4.0f)));
    //        fpp.addFilter(new SSAOFilter(0.5f, 3, 0.2f, 0.2f));
    viewPort.addProcessor(fpp);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Sky_Cloudy.hdr", SkyFactory.EnvMapType.EquirectMap);
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/road.hdr", SkyFactory.EnvMapType.EquirectMap);
    rootNode.attachChild(sky);
    pbrMat = assetManager.loadMaterial("Models/Tank/tank.j3m");
    model.setMaterial(pbrMat);
    final EnvironmentCamera envCam = new EnvironmentCamera(128, new Vector3f(0, 3f, 0));
    stateManager.attach(envCam);
    //        EnvironmentManager envManager = new EnvironmentManager();
    //        stateManager.attach(envManager);
    //       envManager.setScene(rootNode);
    LightsDebugState debugState = new LightsDebugState();
    stateManager.attach(debugState);
    ChaseCamera chaser = new ChaseCamera(cam, modelNode, inputManager);
    chaser.setDragToRotate(true);
    chaser.setMinVerticalRotation(-FastMath.HALF_PI);
    chaser.setMaxDistance(1000);
    chaser.setSmoothMotion(true);
    chaser.setRotationSensitivity(10);
    chaser.setZoomSensitivity(5);
    flyCam.setEnabled(false);
    //flyCam.setMoveSpeed(100);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("debug") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null && tex2.getParent() == null) {
                    guiNode.attachChild(tex);
                } else if (tex2.getParent() == null) {
                    tex.removeFromParent();
                    guiNode.attachChild(tex2);
                } else {
                    tex2.removeFromParent();
                }
            }
            if (name.equals("up") && isPressed) {
                model.move(0, tpf * 100f, 0);
            }
            if (name.equals("down") && isPressed) {
                model.move(0, -tpf * 100f, 0);
            }
            if (name.equals("left") && isPressed) {
                model.move(0, 0, tpf * 100f);
            }
            if (name.equals("right") && isPressed) {
                model.move(0, 0, -tpf * 100f);
            }
            if (name.equals("light") && isPressed) {
                dl.setDirection(cam.getDirection().normalize());
            }
        }
    }, "toggle", "light", "up", "down", "left", "right", "debug");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("light", new KeyTrigger(KeyInput.KEY_F));
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("debug", new KeyTrigger(KeyInput.KEY_D));
    MaterialDebugAppState debug = new MaterialDebugAppState();
    debug.registerBinding("Common/MatDefs/Light/PBRLighting.frag", rootNode);
    getStateManager().attach(debug);
}
Also used : MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) ToneMapFilter(com.jme3.post.filters.ToneMapFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 29 with InputManager

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

the class TestContextSwitching method simpleInitApp.

@Override
public void simpleInitApp() {
    clContext = null;
    NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("jme3test/opencl/ContextSwitchingScreen.xml", "Screen", this);
    guiViewPort.addProcessor(niftyDisplay);
    inputManager.setCursorVisible(true);
    flyCam.setEnabled(false);
}
Also used : NiftyJmeDisplay(com.jme3.niftygui.NiftyJmeDisplay)

Example 30 with InputManager

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

the class TestSSAO method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(68.45442f, 8.235511f, 7.9676695f));
    cam.setRotation(new Quaternion(0.046916496f, -0.69500375f, 0.045538206f, 0.7160271f));
    flyCam.setMoveSpeed(50);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Texture diff = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
    diff.setWrap(Texture.WrapMode.Repeat);
    Texture norm = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_normal.jpg");
    norm.setWrap(Texture.WrapMode.Repeat);
    mat.setTexture("DiffuseMap", diff);
    mat.setTexture("NormalMap", norm);
    mat.setFloat("Shininess", 2.0f);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(1.8f, 1.8f, 1.8f, 1.0f));
    rootNode.addLight(al);
    model = (Geometry) assetManager.loadModel("Models/Sponza/Sponza.j3o");
    model.getMesh().scaleTextureCoordinates(new Vector2f(2, 2));
    model.setMaterial(mat);
    rootNode.attachChild(model);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter ssaoFilter = new SSAOFilter(2.9299974f, 32.920483f, 5.8100376f, 0.091000035f);
    ;
    ssaoFilter.setApproximateNormals(true);
    fpp.addFilter(ssaoFilter);
    SSAOUI ui = new SSAOUI(inputManager, ssaoFilter);
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) Texture(com.jme3.texture.Texture) AmbientLight(com.jme3.light.AmbientLight)

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