Search in sources :

Example 81 with Vector3f

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

the class FlyByCamera method moveCamera.

protected void moveCamera(float value, boolean sideways) {
    Vector3f vel = new Vector3f();
    Vector3f pos = cam.getLocation().clone();
    if (sideways) {
        cam.getLeft(vel);
    } else {
        cam.getDirection(vel);
    }
    vel.multLocal(value * moveSpeed);
    if (motionAllowed != null)
        motionAllowed.checkMotionAllowed(pos, vel);
    else
        pos.addLocal(vel);
    cam.setLocation(pos);
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 82 with Vector3f

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

the class FlyByCamera method rotateCamera.

protected void rotateCamera(float value, Vector3f axis) {
    if (dragToRotate) {
        if (canRotate) {
        //                value = -value;
        } else {
            return;
        }
    }
    Matrix3f mat = new Matrix3f();
    mat.fromAngleNormalAxis(rotationSpeed * value, axis);
    Vector3f up = cam.getUp();
    Vector3f left = cam.getLeft();
    Vector3f dir = cam.getDirection();
    mat.mult(up, up);
    mat.mult(left, left);
    mat.mult(dir, dir);
    Quaternion q = new Quaternion();
    q.fromAxes(left, up, dir);
    q.normalizeLocal();
    cam.setAxes(q);
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 83 with Vector3f

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

the class WaterFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    if (reflectionScene == null) {
        reflectionScene = vp.getScenes().get(0);
        DirectionalLight l = findLight((Node) reflectionScene);
        if (l != null) {
            lightDirection = l.getDirection();
        }
    }
    this.renderManager = renderManager;
    this.viewPort = vp;
    reflectionPass = new Pass();
    reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
    reflectionCam = new Camera(reflectionMapSize, reflectionMapSize);
    reflectionView = new ViewPort("reflectionView", reflectionCam);
    reflectionView.setClearFlags(true, true, true);
    reflectionView.attachScene(reflectionScene);
    reflectionView.setOutputFrameBuffer(reflectionPass.getRenderFrameBuffer());
    plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
    reflectionProcessor = new ReflectionProcessor(reflectionCam, reflectionPass.getRenderFrameBuffer(), plane);
    reflectionProcessor.setReflectionClipPlane(plane);
    reflectionView.addProcessor(reflectionProcessor);
    normalTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.dds");
    if (foamTexture == null) {
        foamTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg");
    }
    if (causticsTexture == null) {
        causticsTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/caustics.jpg");
    }
    heightTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/heightmap.jpg");
    normalTexture.setWrap(WrapMode.Repeat);
    foamTexture.setWrap(WrapMode.Repeat);
    causticsTexture.setWrap(WrapMode.Repeat);
    heightTexture.setWrap(WrapMode.Repeat);
    material = new Material(manager, "Common/MatDefs/Water/Water.j3md");
    material.setTexture("HeightMap", heightTexture);
    material.setTexture("CausticsMap", causticsTexture);
    material.setTexture("FoamMap", foamTexture);
    material.setTexture("NormalMap", normalTexture);
    material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());
    material.setFloat("WaterTransparency", waterTransparency);
    material.setFloat("NormalScale", normalScale);
    material.setFloat("R0", refractionConstant);
    material.setFloat("MaxAmplitude", maxAmplitude);
    material.setVector3("LightDir", lightDirection);
    material.setColor("LightColor", lightColor);
    material.setFloat("ShoreHardness", shoreHardness);
    material.setFloat("RefractionStrength", refractionStrength);
    material.setFloat("WaveScale", waveScale);
    material.setVector3("FoamExistence", foamExistence);
    material.setFloat("SunScale", sunScale);
    material.setVector3("ColorExtinction", colorExtinction);
    material.setFloat("Shininess", shininess);
    material.setColor("WaterColor", waterColor);
    material.setColor("DeepWaterColor", deepWaterColor);
    material.setVector2("WindDirection", windDirection);
    material.setFloat("FoamHardness", foamHardness);
    material.setBoolean("UseRipples", useRipples);
    material.setBoolean("UseHQShoreline", useHQShoreline);
    material.setBoolean("UseSpecular", useSpecular);
    material.setBoolean("UseFoam", useFoam);
    material.setBoolean("UseCaustics", useCaustics);
    material.setBoolean("UseRefraction", useRefraction);
    material.setFloat("ReflectionDisplace", reflectionDisplace);
    material.setFloat("FoamIntensity", foamIntensity);
    material.setFloat("UnderWaterFogDistance", underWaterFogDistance);
    material.setFloat("CausticsIntensity", causticsIntensity);
    if (center != null) {
        material.setVector3("Center", center);
        material.setFloat("Radius", radius * radius);
        material.setBoolean("SquareArea", shapeType == AreaShape.Square);
    }
    material.setFloat("WaterHeight", waterHeight);
}
Also used : Pass(com.jme3.post.Filter.Pass) DirectionalLight(com.jme3.light.DirectionalLight) ViewPort(com.jme3.renderer.ViewPort) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera)

Example 84 with Vector3f

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

the class WaterUtils method updateReflectionCam.

public static void updateReflectionCam(Camera reflectionCam, Plane plane, Camera sceneCam) {
    TempVars vars = TempVars.get();
    //Temp vects for reflection cam orientation calculation
    Vector3f sceneTarget = vars.vect1;
    Vector3f reflectDirection = vars.vect2;
    Vector3f reflectUp = vars.vect3;
    Vector3f reflectLeft = vars.vect4;
    Vector3f camLoc = vars.vect5;
    camLoc = plane.reflect(sceneCam.getLocation(), camLoc);
    reflectionCam.setLocation(camLoc);
    reflectionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom());
    reflectionCam.setParallelProjection(sceneCam.isParallelProjection());
    sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getDirection(vars.vect6));
    reflectDirection = plane.reflect(sceneTarget, reflectDirection);
    reflectDirection.subtractLocal(camLoc);
    sceneTarget.set(sceneCam.getLocation()).subtractLocal(sceneCam.getUp(vars.vect6));
    reflectUp = plane.reflect(sceneTarget, reflectUp);
    reflectUp.subtractLocal(camLoc);
    sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getLeft(vars.vect6));
    reflectLeft = plane.reflect(sceneTarget, reflectLeft);
    reflectLeft.subtractLocal(camLoc);
    reflectionCam.setAxes(reflectLeft, reflectUp, reflectDirection);
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 85 with Vector3f

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

the class TestCameraMotionPath method createScene.

private void createScene() {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 1f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Black);
    mat.setColor("Diffuse", ColorRGBA.DarkGray);
    mat.setColor("Specular", ColorRGBA.White.mult(0.6f));
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Gray);
    matSoil.setColor("Specular", ColorRGBA.Black);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalScale(3);
    teapot.setMaterial(mat);
    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(50, 1, 50));
    soil.setLocalTranslation(0, -1, 0);
    soil.setMaterial(matSoil);
    rootNode.attachChild(soil);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
}
Also used : Geometry(com.jme3.scene.Geometry) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Aggregations

Vector3f (com.jme3.math.Vector3f)536 Material (com.jme3.material.Material)126 Geometry (com.jme3.scene.Geometry)118 DirectionalLight (com.jme3.light.DirectionalLight)95 Quaternion (com.jme3.math.Quaternion)94 TempVars (com.jme3.util.TempVars)67 ColorRGBA (com.jme3.math.ColorRGBA)64 Node (com.jme3.scene.Node)63 Spatial (com.jme3.scene.Spatial)57 Box (com.jme3.scene.shape.Box)57 Sphere (com.jme3.scene.shape.Sphere)51 Texture (com.jme3.texture.Texture)41 KeyTrigger (com.jme3.input.controls.KeyTrigger)36 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)35 Vector2f (com.jme3.math.Vector2f)35 FilterPostProcessor (com.jme3.post.FilterPostProcessor)34 FloatBuffer (java.nio.FloatBuffer)34 InputCapsule (com.jme3.export.InputCapsule)33 BoundingBox (com.jme3.bounding.BoundingBox)30 AmbientLight (com.jme3.light.AmbientLight)30