/** * Compute the Zfar in the model vieuw to adjust the Zfar distance for the splits calculation */ public static float computeZFar(GeometryList occ, GeometryList recv, Camera cam) { Matrix4f mat = cam.getViewMatrix(); BoundingBox bbOcc = ShadowUtil.computeUnionBound(occ, mat); BoundingBox bbRecv = ShadowUtil.computeUnionBound(recv, mat); return min(max(bbOcc.getZExtent() - bbOcc.getCenter().z, bbRecv.getZExtent() - bbRecv.getCenter().z), cam.getFrustumFar()); } }
/** * This method converts the given point into 3D UV coordinates. * * @param boundingBox * the bounding box of the mesh * @param point * the point to be transformed * @param uvs * the result UV coordinates */ private void toTextureUV(BoundingBox boundingBox, Vector3f point, float[] uvs) { uvs[0] = (point.x - boundingBox.getCenter().x) / (boundingBox.getXExtent() == 0 ? 1 : boundingBox.getXExtent()); uvs[1] = (point.y - boundingBox.getCenter().y) / (boundingBox.getYExtent() == 0 ? 1 : boundingBox.getYExtent()); uvs[2] = (point.z - boundingBox.getCenter().z) / (boundingBox.getZExtent() == 0 ? 1 : boundingBox.getZExtent()); // UVS cannot go outside <0, 1> range, but since we are generating texture for triangle envelope it might happen that // some points of the envelope will exceet the bounding box of the mesh thus generating uvs outside the range for (int i = 0; i < 3; ++i) { uvs[i] = FastMath.clamp(uvs[i], 0, 1); } }
/** * This method returns the bounding sphere of the given geometries. * * @param geometries * the list of geometries * @return bounding sphere of the given geometries */ /* package */static BoundingSphere getBoundingSphere(Geometry... geometries) { BoundingSphere result = null; for (Geometry geometry : geometries) { geometry.updateModelBound(); BoundingVolume bv = geometry.getModelBound(); if (bv instanceof BoundingBox) { BoundingBox bb = (BoundingBox) bv; float r = Math.max(bb.getXExtent(), bb.getYExtent()); r = Math.max(r, bb.getZExtent()); return new BoundingSphere(r, bb.getCenter()); } else if (bv instanceof BoundingSphere) { return (BoundingSphere) bv; } else { throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName()); } } return result; }
/** * This method returns the bounding tube of the given geometries. * * @param geometries * the list of geometries * @return bounding tube of the given geometries */ /* package */static BoundingTube getBoundingTube(Geometry... geometries) { BoundingTube result = null; for (Geometry geometry : geometries) { BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometry); Vector3f max = bb.getMax(null); Vector3f min = bb.getMin(null); float radius = Math.max(max.x - min.x, max.y - min.y) * 0.5f; BoundingTube bt = new BoundingTube(radius, max.z - min.z, bb.getCenter()); if (result == null) { result = bt; } else { result.merge(bt); } } return result; }
Vector3f topLeft = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x-bbox.getXExtent(), 0, bbox.getCenter().z-bbox.getZExtent())); Vector3f topRight = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x+bbox.getXExtent(), 0, bbox.getCenter().z-bbox.getZExtent())); Vector3f bottomLeft = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x-bbox.getXExtent(), 0, bbox.getCenter().z+bbox.getZExtent())); Vector3f bottomRight = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x+bbox.getXExtent(), 0, bbox.getCenter().z+bbox.getZExtent()));
/** * Create a geometry suitable for visualizing the specified bounding box. * * @param bbox the bounding box (not null) * @return a new Geometry instance in world space */ public static Geometry makeGeometry(BoundingBox bbox) { float xExtent = bbox.getXExtent(); float yExtent = bbox.getYExtent(); float zExtent = bbox.getZExtent(); WireBox mesh = new WireBox(xExtent, yExtent, zExtent); Geometry result = new Geometry("bounding box", mesh); Vector3f center = bbox.getCenter(); result.setLocalTranslation(center); return result; } }
/** * used by attachBoundChildren() */ private void attachBoundingBox(BoundingBox bb, Node parent) { WireBox wb = new WireBox(bb.getXExtent(), bb.getYExtent(), bb.getZExtent()); Geometry g = new Geometry(); g.setMesh(wb); g.setLocalTranslation(bb.getCenter()); parent.attachChild(g); }
public void updateBoindPoints(Vector3f[] points) { BoundingBox bb = (BoundingBox) batch.getWorldBound(); float xe = bb.getXExtent(); float ye = bb.getYExtent(); float ze = bb.getZExtent(); float x = bb.getCenter().x; float y = bb.getCenter().y; float z = bb.getCenter().z; points[0].set(new Vector3f(x - xe, y - ye, z - ze)); points[1].set(new Vector3f(x - xe, y + ye, z - ze)); points[2].set(new Vector3f(x + xe, y + ye, z - ze)); points[3].set(new Vector3f(x + xe, y - ye, z - ze)); points[4].set(new Vector3f(x + xe, y - ye, z + ze)); points[5].set(new Vector3f(x - xe, y - ye, z + ze)); points[6].set(new Vector3f(x - xe, y + ye, z + ze)); points[7].set(new Vector3f(x + xe, y + ye, z + ze)); } }
float yOffset = Math.max(0, bb.getCenter().y + bb.getYExtent()); label.move(0, label.getSize() + yOffset + 2, 0); label.setColor(new ColorRGBA(0, 0.2f, 0, 1f)); geom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); geom.getMaterial().setColor("Color", ColorRGBA.Red); geom.setLocalTranslation(bb.getCenter()); result.attachChild(geom); float x1 = bb.getCenter().x - bb.getXExtent(); float x2 = bb.getCenter().x + bb.getXExtent(); float y1 = bb.getCenter().y - bb.getYExtent(); float y2 = bb.getCenter().y + bb.getYExtent(); System.out.println("xy1:" + x1 + ", " + y1 + " xy2:" + x2 + ", " + y2); int width = (int)Math.round(x2 - Math.min(0, x1)); down.move(0, bb.getCenter().y - bb.getYExtent() - 1, 0); result.attachChild(down);
float back_wheel_h = (wheelRadius * 1.7f) - 1f; float front_wheel_h = (wheelRadius * 1.9f) - 1f; player.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true); wheel_fl.center(); box = (BoundingBox) wheel_fl.getModelBound(); player.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true); wheel_br.center(); box = (BoundingBox) wheel_br.getModelBound(); player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false); wheel_bl.center(); box = (BoundingBox) wheel_bl.getModelBound(); player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Vector3f otherCenter = box.getCenter(); Vector3f radVect = vars.vect4; radVect.set(box.getXExtent(), box.getYExtent(), box.getZExtent());
float split = currentBox.getCenter().get(axis); int pivot = sortTriangles(l, r, split, axis); if (pivot == l || pivot == r) {
public void makeBoxWire(BoundingBox box) { Vector3f[] points = new Vector3f[8]; for (int i = 0; i < 8; i++) { points[i] = new Vector3f(); } points[0].set(-1, -1, 1); points[1].set(-1, 1, 1); points[2].set(1, 1, 1); points[3].set(1, -1, 1); points[4].set(-1, -1, -1); points[5].set(-1, 1, -1); points[6].set(1, 1, -1); points[7].set(1, -1, -1); WireFrustum frustumShape = new WireFrustum(points); aabbGeom = new Geometry("box", frustumShape); aabbGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); aabbGeom.getMaterial().getAdditionalRenderState().setWireframe(true); aabbGeom.setLocalTranslation(box.getCenter()); aabbGeom.setLocalScale(box.getXExtent(), box.getYExtent(), box.getZExtent()); rootNode.attachChild(aabbGeom); }
this.guiBounding.setYExtent(cam.guiBounding.getYExtent()); this.guiBounding.setZExtent(cam.guiBounding.getZExtent()); this.guiBounding.setCenter(cam.guiBounding.getCenter()); this.guiBounding.setCheckPlane(cam.guiBounding.getCheckPlane());
@Override public boolean intersectsBox(BoundingBox box, TempVars vars) { Vector3f axis1 = getScaledAxis(0, vars.vect1); Vector3f axis2 = getScaledAxis(1, vars.vect2); Vector3f axis3 = getScaledAxis(2, vars.vect3); Vector3f tn = vars.vect4; Plane p = vars.plane; Vector3f c = box.getCenter(); p.setNormal(0, 0, -1); p.setConstant(-(c.z + box.getZExtent())); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(0, 0, 1); p.setConstant(c.z - box.getZExtent()); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(0, -1, 0); p.setConstant(-(c.y + box.getYExtent())); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(0, 1, 0); p.setConstant(c.y - box.getYExtent()); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(-1, 0, 0); p.setConstant(-(c.x + box.getXExtent())); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(1, 0, 0); p.setConstant(c.x - box.getXExtent()); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; return true; }
Vector3f diff = ray.origin.subtract(getCenter(vars.vect2), vars.vect1);
chaseCam.setLookAtOffset(b.getCenter()); chaseCam.setDefaultDistance(5); chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);