use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.
the class CurvesHelper method transformBevel.
/**
* The method transforms the bevel along the curve.
*
* @param bevel
* the bevel to be transformed
* @param prevPos
* previous curve point
* @param currPos
* current curve point (here the center of the new bevel will be
* set)
* @param nextPos
* next curve point
* @return points of transformed bevel
*/
protected Vector3f[] transformBevel(Vector3f[] bevel, Vector3f prevPos, Vector3f currPos, Vector3f nextPos) {
bevel = bevel.clone();
// currPos and directionVector define the line in 3D space
Vector3f directionVector = prevPos != null ? currPos.subtract(prevPos) : nextPos.subtract(currPos);
directionVector.normalizeLocal();
// plane is described by equation: Ax + By + Cz + D = 0 where planeNormal = [A, B, C] and D = -(Ax + By + Cz)
Vector3f planeNormal = null;
if (prevPos != null) {
planeNormal = currPos.subtract(prevPos).normalizeLocal();
if (nextPos != null) {
planeNormal.addLocal(nextPos.subtract(currPos).normalizeLocal()).normalizeLocal();
}
} else {
planeNormal = nextPos.subtract(currPos).normalizeLocal();
}
// D = -(Ax + By + Cz)
float D = -planeNormal.dot(currPos);
// now we need to compute paralell cast of each bevel point on the plane, the leading line is already known
// parametric equation of a line: x = px + vx * t; y = py + vy * t; z = pz + vz * t
// where p = currPos and v = directionVector
// using x, y and z in plane equation we get value of 't' that will allow us to compute the point where plane and line cross
float temp = planeNormal.dot(directionVector);
for (int i = 0; i < bevel.length; ++i) {
float t = -(planeNormal.dot(bevel[i]) + D) / temp;
if (fixUpAxis) {
bevel[i] = new Vector3f(bevel[i].x + directionVector.x * t, bevel[i].y + directionVector.y * t, bevel[i].z + directionVector.z * t);
} else {
bevel[i] = new Vector3f(bevel[i].x + directionVector.x * t, -bevel[i].z + directionVector.z * t, bevel[i].y + directionVector.y * t);
}
}
return bevel;
}
use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.
the class Camera method setClipPlane.
/**
* Sets a clipPlane for this camera.
* The clipPlane is used to recompute the
* projectionMatrix using the plane as the near plane
* This technique is known as the oblique near-plane clipping method introduced by Eric Lengyel
* more info here
* <ul>
* <li><a href="http://www.terathon.com/code/oblique.html">http://www.terathon.com/code/oblique.html</a>
* <li><a href="http://aras-p.info/texts/obliqueortho.html">http://aras-p.info/texts/obliqueortho.html</a>
* <li><a href="http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html">http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html</a>
* </ul>
*
* Note that this will work properly only if it's called on each update, and be aware that it won't work properly with the sky bucket.
* if you want to handle the sky bucket, look at how it's done in SimpleWaterProcessor.java
* @param clipPlane the plane
* @param side the side the camera stands from the plane
*/
public void setClipPlane(Plane clipPlane, Plane.Side side) {
float sideFactor = 1;
if (side == Plane.Side.Negative) {
sideFactor = -1;
}
//we are on the other side of the plane no need to clip anymore.
if (clipPlane.whichSide(location) == side) {
return;
}
TempVars vars = TempVars.get();
try {
Matrix4f p = projectionMatrixOverride.set(projectionMatrix);
Matrix4f ivm = viewMatrix;
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);
Vector4f v = vars.vect4f2.set(0, 0, 0, 0);
v.x = (Math.signum(clipPlaneV.x) + p.m02) / p.m00;
v.y = (Math.signum(clipPlaneV.y) + p.m12) / p.m11;
v.z = -1.0f;
v.w = (1.0f + p.m22) / p.m23;
//clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w;
float dot = clipPlaneV.dot(v);
Vector4f c = clipPlaneV.multLocal(2.0f / dot);
p.m20 = c.x - p.m30;
p.m21 = c.y - p.m31;
p.m22 = c.z - p.m32;
p.m23 = c.w - p.m33;
setProjectionMatrix(p);
} finally {
vars.release();
}
}
use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.
the class WaterFilter method preFrame.
@Override
protected void preFrame(float tpf) {
time = time + (tpf * speed);
material.setFloat("Time", time);
Camera sceneCam = viewPort.getCamera();
biasMatrix.mult(sceneCam.getViewProjectionMatrix(), textureProjMatrix);
material.setMatrix4("TextureProjMatrix", textureProjMatrix);
material.setVector3("CameraPosition", sceneCam.getLocation());
//material.setFloat("WaterHeight", waterHeight);
//update reflection cam
//plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
//reflectionProcessor.setReflectionClipPlane(plane);
WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam);
//if we're under water no need to compute reflection
if (sceneCam.getLocation().y >= waterHeight) {
boolean rtb = true;
if (!renderManager.isHandleTranslucentBucket()) {
renderManager.setHandleTranslucentBucket(true);
rtb = false;
}
renderManager.renderViewPort(reflectionView, tpf);
if (!rtb) {
renderManager.setHandleTranslucentBucket(false);
}
renderManager.setCamera(sceneCam, false);
renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
underWater = false;
} else {
underWater = true;
}
}
use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.
the class TestOnlineJar method simpleInitApp.
@Override
public void simpleInitApp() {
// create a simple plane/quad
Quad quadMesh = new Quad(1, 1);
quadMesh.updateGeometry(1, 1, true);
Geometry quad = new Geometry("Textured Quad", quadMesh);
assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/town.zip", HttpZipLocator.class);
assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
Picture pic1 = new Picture("Picture1");
pic1.move(0, 0, -1);
pic1.setPosition(0, 0);
pic1.setWidth(128);
pic1.setHeight(128);
pic1.setImage(assetManager, "grass.jpg", false);
guiNode.attachChild(pic1);
Picture pic2 = new Picture("Picture1");
pic2.move(0, 0, -1);
pic2.setPosition(128, 0);
pic2.setWidth(128);
pic2.setHeight(128);
pic2.setImage(assetManager, "glasstile2.png", false);
guiNode.attachChild(pic2);
}
use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.
the class TestSimplePhysics method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
rootNode.attachChild(physicsSphere);
getPhysicsSpace().add(physicsSphere);
// Add a physics sphere to the world using the collision shape from sphere one
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
rootNode.attachChild(physicsSphere2);
getPhysicsSpace().add(physicsSphere2);
// Add a physics box to the world
Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
rootNode.attachChild(physicsBox);
getPhysicsSpace().add(physicsBox);
// Add a physics cylinder to the world
Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
rootNode.attachChild(physicsCylinder);
getPhysicsSpace().add(physicsCylinder);
// an obstacle mesh, does not move (mass=0)
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor mesh, does not move (mass=0)
Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
// Join the physics objects with a Point2Point joint
// PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0));
// PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
// getPhysicsSpace().add(joint);
}
Aggregations