Search in sources :

Example 1 with Plane

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

the class SpotLight method intersectsFrustum.

@Override
public boolean intersectsFrustum(Camera cam, TempVars vars) {
    if (spotRange == 0) {
        // The algorithm below does not support infinite spot range.
        return true;
    }
    Vector3f farPoint = vars.vect1.set(position).addLocal(vars.vect2.set(direction).multLocal(spotRange));
    for (int i = 5; i >= 0; i--) {
        //check origin against the plane
        Plane plane = cam.getWorldPlane(i);
        float dot = plane.pseudoDistance(position);
        if (dot < 0) {
            // outside, check the far point against the plane   
            dot = plane.pseudoDistance(farPoint);
            if (dot < 0) {
                // outside, check the projection of the far point along the normal of the plane to the base disc perimeter of the cone
                //computing the radius of the base disc
                float farRadius = (spotRange / outerAngleCos) * outerAngleSin;
                //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
                Vector3f perpDirection = vars.vect2.set(direction).crossLocal(plane.getNormal()).normalizeLocal().crossLocal(direction);
                //projecting the far point on the base disc perimeter
                Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
                //checking against the plane
                dot = plane.pseudoDistance(projectedPoint);
                if (dot < 0) {
                    // Outside, the light can be culled
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Plane(com.jme3.math.Plane) Vector3f(com.jme3.math.Vector3f)

Example 2 with Plane

use of com.jme3.math.Plane 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 3 with Plane

use of com.jme3.math.Plane 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 4 with Plane

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

the class TestUrlLoading method simpleInitApp.

@Override
public void simpleInitApp() {
    // create a simple plane/quad
    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1, true);
    Geometry quad = new Geometry("Textured Quad", quadMesh);
    assetManager.registerLocator("https://raw.githubusercontent.com/jMonkeyEngine/BookSamples/master/assets/Textures/", UrlLocator.class);
    TextureKey key = new TextureKey("mucha-window.png", false);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    quad.setMaterial(mat);
    float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
    quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
    quad.center();
    rootNode.attachChild(quad);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) TextureKey(com.jme3.asset.TextureKey) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 5 with Plane

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

the class Camera method onFrameChange.

/**
     * <code>onFrameChange</code> updates the view frame of the camera.
     */
public void onFrameChange() {
    TempVars vars = TempVars.get();
    Vector3f left = getLeft(vars.vect1);
    Vector3f direction = getDirection(vars.vect2);
    Vector3f up = getUp(vars.vect3);
    float dirDotLocation = direction.dot(location);
    // left plane
    Vector3f leftPlaneNormal = worldPlane[LEFT_PLANE].getNormal();
    leftPlaneNormal.x = left.x * coeffLeft[0];
    leftPlaneNormal.y = left.y * coeffLeft[0];
    leftPlaneNormal.z = left.z * coeffLeft[0];
    leftPlaneNormal.addLocal(direction.x * coeffLeft[1], direction.y * coeffLeft[1], direction.z * coeffLeft[1]);
    worldPlane[LEFT_PLANE].setConstant(location.dot(leftPlaneNormal));
    // right plane
    Vector3f rightPlaneNormal = worldPlane[RIGHT_PLANE].getNormal();
    rightPlaneNormal.x = left.x * coeffRight[0];
    rightPlaneNormal.y = left.y * coeffRight[0];
    rightPlaneNormal.z = left.z * coeffRight[0];
    rightPlaneNormal.addLocal(direction.x * coeffRight[1], direction.y * coeffRight[1], direction.z * coeffRight[1]);
    worldPlane[RIGHT_PLANE].setConstant(location.dot(rightPlaneNormal));
    // bottom plane
    Vector3f bottomPlaneNormal = worldPlane[BOTTOM_PLANE].getNormal();
    bottomPlaneNormal.x = up.x * coeffBottom[0];
    bottomPlaneNormal.y = up.y * coeffBottom[0];
    bottomPlaneNormal.z = up.z * coeffBottom[0];
    bottomPlaneNormal.addLocal(direction.x * coeffBottom[1], direction.y * coeffBottom[1], direction.z * coeffBottom[1]);
    worldPlane[BOTTOM_PLANE].setConstant(location.dot(bottomPlaneNormal));
    // top plane
    Vector3f topPlaneNormal = worldPlane[TOP_PLANE].getNormal();
    topPlaneNormal.x = up.x * coeffTop[0];
    topPlaneNormal.y = up.y * coeffTop[0];
    topPlaneNormal.z = up.z * coeffTop[0];
    topPlaneNormal.addLocal(direction.x * coeffTop[1], direction.y * coeffTop[1], direction.z * coeffTop[1]);
    worldPlane[TOP_PLANE].setConstant(location.dot(topPlaneNormal));
    if (isParallelProjection()) {
        worldPlane[LEFT_PLANE].setConstant(worldPlane[LEFT_PLANE].getConstant() + frustumLeft);
        worldPlane[RIGHT_PLANE].setConstant(worldPlane[RIGHT_PLANE].getConstant() - frustumRight);
        worldPlane[TOP_PLANE].setConstant(worldPlane[TOP_PLANE].getConstant() - frustumTop);
        worldPlane[BOTTOM_PLANE].setConstant(worldPlane[BOTTOM_PLANE].getConstant() + frustumBottom);
    }
    // far plane
    worldPlane[FAR_PLANE].setNormal(left);
    worldPlane[FAR_PLANE].setNormal(-direction.x, -direction.y, -direction.z);
    worldPlane[FAR_PLANE].setConstant(-(dirDotLocation + frustumFar));
    // near plane
    worldPlane[NEAR_PLANE].setNormal(direction.x, direction.y, direction.z);
    worldPlane[NEAR_PLANE].setConstant(dirDotLocation + frustumNear);
    viewMatrix.fromFrame(location, direction, up, left);
    vars.release();
    //        viewMatrix.transposeLocal();
    updateViewProjection();
}
Also used : TempVars(com.jme3.util.TempVars)

Aggregations

Vector3f (com.jme3.math.Vector3f)20 Plane (com.jme3.math.Plane)9 Sphere (com.jme3.scene.shape.Sphere)7 TempVars (com.jme3.util.TempVars)7 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)6 Material (com.jme3.material.Material)6 Geometry (com.jme3.scene.Geometry)6 Node (com.jme3.scene.Node)6 BulletAppState (com.jme3.bullet.BulletAppState)4 Quad (com.jme3.scene.shape.Quad)4 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)3 Box (com.jme3.scene.shape.Box)3 CollisionResult (com.jme3.collision.CollisionResult)2 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 Triangle (com.jme3.math.Triangle)2 Camera (com.jme3.renderer.Camera)2 Spatial (com.jme3.scene.Spatial)2 Structure (com.jme3.scene.plugins.blender.file.Structure)2 Texture (com.jme3.texture.Texture)2