@Override public Plane clone() { return new Plane(this); }
public double getWaterHeight() { return waterPlane.getConstant(); }
/** * Used with serialization. Not to be called manually. * * @param in * ObjectInput * @throws IOException * @throws ClassNotFoundException */ @Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { setNormal((Vector3) in.readObject()); setConstant(in.readDouble()); }
@Test public void testGetSet() { final Plane plane = new Plane(); assertEquals(Vector3.UNIT_Y, plane.getNormal()); assertTrue(plane.getConstant() == 0.0); plane.setNormal(Vector3.UNIT_X); plane.setConstant(1.0); assertEquals(Vector3.UNIT_X, plane.getNormal()); assertTrue(plane.getConstant() == 1.0); final Plane plane2 = new Plane(plane); assertEquals(Vector3.UNIT_X, plane2.getNormal()); assertTrue(plane.getConstant() == 1.0); final Plane plane3 = new Plane(Vector3.NEG_UNIT_Z, 2.5); assertEquals(Vector3.NEG_UNIT_Z, plane3.getNormal()); assertTrue(plane3.getConstant() == 2.5); final Plane plane4 = new Plane().setPlanePoints(new Vector3(1, 1, 1), new Vector3(2, 1, 1), new Vector3(2, 2, 1)); assertEquals(Vector3.UNIT_Z, plane4.getNormal()); assertTrue(plane4.getConstant() == 1.0); }
planeNormal.addLocal(_direction.getX() * _coeffLeft[1], _direction.getY() * _coeffLeft[1], _direction.getZ() * _coeffLeft[1]); _worldPlane[LEFT_PLANE].setNormal(planeNormal); _worldPlane[LEFT_PLANE].setConstant(_location.dot(planeNormal)); planeNormal.addLocal(_direction.getX() * _coeffRight[1], _direction.getY() * _coeffRight[1], _direction.getZ() * _coeffRight[1]); _worldPlane[RIGHT_PLANE].setNormal(planeNormal); _worldPlane[RIGHT_PLANE].setConstant(_location.dot(planeNormal)); planeNormal.addLocal(_direction.getX() * _coeffBottom[1], _direction.getY() * _coeffBottom[1], _direction.getZ() * _coeffBottom[1]); _worldPlane[BOTTOM_PLANE].setNormal(planeNormal); _worldPlane[BOTTOM_PLANE].setConstant(_location.dot(planeNormal)); planeNormal.addLocal(_direction.getX() * _coeffTop[1], _direction.getY() * _coeffTop[1], _direction.getZ() * _coeffTop[1]); _worldPlane[TOP_PLANE].setNormal(planeNormal); _worldPlane[TOP_PLANE].setConstant(_location.dot(planeNormal)); _worldPlane[LEFT_PLANE].setConstant(_worldPlane[LEFT_PLANE].getConstant() + _frustumLeft); _worldPlane[RIGHT_PLANE].setConstant(_worldPlane[RIGHT_PLANE].getConstant() - _frustumRight); } else { _worldPlane[LEFT_PLANE].setConstant(_worldPlane[LEFT_PLANE].getConstant() - _frustumLeft); _worldPlane[RIGHT_PLANE].setConstant(_worldPlane[RIGHT_PLANE].getConstant() + _frustumRight); _worldPlane[TOP_PLANE].setConstant(_worldPlane[TOP_PLANE].getConstant() + _frustumTop); _worldPlane[BOTTOM_PLANE].setConstant(_worldPlane[BOTTOM_PLANE].getConstant() - _frustumBottom); } else {
protected Vector3 getNewOffset(final Vector2 oldMouse, final MouseState current, final Camera camera, final InteractManager manager) { // make plane object final Plane pickPlane = new Plane().setPlanePoints(_calcVec3A, _calcVec3B, _calcVec3C); // find out where we were hitting the plane before getPickRay(oldMouse, camera); if (!_calcRay.intersectsPlane(pickPlane, _calcVec3A)) { return _calcVec3A.zero(); } // find out where we are hitting the plane now getPickRay(new Vector2(current.getX(), current.getY()), camera); if (!_calcRay.intersectsPlane(pickPlane, _calcVec3B)) { return _calcVec3A.zero(); } // convert to target coord space final Node parent = manager.getSpatialTarget().getParent(); if (parent != null) { parent.getWorldTransform().applyInverse(_calcVec3A); parent.getWorldTransform().applyInverse(_calcVec3B); } return _calcVec3B.subtractLocal(_calcVec3A); } }
@Test public void testValid() { final Plane plane1 = new Plane(); final Plane plane2 = new Plane(new Vector3(Double.NaN, 0, 0), 0.5); final Plane plane3 = new Plane(Vector3.UNIT_X, Double.NaN); final Plane plane4 = new Plane(Vector3.UNIT_X, Double.POSITIVE_INFINITY); assertTrue(Plane.isValid(plane1)); assertFalse(Plane.isValid(plane2)); assertFalse(Plane.isValid(plane3)); assertFalse(Plane.isValid(plane4)); plane4.setConstant(1); assertTrue(Plane.isValid(plane4)); assertFalse(Plane.isValid(null)); }
final double camWaterDist = waterPlane.pseudoDistance(cam.getLocation()); aboveWater = camWaterDist >= 0; if (useProjectedShader) { setProperty("cameraPos", cam.getLocation()); setProperty("waterHeight", (float) waterPlane.getConstant()); setProperty("amplitude", (float) waterMaxAmplitude); setProperty("heightFalloffStart", (float) heightFalloffStart); final double heightTotal = clipBias + waterMaxAmplitude - waterPlane.getConstant(); final Vector4 clipPlane = Vector4.fetchTempInstance(); clipPlane.set(waterPlane.getNormal().getX(), waterPlane.getNormal().getY(), waterPlane.getNormal().getZ(), heightTotal); renderReflection(clipPlane); clipPlane.set(-waterPlane.getNormal().getX(), -waterPlane.getNormal().getY(), -waterPlane.getNormal().getZ(), -waterPlane.getConstant()); renderRefraction(clipPlane);
@Test public void testEquals() { // couple of equals validity tests final Plane plane1 = new Plane(); assertEquals(plane1, plane1); assertFalse(plane1.equals(null)); assertFalse(plane1.equals(new Vector2())); // throw in a couple pool accesses for coverage final Plane plane2 = Plane.fetchTempInstance(); plane2.set(plane1); assertEquals(plane1, plane2); assertNotSame(plane1, plane2); Plane.releaseTempInstance(plane2); // cover more of equals assertFalse(plane1.equals(new Plane(Vector3.UNIT_X, 0))); }
@Test public void testDistance() { final Plane plane1 = new Plane(Vector3.UNIT_Y, 1.0); final Vector3 point = new Vector3(0, 5, 0); assertTrue(4.0 == plane1.pseudoDistance(point)); assertEquals(Side.Outside, plane1.whichSide(point)); point.set(0, -4, 0); assertTrue(-5.0 == plane1.pseudoDistance(point)); assertEquals(Side.Inside, plane1.whichSide(point)); point.set(1, 1, 1); assertTrue(0.0 == plane1.pseudoDistance(point)); assertEquals(Side.Neither, plane1.whichSide(point)); }
@Override public void apply(final double dt, final Particle particle, final int index) { // Is particle alive, AND "under" our floor? if (particle.getStatus() == Particle.Status.Alive && _floor.pseudoDistance(particle.getPosition()) <= 0) { final Vector3 tempVect1 = Vector3.fetchTempInstance(); final double scale = particle.getVelocity().length(); tempVect1.set(particle.getVelocity()).divideLocal(scale); // normalize // Is the particle moving further into the floor? if (_floor.getNormal().smallestAngleBetween(tempVect1) > MathUtils.HALF_PI) { // reflect our velocity vector across the floor plane _floor.reflectVector(tempVect1, tempVect1); // apply the "bounciness" factor tempVect1.multiplyLocal(scale * _bounciness); // write back to particle particle.setVelocity(tempVect1); } Vector3.releaseTempInstance(tempVect1); } }
@Test public void testSimpleHash() { // Just a simple sanity check. final Plane plane1 = new Plane(Vector3.UNIT_Y, 2); final Plane plane2 = new Plane(Vector3.UNIT_Y, 2); final Plane plane3 = new Plane(Vector3.UNIT_Z, 2); assertTrue(plane1.hashCode() == plane2.hashCode()); assertTrue(plane1.hashCode() != plane3.hashCode()); }
/** * Set base height of the waterplane(Used for reflecting the camera for rendering reflection) * * @param waterHeight * Waterplane height */ public void setWaterHeight(final double waterHeight) { waterPlane.setConstant(waterHeight); }
/** * Set the normal of the waterplane(Used for reflecting the camera for rendering reflection) * * @param normal * Waterplane normal */ public void setNormal(final Vector3 normal) { waterPlane.setNormal(normal); }
@Test public void testReflect() { final Plane plane1 = new Plane(Vector3.UNIT_X, 5.0); assertEquals(new Vector3(), plane1.reflectVector(new Vector3(), new Vector3())); assertEquals(new Vector3(-1, 0, 0), plane1.reflectVector(new Vector3(1, 0, 0), null)); assertEquals(new Vector3(-1, 1, 1).normalizeLocal(), plane1.reflectVector(new Vector3(1, 1, 1).normalizeLocal(), null)); assertEquals(new Vector3(-3, 2, -1).normalizeLocal(), plane1.reflectVector(new Vector3(3, 2, -1).normalizeLocal(), null)); final Plane plane2 = new Plane(Vector3.UNIT_Z, 1.0); assertEquals(new Vector3(), plane2.reflectVector(new Vector3(), new Vector3())); assertEquals(new Vector3(0, 0, -1), plane2.reflectVector(new Vector3(0, 0, 1), null)); assertEquals(new Vector3(1, 1, -1).normalizeLocal(), plane2.reflectVector(new Vector3(1, 1, 1).normalizeLocal(), null)); assertEquals(new Vector3(3, 2, 1).normalizeLocal(), plane2.reflectVector(new Vector3(3, 2, -1).normalizeLocal(), null)); } }
camLocation.set(cam.getLocation()); double planeDistance = waterPlane.pseudoDistance(camLocation); calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f); camReflectPos.set(camLocation.subtractLocal(calcVect)); planeDistance = waterPlane.pseudoDistance(camLocation); calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f); camReflectDir.set(camLocation.subtractLocal(calcVect)).subtractLocal(camReflectPos).normalizeLocal(); planeDistance = waterPlane.pseudoDistance(camLocation); calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f); camReflectUp.set(camLocation.subtractLocal(calcVect)).subtractLocal(camReflectPos).normalizeLocal();
/** * @param point * @return the side of this plane on which the given point lies. * @see Side * @throws NullPointerException * if point is null. */ @Override public Side whichSide(final ReadOnlyVector3 point) { final double dis = pseudoDistance(point); if (dis < 0) { return Side.Inside; } else if (dis > 0) { return Side.Outside; } else { return Side.Neither; } }
/** * @param plane * The imaginary floor plane * @param bounciness * Bounciness is the factor of multiplication when bouncing off the floor. A bounciness factor of 1 means * the ball leaves the floor with the same velocity as it hit the floor, much like a rubber ball. */ public FloorInfluence(final ReadOnlyPlane plane, final double bounciness) { _bounciness = bounciness; _floor.set(plane); }