/** * 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; }
/** * Compute bounds of a geomList * @param list * @param transform * @return */ public static BoundingBox computeUnionBound(GeometryList list, Transform transform) { BoundingBox bbox = new BoundingBox(); TempVars tempv = TempVars.get(); for (int i = 0; i < list.size(); i++) { BoundingVolume vol = list.get(i).getWorldBound(); BoundingVolume newVol = vol.transform(transform, tempv.bbox); //Nehon : prevent NaN and infinity values to screw the final bounding box if (!Float.isNaN(newVol.getCenter().x) && !Float.isInfinite(newVol.getCenter().x)) { bbox.mergeLocal(newVol); } } tempv.release(); return bbox; }
/** * Compute bounds of a geomList * @param list * @param mat * @return */ public static BoundingBox computeUnionBound(GeometryList list, Matrix4f mat) { BoundingBox bbox = new BoundingBox(); TempVars tempv = TempVars.get(); for (int i = 0; i < list.size(); i++) { BoundingVolume vol = list.get(i).getWorldBound(); BoundingVolume store = vol.transform(mat, tempv.bbox); //Nehon : prevent NaN and infinity values to screw the final bounding box if (!Float.isNaN(store.getCenter().x) && !Float.isInfinite(store.getCenter().x)) { bbox.mergeLocal(store); } } tempv.release(); return bbox; }
private int collideWithBoundingVolume(BoundingVolume boundingVolume, CollisionResults results) { if (boundingVolume instanceof BoundingBox) return collideWithBoundingBox((BoundingBox)boundingVolume, results); else if(boundingVolume instanceof BoundingSphere) { BoundingSphere sphere = (BoundingSphere) boundingVolume; BoundingBox bbox = new BoundingBox(boundingVolume.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius()); return collideWithBoundingBox(bbox, results); } return 0; }
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; }
/** * 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; }
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); }
public static Vector3f getCenterBoinding(Spatial spatial) { spatial.updateModelBound(); BoundingVolume wb = spatial.getWorldBound(); if (wb == null) { return spatial.getWorldTranslation(); } else { return wb.getCenter(); } }
/** * 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; }
/** * 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; }
protected void createCameras() { flyCam.setMoveSpeed(10f); flyCam.setDragToRotate(true);// to prevent mouse capture cam.setLocation(new Vector3f(7.0357456f, 11.175021f, 5.927986f)); //cam.setRotation(new Quaternion(-0.3325067f, 0.6662985f, -0.44692048f, -0.49572945f)); cam.lookAt(rootNode.getWorldBound().getCenter(), Vector3f.UNIT_Y); }
protected float getMinZ( BoundingVolume bv ) { if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return bb.getCenter().z - bb.getZExtent(); } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return bs.getCenter().z - bs.getRadius(); } Vector3f offset = bv.getCenter().add(0, 0, -1000); return offset.z + bv.distanceTo(offset); // untested }
protected float getMaxZ( BoundingVolume bv ) { if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return bb.getCenter().z + bb.getZExtent(); } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return bs.getCenter().z + bs.getRadius(); } else if( bv == null ) { // Apparently this can happen for empty nodes... return 0; } Vector3f offset = bv.getCenter().add(0, 0, 1000); return offset.z - bv.distanceTo(offset); }
private int collideWithBoundingVolume(BoundingVolume boundingVolume, CollisionResults results) { if (boundingVolume instanceof BoundingBox) return collideWithBoundingBox((BoundingBox)boundingVolume, results); else if(boundingVolume instanceof BoundingSphere) { BoundingSphere sphere = (BoundingSphere) boundingVolume; BoundingBox bbox = new BoundingBox(boundingVolume.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius()); return collideWithBoundingBox(bbox, results); } return 0; }
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; }
@Override protected void createCameras() { flyCam.setMoveSpeed(1f); flyCam.setDragToRotate(true);// to prevent mouse capture //flyCam.setEnabled(false); cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 0.01f, 1000f); Vector3f center = screenQR.getModelBound().getCenter(); center.multLocal(qrSize); screenLoc = screenQR.getWorldTranslation().add(center); initialPos(); }
@Override protected void createCameras() { flyCam.setMoveSpeed(1f); flyCam.setDragToRotate(true);// to prevent mouse capture //flyCam.setEnabled(false); cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 0.01f, 1000f); Vector3f center = screen.getModelBound().getCenter(); center.multLocal(qrSize); screenLoc = screen.getWorldTranslation().add(center); initialPos(); }
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); }