/** * Serialization only. Do not use. */ public Camera() { worldPlane = new Plane[MAX_WORLD_PLANES]; for (int i = 0; i < MAX_WORLD_PLANES; i++) { worldPlane[i] = new Plane(); } }
/** * Set the water plane for this processor. * @param plane */ public void setPlane(Plane plane) { this.plane.setConstant(plane.getConstant()); this.plane.setNormal(plane.getNormal()); updateClipPlanes(); }
private void updateClipPlanes() { reflectionClipPlane = plane.clone(); reflectionClipPlane.setConstant(reflectionClipPlane.getConstant() + reflectionClippingOffset); refractionClipPlane = plane.clone(); refractionClipPlane.setConstant(refractionClipPlane.getConstant() + refractionClippingOffset); }
/** * Instantiate the configured shape in Bullet. */ protected void createShape() { objectId = createShape(plane.getNormal(), plane.getConstant()); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); // objectId = new StaticPlaneShape(Converter.convert(plane.getNormal()),plane.getConstant()); // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); setScale(scale); setMargin(margin); }
if (clipPlane.whichSide(location) == side) { return; Vector3f point = clipPlane.getNormal().mult(clipPlane.getConstant(), vars.vect1); Vector3f pp = ivm.mult(point, vars.vect2); Vector3f pn = ivm.multNormal(clipPlane.getNormal(), vars.vect3); Vector4f clipPlaneV = vars.vect4f1.set(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor);
private boolean insidePlane(Plane p, Vector3f axis1, Vector3f axis2, Vector3f axis3, Vector3f tn) { // transform the plane normal in the box local space. tn.set(axis1.dot(p.getNormal()), axis2.dot(p.getNormal()), axis3.dot(p.getNormal())); // distance check float radius = FastMath.abs(tn.x) + FastMath.abs(tn.y) + FastMath.abs(tn.z); float distance = p.pseudoDistance(transform.getTranslation()); if (distance < -radius) { return false; } return true; }
plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y)); reflectionProcessor.setReflectionClipPlane(plane); boolean inv = false; inv = true; Vector3f loc = plane.reflect(sceneCam.getLocation(), new Vector3f()); reflectionCam.setLocation(loc); reflectionCam.setFrustum(sceneCam.getFrustumNear(), float planeDistance = plane.pseudoDistance(vars.vect1); vars.vect2.set(plane.getNormal()).multLocal(planeDistance * 2.0f); vars.vect3.set(vars.vect1.subtractLocal(vars.vect2)).subtractLocal(loc).normalizeLocal().negateLocal();
center.mult(invDim, sCenter); triPlane.setPlanePoints(scaledTri); float normalDotVelocity = triPlane.getNormal().dot(sVelocity); boolean embedded = false; float signedDistanceToPlane = triPlane.pseudoDistance(sCenter); if (normalDotVelocity == 0.0f){ contactPoint.multLocal(t0); contactPoint.addLocal(sCenter); contactPoint.subtractLocal(triPlane.getNormal());
public VirtualFloor(BasicGoodyCtx bgc, Ident floorUri, Vector3f position, ColorRGBA color, boolean rigidBodyPhysFlag) { super(bgc, floorUri); setPosition(position, VWorldEntity.QueueingStyle.QUEUE_AND_RETURN); // Constants and collision shape below taken from PhysicsStuffBuilder. // How much of this stuff do we want to come from repo instead? Mesh floorBox = new Box(140f, 0.25f, 140f); Plane plane = new Plane(); plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y); if (color == null) { color = DEFAULT_COLOR; } addGeometry(floorBox, null, color, new Quaternion(), new PlaneCollisionShape(plane), 0f); }
inv = true; Vector3f loc = plane.reflect(sceneCam.getLocation(), new Vector3f()); reflectionCam.setLocation(loc); reflectionCam.setFrustum(sceneCam.getFrustumNear(), float planeDistance = plane.pseudoDistance(vect1); vect2.set(plane.getNormal()).multLocal(planeDistance * 2.0f); vect3.set(vect1.subtractLocal(vect2)).subtractLocal(loc).normalizeLocal().negateLocal();
@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; }
@Override public void simpleUpdate(float tpf) { TempVars vars = TempVars.get(); boolean intersect = spotLight.intersectsFrustum(frustumCam, vars); if (intersect) { geom.getMaterial().setColor("Diffuse", ColorRGBA.Green); } else { geom.getMaterial().setColor("Diffuse", ColorRGBA.White); } Vector3f farPoint = vars.vect1.set(spotLight.getPosition()).addLocal(vars.vect2.set(spotLight.getDirection()).multLocal(spotLight.getSpotRange())); //computing the radius of the base disc float farRadius = (spotLight.getSpotRange() / FastMath.cos(spotLight.getSpotOuterAngle())) * FastMath.sin(spotLight.getSpotOuterAngle()); //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector Vector3f perpDirection = vars.vect2.set(spotLight.getDirection()).crossLocal(frustumCam.getWorldPlane(3).getNormal()).normalizeLocal().crossLocal(spotLight.getDirection()); //projecting the far point on the base disc perimeter Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius)); vars.release(); // boxGeo.setLocalTranslation(spotLight.getPosition()); // boxGeo.setLocalTranslation(projectedPoint); } }
@Override public Camera clone() { try { Camera cam = (Camera) super.clone(); cam.viewportChanged = true; cam.planeState = 0; cam.worldPlane = new Plane[MAX_WORLD_PLANES]; for (int i = 0; i < worldPlane.length; i++) { cam.worldPlane[i] = worldPlane[i].clone(); } cam.coeffLeft = new float[2]; cam.coeffRight = new float[2]; cam.coeffBottom = new float[2]; cam.coeffTop = new float[2]; cam.location = location.clone(); cam.rotation = rotation.clone(); if (projectionMatrixOverride != null) { cam.projectionMatrixOverride = projectionMatrixOverride.clone(); } cam.viewMatrix = viewMatrix.clone(); cam.projectionMatrix = projectionMatrix.clone(); cam.viewProjectionMatrix = viewProjectionMatrix.clone(); cam.guiBounding = (BoundingBox) guiBounding.clone(); cam.update(); return cam; } catch (CloneNotSupportedException ex) { throw new AssertionError(); } }
/** * Set the water plane using an origin (location) and a normal (reflection direction). * @param origin Set to 0,-6,0 if your water quad is at that location for correct reflection * @param normal Set to 0,1,0 (Vector3f.UNIT_Y) for normal planar water */ public void setPlane(Vector3f origin, Vector3f normal) { this.plane.setOriginNormal(origin, normal); updateClipPlanes(); }
Vector3f reflectLeft = vars.vect4; Vector3f camLoc = vars.vect5; camLoc = plane.reflect(sceneCam.getLocation(), camLoc); reflectionCam.setLocation(camLoc); reflectionCam.setFrustum(sceneCam.getFrustumNear(), reflectDirection = plane.reflect(sceneTarget, reflectDirection); reflectDirection.subtractLocal(camLoc); reflectUp = plane.reflect(sceneTarget, reflectUp); reflectUp.subtractLocal(camLoc); reflectLeft = plane.reflect(sceneTarget, reflectLeft); reflectLeft.subtractLocal(camLoc);
/** * * @param p * @param loc * @return true if the ray collides with the given Plane */ public boolean intersectsWherePlane(Plane p, Vector3f loc) { float denominator = p.getNormal().dot(direction); if (denominator > -FastMath.FLT_EPSILON && denominator < FastMath.FLT_EPSILON) { return false; // coplanar } float numerator = -(p.getNormal().dot(origin) - p.getConstant()); float ratio = numerator / denominator; if (ratio < FastMath.FLT_EPSILON) { return false; // intersects behind origin } loc.set(direction).multLocal(ratio).addLocal(origin); return true; }
if (clipPlane.whichSide(location) == side) { return; Vector3f point = clipPlane.getNormal().mult(clipPlane.getConstant()); Vector3f pp = ivm.mult(point); Vector3f pn = ivm.multNormal(clipPlane.getNormal(), null); Vector4f clipPlaneV = new Vector4f(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor);
/** * <code>whichSide</code> takes a plane (typically provided by a view * frustum) to determine which side this bound is on. * * @param plane * the plane to check against. */ public Plane.Side whichSide(Plane plane) { float radius = FastMath.abs(xExtent * plane.getNormal().getX()) + FastMath.abs(yExtent * plane.getNormal().getY()) + FastMath.abs(zExtent * plane.getNormal().getZ()); float distance = plane.pseudoDistance(center); //changed to < and > to prevent floating point precision problems if (distance < -radius) { return Plane.Side.Negative; } else if (distance > radius) { return Plane.Side.Positive; } else { return Plane.Side.None; } }
center.mult(invDim, sCenter); triPlane.setPlanePoints(scaledTri); float normalDotVelocity = triPlane.getNormal().dot(sVelocity); boolean embedded = false; float signedDistanceToPlane = triPlane.pseudoDistance(sCenter); if (normalDotVelocity == 0.0f){ contactPoint.multLocal(t0); contactPoint.addLocal(sCenter); contactPoint.subtractLocal(triPlane.getNormal());
@Override public Camera clone() { try { Camera cam = (Camera) super.clone(); cam.viewportChanged = true; cam.planeState = 0; cam.worldPlane = new Plane[MAX_WORLD_PLANES]; for (int i = 0; i < worldPlane.length; i++) { cam.worldPlane[i] = worldPlane[i].clone(); } cam.coeffLeft = new float[2]; cam.coeffRight = new float[2]; cam.coeffBottom = new float[2]; cam.coeffTop = new float[2]; cam.location = location.clone(); cam.rotation = rotation.clone(); if (projectionMatrixOverride != null) { cam.projectionMatrixOverride = projectionMatrixOverride.clone(); } cam.viewMatrix = viewMatrix.clone(); cam.projectionMatrix = projectionMatrix.clone(); cam.viewProjectionMatrix = viewProjectionMatrix.clone(); cam.guiBounding = (BoundingBox) guiBounding.clone(); cam.update(); return cam; } catch (CloneNotSupportedException ex) { throw new AssertionError(); } }