Search in sources :

Example 36 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class TestDepthStencil method simpleInitApp.

@Override
public void simpleInitApp() {
    int w = settings.getWidth();
    int h = settings.getHeight();
    //setup framebuffer
    fb = new FrameBuffer(w, h, 1);
    Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
    fb.setDepthBuffer(Format.Depth24Stencil8);
    fb.setColorTexture(fbTex);
    // setup framebuffer's scene
    Sphere sphMesh = new Sphere(20, 20, 1);
    Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    final Geometry sphere = new Geometry("sphere", sphMesh);
    sphere.setMaterial(solidColor);
    fbNode.attachChild(sphere);
    sphere.addControl(new AbstractControl() {

        @Override
        protected void controlUpdate(float tpf) {
            Material mat = sphere.getMaterial();
            mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
        }

        @Override
        protected void controlRender(RenderManager rm, ViewPort vp) {
        }
    });
    //setup main scene
    Picture p = new Picture("Picture");
    p.setPosition(0, 0);
    p.setWidth(w);
    p.setHeight(h);
    p.setTexture(assetManager, fbTex, false);
    rootNode.attachChild(p);
    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 (enableStencil) {
                    enableStencil = false;
                    System.out.println("Stencil Enabled (model should be hidden)");
                } else {
                    enableStencil = true;
                    System.out.println("Stencil Disabled (model should be visible)");
                }
            }
        }
    };
    inputManager.addListener(acl, "toggle");
    System.out.println("Press space to toggle stencil");
}
Also used : Texture2D(com.jme3.texture.Texture2D) KeyTrigger(com.jme3.input.controls.KeyTrigger) AbstractControl(com.jme3.scene.control.AbstractControl) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) RenderManager(com.jme3.renderer.RenderManager)

Example 37 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class LightsDebugState method initialize.

@Override
protected void initialize(Application app) {
    debugNode = new Node("Environment debug Node");
    Sphere s = new Sphere(16, 16, 1);
    debugGeom = new Geometry("debugEnvProbe", s);
    debugMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/reflect.j3md");
    debugGeom.setMaterial(debugMaterial);
    debugBounds = BoundingSphereDebug.createDebugSphere(app.getAssetManager());
    if (scene == null) {
        scene = app.getViewPort().getScenes().get(0);
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 38 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class SpotLight method intersectsBox.

@Override
public boolean intersectsBox(BoundingBox box, TempVars vars) {
    if (this.spotRange > 0f) {
        // Sphere v. box collision
        if (!Intersection.intersect(box, position, spotRange)) {
            return false;
        }
    }
    Vector3f otherCenter = box.getCenter();
    Vector3f radVect = vars.vect4;
    radVect.set(box.getXExtent(), box.getYExtent(), box.getZExtent());
    float otherRadiusSquared = radVect.lengthSquared();
    float otherRadius = FastMath.sqrt(otherRadiusSquared);
    // Check if sphere is within spot angle.
    // Cone v. sphere collision.
    Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1);
    Vector3f U = position.subtract(E, vars.vect2);
    Vector3f D = otherCenter.subtract(U, vars.vect3);
    float dsqr = D.dot(D);
    float e = direction.dot(D);
    if (e > 0f && e * e >= dsqr * outerAngleCosSqr) {
        D = otherCenter.subtract(position, vars.vect3);
        dsqr = D.dot(D);
        e = -direction.dot(D);
        if (e > 0f && e * e >= dsqr * outerAngleSinSqr) {
            return dsqr <= otherRadiusSquared;
        } else {
            return true;
        }
    }
    return false;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 39 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class SpotLight method intersectsSphere.

@Override
public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) {
    if (this.spotRange > 0f) {
        // Sphere v. sphere collision
        if (!Intersection.intersect(sphere, position, spotRange)) {
            return false;
        }
    }
    float otherRadiusSquared = FastMath.sqr(sphere.getRadius());
    float otherRadius = sphere.getRadius();
    // Check if sphere is within spot angle.
    // Cone v. sphere collision.
    Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1);
    Vector3f U = position.subtract(E, vars.vect2);
    Vector3f D = sphere.getCenter().subtract(U, vars.vect3);
    float dsqr = D.dot(D);
    float e = direction.dot(D);
    if (e > 0f && e * e >= dsqr * outerAngleCosSqr) {
        D = sphere.getCenter().subtract(position, vars.vect3);
        dsqr = D.dot(D);
        e = -direction.dot(D);
        if (e > 0f && e * e >= dsqr * outerAngleSinSqr) {
            return dsqr <= otherRadiusSquared;
        } else {
            return true;
        }
    }
    return false;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 40 with Sphere

use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.

the class BoundingSphereDebug method createDebugSphere.

/**
     * Convenience factory method that creates a debuging bounding sphere geometry
     * @param assetManager the assetManager
     * @return the bounding sphere debug geometry.
     */
public static Geometry createDebugSphere(AssetManager assetManager) {
    BoundingSphereDebug b = new BoundingSphereDebug();
    Geometry geom = new Geometry("BoundingDebug", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setBoolean("VertexColor", true);
    mat.getAdditionalRenderState().setWireframe(true);
    geom.setMaterial(mat);
    return geom;
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material)

Aggregations

Sphere (com.jme3.scene.shape.Sphere)63 Geometry (com.jme3.scene.Geometry)58 Vector3f (com.jme3.math.Vector3f)57 Material (com.jme3.material.Material)46 DirectionalLight (com.jme3.light.DirectionalLight)23 Box (com.jme3.scene.shape.Box)22 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)17 Node (com.jme3.scene.Node)17 PointLight (com.jme3.light.PointLight)15 BulletAppState (com.jme3.bullet.BulletAppState)13 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)13 BoundingSphere (com.jme3.bounding.BoundingSphere)12 AmbientLight (com.jme3.light.AmbientLight)12 Quaternion (com.jme3.math.Quaternion)11 ColorRGBA (com.jme3.math.ColorRGBA)10 Spatial (com.jme3.scene.Spatial)9 TempVars (com.jme3.util.TempVars)9 KeyTrigger (com.jme3.input.controls.KeyTrigger)8 Vector2f (com.jme3.math.Vector2f)8 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)7