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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations