@Override protected void computeLastDistance(Spatial owner) { if (owner.getWorldBound() != null) { BoundingVolume bv = owner.getWorldBound(); lastDistance = bv.distanceSquaredTo(position); } else { lastDistance = owner.getWorldTranslation().distanceSquared(position); } }
@Override protected void computeLastDistance(Spatial owner) { if (owner.getWorldBound() != null) { BoundingVolume bv = owner.getWorldBound(); lastDistance = bv.distanceSquaredTo(position); } else { lastDistance = owner.getWorldTranslation().distanceSquared(position); } }
@Override public void computeLastDistance(Spatial owner) { if (owner.getWorldBound() != null) { BoundingVolume bv = owner.getWorldBound(); lastDistance = bv.distanceSquaredTo(position); } else { lastDistance = owner.getWorldTranslation().distanceSquared(position); } }
private void fixRefreshFlags(){ // force transforms to update below this node spatial.updateGeometricState(); // force world bound to update Spatial rootNode = spatial; while (rootNode.getParent() != null){ rootNode = rootNode.getParent(); } rootNode.getWorldBound(); }
@Override protected void updateWorldBound(){ super.updateWorldBound(); // for a node, the world bound is a combination of all its children // bounds BoundingVolume resultBound = null; for (Spatial child : children.getArray()) { // child bound is assumed to be updated assert (child.refreshFlags & RF_BOUND) == 0; if (resultBound != null) { // merge current world bound with child world bound resultBound.mergeLocal(child.getWorldBound()); } else { // set world bound to first non-null child world bound if (child.getWorldBound() != null) { resultBound = child.getWorldBound().clone(this.worldBound); } } } if (resultBound == null) { resultBound = new BoundingBox(getWorldTranslation(), 0f, 0f, 0f); } this.worldBound = resultBound; }
/** * Centers the spatial in the origin of the world bound. * @return The spatial on which this method is called, e.g <code>this</code>. */ public Spatial center() { Vector3f worldTrans = getWorldTranslation(); Vector3f worldCenter = getWorldBound().getCenter(); Vector3f absTrans = worldTrans.subtract(worldCenter); setLocalTranslation(absTrans); return this; }
/** * Use the bounding box of the supplied spatial to create a * BoxCollisionShape. * * @param spatial the spatial on which to base the shape (not null) * @param parent unused * @return a new shape with the dimensions of the spatial's bounding box * (not null) */ private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) { //TODO: using world bound here instead of "local world" bound... BoxCollisionShape shape = new BoxCollisionShape( ((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f())); return shape; }
/** * Use the bounding box of the supplied spatial to create a * BoxCollisionShape. * * @param spatial the spatial on which to base the shape (not null) * @param parent unused * @return a new shape with the dimensions of the spatial's bounding box * (not null) */ private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) { //TODO: using world bound here instead of "local world" bound... BoxCollisionShape shape = new BoxCollisionShape( ((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f())); return shape; }
return cam.containsGui(getWorldBound()); } else { frustrumIntersects = cam.contains(getWorldBound());
protected void controlRender(RenderManager rm, ViewPort vp) { BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) { level = lastLevel; // we haven't moved relative to the model, send the old measurement back. } else if (lastDistance > newDistance && lastLevel == 0) { level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. } else if (lastDistance < newDistance && lastLevel == numLevels - 1) { level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. } else { lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;) { if (trisToDraw - numTris[i] < 0) { break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }
/** * A handy method that will attach all bounding boxes of this terrain * to the node you supply. * Useful to visualize the bounding boxes when debugging. * * @param parent that will get the bounding box shapes of the terrain attached to */ public void attachBoundChildren(Node parent) { for (int i = 0; i < this.getQuantity(); i++) { if (this.getChild(i) instanceof TerrainQuad) { ((TerrainQuad) getChild(i)).attachBoundChildren(parent); } else if (this.getChild(i) instanceof TerrainPatch) { BoundingVolume bv = getChild(i).getWorldBound(); if (bv instanceof BoundingBox) { attachBoundingBox((BoundingBox)bv, parent); } } } BoundingVolume bv = getWorldBound(); if (bv instanceof BoundingBox) { attachBoundingBox((BoundingBox)bv, parent); } }
/** * Helper function used to recursively populate the outputGeometryList * with geometry children of scene node * * @param camera * @param scene * @param outputGeometryList */ private static void addGeometriesInCamFrustumFromNode(Camera camera, Node scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) { if (scene.getCullHint() == Spatial.CullHint.Always) return; camera.setPlaneState(0); if (camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside) { for (Spatial child: scene.getChildren()) { if (child instanceof Node) addGeometriesInCamFrustumFromNode(camera, (Node)child, mode, outputGeometryList); else if (child instanceof Geometry && child.getCullHint() != Spatial.CullHint.Always) { camera.setPlaneState(0); if (checkShadowMode(child.getShadowMode(), mode) && !((Geometry)child).isGrouped() && camera.contains(child.getWorldBound()) != Camera.FrustumIntersect.Outside) { outputGeometryList.add((Geometry)child); } } } } }
int planeState = camera.getPlaneState(); camera.setPlaneState(0); inFrustum = camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside && scene.checkCulling(vpCamera); camera.setPlaneState(planeState);
public void makeMissile() { Vector3f pos = spaceCraft.getWorldTranslation().clone(); Quaternion rot = spaceCraft.getWorldRotation(); Vector3f dir = rot.getRotationColumn(2); Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml"); missile.scale(0.5f); missile.rotate(0, FastMath.PI, 0); missile.updateGeometricState(); BoundingBox box = (BoundingBox) missile.getWorldBound(); final Vector3f extent = box.getExtent(null); BoxCollisionShape boxShape = new BoxCollisionShape(extent); missile.setName("Missile"); missile.rotate(rot); missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0)); missile.setLocalRotation(hoverControl.getPhysicsRotation()); missile.setShadowMode(ShadowMode.Cast); RigidBodyControl control = new BombControl(assetManager, boxShape, 20); control.setLinearVelocity(dir.mult(100)); control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03); missile.addControl(control); rootNode.attachChild(missile); getPhysicsSpace().add(missile); }
@Override public void computeLastDistance(Spatial owner) { if (owner.getWorldBound() != null) { BoundingVolume bv = owner.getWorldBound(); lastDistance = bv.distanceSquaredTo(position); } else { lastDistance = owner.getWorldTranslation().distanceSquared(position); } }
@Override public void computeLastDistance(Spatial owner) { if (owner.getWorldBound() != null) { BoundingVolume bv = owner.getWorldBound(); lastDistance = bv.distanceSquaredTo(position); } else { lastDistance = owner.getWorldTranslation().distanceSquared(position); } }
private void fixRefreshFlags(){ // force transforms to update below this node spatial.updateGeometricState(); // force world bound to update Spatial rootNode = spatial; while (rootNode.getParent() != null){ rootNode = rootNode.getParent(); } rootNode.getWorldBound(); }
private void fixRefreshFlags(){ // force transforms to update below this node spatial.updateGeometricState(); // force world bound to update Spatial rootNode = spatial; while (rootNode.getParent() != null){ rootNode = rootNode.getParent(); } rootNode.getWorldBound(); }
public static Vector3f getCenterBoinding(Spatial spatial) { spatial.updateModelBound(); BoundingVolume wb = spatial.getWorldBound(); if (wb == null) { return spatial.getWorldTranslation(); } else { return wb.getCenter(); } }
public static Vector3f getMinBounding(Spatial spatial) { spatial.updateModelBound(); BoundingVolume wb = spatial.getWorldBound(); if (wb instanceof BoundingBox) { BoundingBox bb = (BoundingBox) wb; Vector3f min = new Vector3f(); return bb.getMin(min); } else if (wb instanceof BoundingSphere) { BoundingSphere bs = (BoundingSphere) wb; float radius = bs.getRadius(); return new Vector3f(-radius, -radius, -radius); } return spatial.getWorldTranslation(); }