Search in sources :

Example 26 with BoundingSphere

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

the class BIHTree method collideWithBoundingVolume.

private int collideWithBoundingVolume(BoundingVolume bv, Matrix4f worldMatrix, CollisionResults results) {
    BoundingBox bbox;
    if (bv instanceof BoundingSphere) {
        BoundingSphere sphere = (BoundingSphere) bv;
        bbox = new BoundingBox(bv.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius());
    } else if (bv instanceof BoundingBox) {
        bbox = new BoundingBox((BoundingBox) bv);
    } else {
        throw new UnsupportedCollisionException("BoundingVolume:" + bv);
    }
    bbox.transform(worldMatrix.invert(), bbox);
    return root.intersectWhere(bv, bbox, worldMatrix, this, results);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Example 27 with BoundingSphere

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

the class BoundingCollisionTest method testSphereTriangleCollision.

@Test
public void testSphereTriangleCollision() {
    BoundingSphere sphere = new BoundingSphere(1, Vector3f.ZERO);
    Geometry geom = new Geometry("geom", new Quad(1, 1));
    checkCollision(sphere, geom, 2);
    // The box touches the edges of the triangles.
    sphere.setCenter(new Vector3f(-1f + FastMath.ZERO_TOLERANCE, 0, 0));
    checkCollision(sphere, geom, 2);
    // Move it slightly farther..
    sphere.setCenter(new Vector3f(-1f - FastMath.ZERO_TOLERANCE, 0, 0));
    checkCollision(sphere, geom, 0);
    // Parallel triangle / box side, touching
    sphere.setCenter(new Vector3f(0, 0, -1f));
    checkCollision(sphere, geom, 2);
    // Not touching
    sphere.setCenter(new Vector3f(0, 0, -1f - FastMath.ZERO_TOLERANCE));
    checkCollision(sphere, geom, 0);
    // Test collisions only against one of the triangles
    sphere.setCenter(new Vector3f(-0.9f, 1.2f, 0f));
    checkCollision(sphere, geom, 1);
    sphere.setCenter(new Vector3f(1.2f, -0.9f, 0f));
    checkCollision(sphere, geom, 1);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) BoundingSphere(com.jme3.bounding.BoundingSphere) Vector3f(com.jme3.math.Vector3f) Test(org.junit.Test)

Example 28 with BoundingSphere

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

the class LightFilterTest method testAmbientFiltering.

@Test
public void testAmbientFiltering() {
    geom.addLight(new AmbientLight());
    // Ambient lights must never be filtered
    checkFilteredLights(1);
    // Test for bounding Sphere
    geom.setModelBound(new BoundingSphere(0.5f, Vector3f.ZERO));
    // Ambient lights must never be filtered
    checkFilteredLights(1);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Test(org.junit.Test)

Example 29 with BoundingSphere

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

the class LightFilterTest method testPointFiltering.

@Test
public void testPointFiltering() {
    PointLight pl = new PointLight(Vector3f.ZERO);
    geom.addLight(pl);
    // Infinite point lights must never be filtered
    checkFilteredLights(1);
    // Light at origin does not intersect geom which is at Z=10
    pl.setRadius(1);
    checkFilteredLights(0);
    // Put it closer to geom, the very edge of the sphere touches the box.
    // Still not considered an intersection though.
    pl.setPosition(new Vector3f(0, 0, 8f));
    checkFilteredLights(0);
    // And more close - now its an intersection.
    pl.setPosition(new Vector3f(0, 0, 8f + FastMath.ZERO_TOLERANCE));
    checkFilteredLights(1);
    // Move the geometry away
    geom.move(0, 0, FastMath.ZERO_TOLERANCE);
    checkFilteredLights(0);
    // Test if the algorithm converts the sphere 
    // to a box before testing the collision (incorrect)
    float sqrt3 = FastMath.sqrt(3);
    pl.setPosition(new Vector3f(2, 2, 8));
    pl.setRadius(sqrt3);
    checkFilteredLights(0);
    // Make it a wee bit larger.
    pl.setRadius(sqrt3 + FastMath.ZERO_TOLERANCE);
    checkFilteredLights(1);
    // Rotate the camera so it is up, light is outside frustum.
    cam.lookAtDirection(Vector3f.UNIT_Y, Vector3f.UNIT_Y);
    checkFilteredLights(0);
    // ==================================
    // Tests for bounding Sphere
    geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO));
    geom.setLocalTranslation(0, 0, 2);
    pl.setPosition(new Vector3f(0, 0, 2f));
    // Infinite point lights must never be filtered
    pl.setRadius(0);
    checkFilteredLights(1);
    pl.setRadius(1f);
    // Put the light at the very close to the geom,
    // the very edge of the sphere touches the other bounding sphere
    // Still not considered an intersection though.
    pl.setPosition(new Vector3f(0, 0, 0));
    checkFilteredLights(0);
    // And more close - now its an intersection.
    pl.setPosition(new Vector3f(0, 0, 0f + FastMath.ZERO_TOLERANCE));
    checkFilteredLights(1);
    geom.setLocalTranslation(0, 0, 0);
    // In this case its an intersection for pointLight v. box
    // But not for pointLight v. sphere
    // Vector3f(0, 0.5f, 0.5f).normalize().mult(2) ~ >= (0.0, 1.4142135, 1.4142135)
    //pl.setPosition(new Vector3f(0, 0.5f, 0.5f).normalizeLocal().multLocal(2 + FastMath.ZERO_TOLERANCE));
    pl.setPosition(new Vector3f(0f, 1.4142135f, 1.4142135f).multLocal(1 + FastMath.ZERO_TOLERANCE));
    checkFilteredLights(0);
    // Make the distance a wee bit closer, now its an intersection
    //pl.setPosition(new Vector3f(0, 0.5f, 0.5f).normalizeLocal().multLocal(2 - FastMath.ZERO_TOLERANCE));
    pl.setPosition(new Vector3f(0f, 1.4142135f, 1.4142135f).multLocal(1 - FastMath.ZERO_TOLERANCE));
    checkFilteredLights(1);
    // it's a point light, also test for the other corner
    pl.setPosition(new Vector3f(0f, -1.4142135f, -1.4142135f).multLocal(1 - FastMath.ZERO_TOLERANCE));
    checkFilteredLights(0);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Vector3f(com.jme3.math.Vector3f) Test(org.junit.Test)

Example 30 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompState method initializeLocal.

@Override
protected void initializeLocal() {
    // 认知模块的根节点
    root = new Node(ROOT_NAME);
    LOG.debug("创建元器件状态机的根节点{}", root.getName());
    rootNode.attachChild(root);
    setupLight();
    stateManager.attach(chaserState = new MyCameraState());
    // //		PBR indirect lighting
    // final EnvironmentCamera envCam = new EnvironmentCamera(256, new Vector3f(0, 3f, 0));
    // stateManager.attach(envCam);
    // 
    // stateManager.attach(new BreakPointState((a) -> {
    // LightProbe probe = LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter<LightProbe>() {
    // @Override
    // public void done(LightProbe result) {
    // //					加载结束
    // Platform.runLater(() -> SpringUtil.getBean(PageController.class).hideLoading());
    // }
    // });
    // ((BoundingSphere) probe.getBounds()).setRadius(100);
    // rootNode.addLight(probe);
    // }));
    // 加载结束
    Platform.runLater(() -> SpringUtil.getBean(PageController.class).hideLoading());
}
Also used : Node(com.jme3.scene.Node)

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