Java Code Examples for com.jme3.scene.Geometry#getWorldBound()
The following examples show how to use
com.jme3.scene.Geometry#getWorldBound() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpaqueComparator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public float distanceToCam(Geometry spat){ if (spat == null) return Float.NEGATIVE_INFINITY; if (spat.queueDistance != Float.NEGATIVE_INFINITY) return spat.queueDistance; Vector3f camPosition = cam.getLocation(); Vector3f viewVector = cam.getDirection(tempVec2); Vector3f spatPosition = null; if (spat.getWorldBound() != null){ spatPosition = spat.getWorldBound().getCenter(); }else{ spatPosition = spat.getWorldTranslation(); } spatPosition.subtract(camPosition, tempVec); spat.queueDistance = tempVec.dot(viewVector); return spat.queueDistance; }
Example 2
Source File: InstancedGeometry.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void updateWorldBound() { refreshFlags &= ~RF_BOUND; BoundingVolume resultBound = null; for (int i = 0; i < firstUnusedIndex; i++) { Geometry geom = geometries[i]; if (geom != null) { if (resultBound != null) { // merge current world bound with child world bound resultBound.mergeLocal(geom.getWorldBound()); } else { // set world bound to first non-null child world bound if (geom.getWorldBound() != null) { resultBound = geom.getWorldBound().clone(this.worldBound); } } } } this.worldBound = resultBound; }
Example 3
Source File: OpaqueComparator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public float distanceToCam(Geometry spat){ if (spat == null) return Float.NEGATIVE_INFINITY; if (spat.queueDistance != Float.NEGATIVE_INFINITY) return spat.queueDistance; Vector3f camPosition = cam.getLocation(); Vector3f viewVector = cam.getDirection(tempVec2); Vector3f spatPosition = null; if (spat.getWorldBound() != null){ spatPosition = spat.getWorldBound().getCenter(); }else{ spatPosition = spat.getWorldTranslation(); } spatPosition.subtract(camPosition, tempVec); spat.queueDistance = tempVec.dot(viewVector); return spat.queueDistance; }
Example 4
Source File: TransparentComparator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Calculates the distance from a spatial to the camera. Distance is a * squared distance. * * @param spat * Spatial to distancize. * @return Distance from Spatial to camera. */ private float distanceToCam2(Geometry spat){ if (spat == null) return Float.NEGATIVE_INFINITY; if (spat.queueDistance != Float.NEGATIVE_INFINITY) return spat.queueDistance; Vector3f camPosition = cam.getLocation(); Vector3f viewVector = cam.getDirection(); Vector3f spatPosition = null; if (spat.getWorldBound() != null){ spatPosition = spat.getWorldBound().getCenter(); }else{ spatPosition = spat.getWorldTranslation(); } spatPosition.subtract(camPosition, tempVec); spat.queueDistance = tempVec.dot(tempVec); float retval = Math.abs(tempVec.dot(viewVector) / viewVector.dot(viewVector)); viewVector.mult(retval, tempVec); spat.queueDistance = tempVec.length(); return spat.queueDistance; }
Example 5
Source File: ShapeBoundsTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testQuad() { Quad shape = new Quad(64, 16); Geometry geometry = new Geometry("geom", shape); BoundingVolume bv = geometry.getWorldBound(); BoundingBox bb = (BoundingBox) bv; //Quad z extent 0 is normal, so not using testBounds() here. Assert.assertTrue(bb.getXExtent() > 0 && bb.getYExtent() > 0); testVertices(geometry); }
Example 6
Source File: ShapeBoundsTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void testBounds(Geometry geometry) { BoundingVolume bv = geometry.getWorldBound(); if (bv instanceof BoundingBox) { BoundingBox bb = (BoundingBox) bv; Assert.assertTrue(bb.getXExtent() > 0 && bb.getYExtent() > 0 && bb.getZExtent() > 0); } else if (bv instanceof BoundingSphere) { BoundingSphere bs = (BoundingSphere) bv; Assert.assertTrue(bs.getRadius() > 1f); } testVertices(geometry); }
Example 7
Source File: ShapeBoundsTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void testVertices(Geometry geometry) { BoundingVolume bv = geometry.getWorldBound(); Assert.assertNotNull(bv); for (int e = 0; e < geometry.getVertexCount(); e++) { float x = (Float) geometry.getMesh().getBuffer(VertexBuffer.Type.Position).getElementComponent(e, 0); float y = (Float) geometry.getMesh().getBuffer(VertexBuffer.Type.Position).getElementComponent(e, 1); float z = (Float) geometry.getMesh().getBuffer(VertexBuffer.Type.Position).getElementComponent(e, 2); Vector3f vertex = new Vector3f(x, y, z); Assert.assertTrue("Vertex outside world bound: " + vertex, bv.intersects(vertex)); } }
Example 8
Source File: Octree.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Octree(Spatial scene, int minTrisPerNode){ scene.updateGeometricState(); List<Geometry> geomsList = getGeometries(scene); geoms = new Geometry[geomsList.size()]; geomsList.toArray(geoms); // generate bound box for all geom bbox = new BoundingBox(); for (Geometry geom : geoms){ BoundingVolume bv = geom.getWorldBound(); bbox.mergeLocal(bv); } // set largest extent float extent = Math.max(bbox.getXExtent(), Math.max(bbox.getYExtent(), bbox.getZExtent())); bbox.setXExtent(extent); bbox.setYExtent(extent); bbox.setZExtent(extent); this.minTrisPerNode = minTrisPerNode; Triangle t = new Triangle(); for (int g = 0; g < geoms.length; g++){ Mesh m = geoms[g].getMesh(); for (int i = 0; i < m.getTriangleCount(); i++){ m.getTriangle(i, t); OCTTriangle ot = new OCTTriangle(t.get1(), t.get2(), t.get3(), i, g); allTris.add(ot); // convert triangle to world space // geom.getWorldTransform().transformVector(t.get1(), t.get1()); // geom.getWorldTransform().transformVector(t.get2(), t.get2()); // geom.getWorldTransform().transformVector(t.get3(), t.get3()); } } }
Example 9
Source File: TransparentComparator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Calculates the distance from a spatial to the camera. Distance is a * squared distance. * * @param spat * Spatial to distancize. * @return Distance from Spatial to camera. */ private float distanceToCam2(Geometry spat){ if (spat == null) return Float.NEGATIVE_INFINITY; if (spat.queueDistance != Float.NEGATIVE_INFINITY) return spat.queueDistance; Vector3f camPosition = cam.getLocation(); Vector3f viewVector = cam.getDirection(); Vector3f spatPosition = null; if (spat.getWorldBound() != null){ spatPosition = spat.getWorldBound().getCenter(); }else{ spatPosition = spat.getWorldTranslation(); } spatPosition.subtract(camPosition, tempVec); spat.queueDistance = tempVec.dot(tempVec); float retval = Math.abs(tempVec.dot(viewVector) / viewVector.dot(viewVector)); viewVector.mult(retval, tempVec); spat.queueDistance = tempVec.length(); return spat.queueDistance; }
Example 10
Source File: CubeField.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Core Game Logic */ private void gameLogic(float tpf){ //Subtract difficulty level in accordance to speed every 10 seconds if(timer.getTimeInSeconds()>=coreTime2){ coreTime2=timer.getTimeInSeconds()+10; if(difficulty<=lowCap){ difficulty=lowCap; } else if(difficulty>lowCap){ difficulty-=5; diffHelp+=1; } } if(speed<.1f){ speed+=.000001f*tpf*fpsRate; } player.move(speed * tpf * fpsRate, 0, 0); if (cubeField.size() > difficulty){ cubeField.remove(0); }else if (cubeField.size() != difficulty){ randomizeCube(); } if (cubeField.isEmpty()){ requestClose(false); }else{ for (int i = 0; i < cubeField.size(); i++){ //better way to check collision Geometry playerModel = (Geometry) player.getChild(0); Geometry cubeModel = cubeField.get(i); BoundingVolume pVol = playerModel.getWorldBound(); BoundingVolume vVol = cubeModel.getWorldBound(); if (pVol.intersects(vVol)){ gameLost(); return; } //Remove cube if 10 world units behind player if (cubeField.get(i).getLocalTranslation().getX() + 10 < player.getLocalTranslation().getX()){ cubeField.get(i).removeFromParent(); cubeField.remove(cubeField.get(i)); } } } Score += fpsRate * tpf; fpsScoreText.setText("Current Score: "+Score); }
Example 11
Source File: DefaultLightFilter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void filterLights(Geometry geometry, LightList filteredLightList) { TempVars vars = TempVars.get(); try { LightList worldLights = geometry.getWorldLightList(); for (int i = 0; i < worldLights.size(); i++) { Light light = worldLights.get(i); // If this light is not enabled it will be ignored. if (!light.isEnabled()) { continue; } if (light.frustumCheckNeeded) { processedLights.add(light); light.frustumCheckNeeded = false; light.intersectsFrustum = light.intersectsFrustum(camera, vars); } if (!light.intersectsFrustum) { continue; } BoundingVolume bv = geometry.getWorldBound(); if (bv instanceof BoundingBox) { if (!light.intersectsBox((BoundingBox)bv, vars)) { continue; } } else if (bv instanceof BoundingSphere) { if (!Float.isInfinite( ((BoundingSphere)bv).getRadius() )) { if (!light.intersectsSphere((BoundingSphere)bv, vars)) { continue; } } } if (light.getType() == Light.Type.Probe) { probeBlendStrat.registerProbe((LightProbe) light); } else { filteredLightList.add(light); } } probeBlendStrat.populateProbes(geometry, filteredLightList); } finally { vars.release(); } }
Example 12
Source File: InstancedGeometry.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void updateInstances() { FloatBuffer fb = (FloatBuffer) transformInstanceData.getData(); fb.limit(fb.capacity()); fb.position(0); numCulledGeometries = 0; TempVars vars = TempVars.get(); { float[] temp = vars.matrixWrite; for (int i = 0; i < firstUnusedIndex; i++) { Geometry geom = geometries[i]; if (geom == null) { geom = geometries[firstUnusedIndex - 1]; if (geom == null) { throw new AssertionError(); } swap(i, firstUnusedIndex - 1); while (geometries[firstUnusedIndex -1] == null) { firstUnusedIndex--; } } if (cam != null) { BoundingVolume bv = geom.getWorldBound(); int save = cam.getPlaneState(); cam.setPlaneState(0); FrustumIntersect intersect = cam.contains(bv); cam.setPlaneState(save); if (intersect == FrustumIntersect.Outside) { numCulledGeometries++; continue; } } Matrix4f worldMatrix = geom.getWorldMatrix(); updateInstance(worldMatrix, temp, 0, vars.tempMat3, vars.quat1); fb.put(temp); } } vars.release(); fb.flip(); if (fb.limit() / INSTANCE_SIZE != (firstUnusedIndex - numCulledGeometries)) { throw new AssertionError(); } transformInstanceData.updateData(fb); }
Example 13
Source File: CubeField.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Core Game Logic */ private void gameLogic(float tpf){ //Subtract difficulty level in accordance to speed every 10 seconds if(timer.getTimeInSeconds()>=coreTime2){ coreTime2=timer.getTimeInSeconds()+10; if(difficulty<=lowCap){ difficulty=lowCap; } else if(difficulty>lowCap){ difficulty-=5; diffHelp+=1; } } if(speed<.1f){ speed+=.000001f*tpf*fpsRate; } player.move(speed * tpf * fpsRate, 0, 0); if (cubeField.size() > difficulty){ cubeField.remove(0); }else if (cubeField.size() != difficulty){ randomizeCube(); } if (cubeField.isEmpty()){ requestClose(false); }else{ for (int i = 0; i < cubeField.size(); i++){ //better way to check collision Geometry playerModel = (Geometry) player.getChild(0); Geometry cubeModel = cubeField.get(i); cubeModel.updateGeometricState(); BoundingVolume pVol = playerModel.getWorldBound(); BoundingVolume vVol = cubeModel.getWorldBound(); if (pVol.intersects(vVol)){ gameLost(); return; } //Remove cube if 10 world units behind player if (cubeField.get(i).getLocalTranslation().getX() + 10 < player.getLocalTranslation().getX()){ cubeField.get(i).removeFromParent(); cubeField.remove(cubeField.get(i)); } } } Score += fpsRate * tpf; fpsScoreText.setText("Current Score: "+Score); }