Search in sources :

Example 6 with Quaternion

use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.

the class KinematicRagdollControl method ikUpdate.

private void ikUpdate(float tpf) {
    TempVars vars = TempVars.get();
    Quaternion tmpRot1 = vars.quat1;
    Quaternion[] tmpRot2 = new Quaternion[] { vars.quat2, new Quaternion() };
    Iterator<String> it = ikTargets.keySet().iterator();
    float distance;
    Bone bone;
    String boneName;
    while (it.hasNext()) {
        boneName = it.next();
        bone = (Bone) boneLinks.get(boneName).bone;
        if (!bone.hasUserControl()) {
            Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
            continue;
        }
        distance = bone.getModelSpacePosition().distance(ikTargets.get(boneName));
        if (distance < IKThreshold) {
            Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "Distance is close enough");
            continue;
        }
        int depth = 0;
        int maxDepth = ikChainDepth.get(bone.getName());
        updateBone(boneLinks.get(bone.getName()), tpf * (float) FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
        Vector3f position = vars.vect1;
        for (PhysicsBoneLink link : boneLinks.values()) {
            matchPhysicObjectToBone(link, position, tmpRot1);
        }
    }
    vars.release();
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars) Bone(com.jme3.animation.Bone) SixDofJoint(com.jme3.bullet.joints.SixDofJoint)

Example 7 with Quaternion

use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.

the class TestDepthOfField method simpleInitApp.

@Override
public void simpleInitApp() {
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
    mainScene.addLight(sun);
    DirectionalLight l = new DirectionalLight();
    l.setDirection(Vector3f.UNIT_Y.mult(-1));
    l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
    mainScene.addLight(l);
    flyCam.setMoveSpeed(50);
    cam.setFrustumFar(3000);
    cam.setLocation(new Vector3f(-700, 100, 300));
    cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    //     fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    dofFilter = new DepthOfFieldFilter();
    dofFilter.setFocusDistance(0);
    dofFilter.setFocusRange(50);
    dofFilter.setBlurScale(1.4f);
    fpp.addFilter(dofFilter);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("toggle")) {
                    dofFilter.setEnabled(!dofFilter.isEnabled());
                }
            }
        }
    }, "toggle");
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("blurScaleUp")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() + 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("blurScaleDown")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() - 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("focusRangeUp")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() + 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusRangeDown")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() - 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusDistanceUp")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() + 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
            if (name.equals("focusDistanceDown")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() - 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
        }
    }, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown");
    inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE));
    inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U));
    inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J));
    inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I));
    inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K));
    inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O));
    inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L));
}
Also used : Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 8 with Quaternion

use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.

the class TestFog method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(50);
    Node mainScene = new Node();
    cam.setLocation(new Vector3f(-34.74095f, 95.21318f, -287.4945f));
    cam.setRotation(new Quaternion(0.023536969f, 0.9361278f, -0.016098259f, -0.35050195f));
    // load sky
    mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    mainScene.addLight(sun);
    rootNode.attachChild(mainScene);
    fpp = new FilterPostProcessor(assetManager);
    //fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    fog = new FogFilter();
    fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
    fog.setFogDistance(155);
    fog.setFogDensity(1.0f);
    fpp.addFilter(fog);
    viewPort.addProcessor(fpp);
    initInputs();
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) FilterPostProcessor(com.jme3.post.FilterPostProcessor) FogFilter(com.jme3.post.filters.FogFilter)

Example 9 with Quaternion

use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.

the class TestLightScattering method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(55.35316f, -0.27061665f, 27.092093f));
    cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f));
    //        cam.setDirection(new Vector3f(0,-0.5f,1.0f));
    //        cam.setLocation(new Vector3f(0, 300, -500));
    //cam.setFrustumFar(1000);
    flyCam.setMoveSpeed(10);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m");
    Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml");
    TangentBinormalGenerator.generate(((Geometry) ((Node) scene).getChild(0)).getMesh());
    scene.setMaterial(mat);
    scene.setShadowMode(ShadowMode.CastAndReceive);
    scene.setLocalScale(400);
    scene.setLocalTranslation(0, -10, -120);
    rootNode.attachChild(scene);
    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false));
    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    Vector3f lightPos = lightDir.multLocal(-3000);
    LightScatteringFilter filter = new LightScatteringFilter(lightPos);
    LightScatteringUI ui = new LightScatteringUI(inputManager, filter);
    fpp.addFilter(filter);
    viewPort.addProcessor(fpp);
}
Also used : LightScatteringFilter(com.jme3.post.filters.LightScatteringFilter) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor)

Example 10 with Quaternion

use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.

the class TestMultiRenderTarget method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.addProcessor(this);
    //        flyCam.setEnabled(false);
    cam.setLocation(new Vector3f(4.8037705f, 4.851632f, 10.789033f));
    cam.setRotation(new Quaternion(-0.05143692f, 0.9483723f, -0.21131563f, -0.230846f));
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    //tankMesh.getMaterial().setColor("Specular", ColorRGBA.Black);
    rootNode.attachChild(tank);
    display1 = new Picture("Picture");
    // make it appear behind stats view
    display1.move(0, 0, -1);
    display2 = (Picture) display1.clone();
    display3 = (Picture) display1.clone();
    display4 = (Picture) display1.clone();
    display = (Picture) display1.clone();
    ColorRGBA[] colors = new ColorRGBA[] { ColorRGBA.White, ColorRGBA.Blue, ColorRGBA.Cyan, ColorRGBA.DarkGray, ColorRGBA.Green, ColorRGBA.Magenta, ColorRGBA.Orange, ColorRGBA.Pink, ColorRGBA.Red, ColorRGBA.Yellow };
    pls = new PointLight[3];
    for (int i = 0; i < pls.length; i++) {
        PointLight pl = new PointLight();
        pl.setColor(colors[i % colors.length]);
        pl.setRadius(5);
        display.addLight(pl);
        pls[i] = pl;
    }
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Picture(com.jme3.ui.Picture) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) PointLight(com.jme3.light.PointLight)

Aggregations

Quaternion (com.jme3.math.Quaternion)115 Vector3f (com.jme3.math.Vector3f)100 Geometry (com.jme3.scene.Geometry)42 DirectionalLight (com.jme3.light.DirectionalLight)37 Material (com.jme3.material.Material)36 Node (com.jme3.scene.Node)30 FilterPostProcessor (com.jme3.post.FilterPostProcessor)26 Spatial (com.jme3.scene.Spatial)26 KeyTrigger (com.jme3.input.controls.KeyTrigger)22 Box (com.jme3.scene.shape.Box)21 TempVars (com.jme3.util.TempVars)16 ActionListener (com.jme3.input.controls.ActionListener)15 ColorRGBA (com.jme3.math.ColorRGBA)15 Quad (com.jme3.scene.shape.Quad)15 AmbientLight (com.jme3.light.AmbientLight)14 Sphere (com.jme3.scene.shape.Sphere)11 Bone (com.jme3.animation.Bone)9 PointLight (com.jme3.light.PointLight)8 AnimControl (com.jme3.animation.AnimControl)7 SpotLight (com.jme3.light.SpotLight)7