/** * @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 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; } }
@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); } }
@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); } }
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();
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();
final double camWaterDist = waterPlane.pseudoDistance(cam.getLocation()); aboveWater = camWaterDist >= 0;
final double camWaterDist = waterPlane.pseudoDistance(cam.getLocation()); aboveWater = camWaterDist >= 0;