Search in sources :

Example 6 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class RefEnv method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    frame++;
    if (frame == 2) {
        final LightProbe probe = LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter<LightProbe>() {

            @Override
            public void done(LightProbe result) {
                System.err.println("Done rendering env maps");
                tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(result.getPrefilteredEnvMap(), assetManager);
                //  guiNode.attachChild(tex);
                rootNode.getChild("Scene").setCullHint(Spatial.CullHint.Dynamic);
            }
        });
        ((BoundingSphere) probe.getBounds()).setRadius(100);
        rootNode.addLight(probe);
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) LightProbe(com.jme3.light.LightProbe) EnvironmentCamera(com.jme3.environment.EnvironmentCamera)

Example 7 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class TestPBRLighting method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    frame++;
    if (frame == 2) {
        modelNode.removeFromParent();
        final LightProbe probe = LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter<LightProbe>() {

            @Override
            public void done(LightProbe result) {
                System.err.println("Done rendering env maps");
                tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(result.getPrefilteredEnvMap(), assetManager);
                tex2 = EnvMapUtils.getCubeMapCrossDebugView(result.getIrradianceMap(), assetManager);
            }
        });
        ((BoundingSphere) probe.getBounds()).setRadius(100);
        rootNode.addLight(probe);
    //getStateManager().getState(EnvironmentManager.class).addEnvProbe(probe);
    }
    if (frame > 10 && modelNode.getParent() == null) {
        rootNode.attachChild(modelNode);
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) LightProbe(com.jme3.light.LightProbe) EnvironmentCamera(com.jme3.environment.EnvironmentCamera)

Example 8 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class TestRayCasting method simpleInitApp.

@Override
public void simpleInitApp() {
    //        flyCam.setEnabled(false);
    // load material
    Material mat = (Material) assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    Mesh q = new Mesh();
    q.setBuffer(Type.Position, 3, new float[] { 1, 0, 0, 0, 1.5f, 0, -1, 0, 0 });
    q.setBuffer(Type.Index, 3, new int[] { 0, 1, 2 });
    q.setBound(new BoundingSphere());
    q.updateBound();
    //        Geometry teapot = new Geometry("MyGeom", q);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
    //        teapot.scale(2f, 2f, 2f);
    //        teapot.move(2f, 2f, -.5f);
    teapot.rotate(FastMath.HALF_PI, FastMath.HALF_PI, FastMath.HALF_PI);
    teapot.setMaterial(mat);
    rootNode.attachChild(teapot);
    //        cam.setLocation(cam.getLocation().add(0,1,0));
    //        cam.lookAt(teapot.getWorldBound().getCenter(), Vector3f.UNIT_Y);
    tracer = new RayTrace(rootNode, cam, 160, 128);
    tracer.show();
    tracer.update();
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material)

Example 9 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class BoundingCollisionTest method testSphereSphereCollision.

@Test
public void testSphereSphereCollision() {
    BoundingSphere sphere1 = new BoundingSphere(1, Vector3f.ZERO);
    BoundingSphere sphere2 = new BoundingSphere(1, Vector3f.ZERO);
    checkCollision(sphere1, sphere2, 1);
    // Put it at the very edge - should still intersect.
    sphere2.setCenter(new Vector3f(2f, 0f, 0f));
    checkCollision(sphere1, sphere2, 1);
    // Put it a wee bit farther - no intersection expected
    sphere2.setCenter(new Vector3f(2f + FastMath.ZERO_TOLERANCE, 0, 0));
    checkCollision(sphere1, sphere2, 0);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Vector3f(com.jme3.math.Vector3f) Test(org.junit.Test)

Example 10 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class BoundingCollisionTest method testBoxSphereCollision.

@Test
public void testBoxSphereCollision() {
    BoundingBox box1 = new BoundingBox(Vector3f.ZERO, 1, 1, 1);
    BoundingSphere sphere2 = new BoundingSphere(1, Vector3f.ZERO);
    checkCollision(box1, sphere2, 1);
    // Put it at the very edge - for sphere vs. box, it will not intersect
    sphere2.setCenter(new Vector3f(2f, 0f, 0f));
    checkCollision(box1, sphere2, 0);
    // Put it a wee bit closer - should intersect.
    sphere2.setCenter(new Vector3f(2f - FastMath.ZERO_TOLERANCE, 0, 0));
    checkCollision(box1, sphere2, 1);
    // Test if the algorithm converts the sphere 
    // to a box before testing the collision (incorrect)
    float sqrt3 = FastMath.sqrt(3);
    sphere2.setCenter(Vector3f.UNIT_XYZ.mult(2));
    sphere2.setRadius(sqrt3);
    checkCollision(box1, sphere2, 0);
    // Make it a wee bit larger.
    sphere2.setRadius(sqrt3 + FastMath.ZERO_TOLERANCE);
    checkCollision(box1, sphere2, 1);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) Test(org.junit.Test)

Aggregations

BoundingSphere (com.jme3.bounding.BoundingSphere)24 Vector3f (com.jme3.math.Vector3f)9 BoundingBox (com.jme3.bounding.BoundingBox)8 TempVars (com.jme3.util.TempVars)7 Test (org.junit.Test)7 BoundingVolume (com.jme3.bounding.BoundingVolume)5 Geometry (com.jme3.scene.Geometry)5 LightProbe (com.jme3.light.LightProbe)4 EnvironmentCamera (com.jme3.environment.EnvironmentCamera)3 Material (com.jme3.material.Material)3 Node (com.jme3.scene.Node)2 ArrayList (java.util.ArrayList)2 UnsupportedCollisionException (com.jme3.collision.UnsupportedCollisionException)1 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 Light (com.jme3.light.Light)1 Triangle (com.jme3.math.Triangle)1 Vector2f (com.jme3.math.Vector2f)1 Mesh (com.jme3.scene.Mesh)1 Spatial (com.jme3.scene.Spatial)1