/** * <code>crossLocal</code> calculates the cross product of this vector * with a parameter vector v. * * @param v * the vector to take the cross product of with this. * @return this. */ public Vector3f crossLocal(Vector3f v) { return crossLocal(v.x, v.y, v.z); }
/** * A method that computes normal for a triangle defined by three vertices. * @param v1 first vertex * @param v2 second vertex * @param v3 third vertex * @return a normal for the face */ public static Vector3f computeNormal(Vector3f v1, Vector3f v2, Vector3f v3) { Vector3f a1 = v1.subtract(v2); Vector3f a2 = v3.subtract(v2); return a2.crossLocal(a1).normalizeLocal(); }
public Vector3f getNormal(){ Vector3f normal = new Vector3f(pointb); normal.subtractLocal(pointa).crossLocal(pointc.x-pointa.x, pointc.y-pointa.y, pointc.z-pointa.z); normal.normalizeLocal(); return normal; }
/** * Updates the local coordinate system from the localForward and localUp * vectors, adapts localForward, sets localForwardRotation quaternion to * local Z-forward rotation. */ protected void updateLocalCoordinateSystem() { //gravity vector has possibly changed, calculate new world forward (UNIT_Z) calculateNewForward(localForwardRotation, localForward, localUp); localLeft.set(localUp).crossLocal(localForward); rigidBody.setPhysicsRotation(localForwardRotation); updateLocalViewDirection(); }
private boolean pointsOnSameSide(Vector3f p1, Vector3f p2, Vector3f line1, Vector3f line2) { // V1 = (line2 - line1) x (p1 - line1) // V2 = (p2 - line1) x (line2 - line1) temp1.set(line2).subtractLocal(line1); temp3.set(temp1); temp2.set(p1).subtractLocal(line1); temp1.crossLocal(temp2); temp2.set(p2).subtractLocal(line1); temp3.crossLocal(temp2); // V1 . V2 >= 0 return temp1.dot(temp3) >= 0; }
/** * Updates the local coordinate system from the localForward and localUp * vectors, adapts localForward, sets localForwardRotation quaternion to * local Z-forward rotation. */ protected void updateLocalCoordinateSystem() { //gravity vector has possibly changed, calculate new world forward (UNIT_Z) calculateNewForward(localForwardRotation, localForward, localUp); localLeft.set(localUp).crossLocal(localForward); rigidBody.setPhysicsRotation(localForwardRotation); updateLocalViewDirection(); }
public static Vector3f computeTriangleNormal(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f store) { if (store == null) { store = new Vector3f(v2); } else { store.set(v2); } store.subtractLocal(v1).crossLocal(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z); return store.normalizeLocal(); }
/** * calculateNormal generates the normal for this triangle * */ public void calculateNormal() { if (normal == null) { normal = new Vector3f(pointb); } else { normal.set(pointb); } normal.subtractLocal(pointa).crossLocal(pointc.x - pointa.x, pointc.y - pointa.y, pointc.z - pointa.z); normal.normalizeLocal(); }
/** * Initialize the Plane using the given 3 points as coplanar. * * @param v1 * the first point * @param v2 * the second point * @param v3 * the third point */ public void setPlanePoints(Vector3f v1, Vector3f v2, Vector3f v3) { normal.set(v2).subtractLocal(v1); normal.crossLocal(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z) .normalizeLocal(); constant = normal.dot(v1); }
public void onAnalog(String name, float value, float tpf) { //computing the normalized direction of the cam to move the teaNode direction.set(cam.getDirection()).normalizeLocal(); if (name.equals("moveForward")) { direction.multLocal(5 * tpf); teaNode.move(direction); } if (name.equals("moveBackward")) { direction.multLocal(-5 * tpf); teaNode.move(direction); } if (name.equals("moveRight")) { direction.crossLocal(Vector3f.UNIT_Y).multLocal(5 * tpf); teaNode.move(direction); } if (name.equals("moveLeft")) { direction.crossLocal(Vector3f.UNIT_Y).multLocal(-5 * tpf); teaNode.move(direction); } if (name.equals("rotateRight") && rotate) { teaNode.rotate(0, 5 * tpf, 0); } if (name.equals("rotateLeft") && rotate) { teaNode.rotate(0, -5 * tpf, 0); } }
private Vector3f calculateNormal(Vector3f firstPoint, Vector3f rootPoint, Vector3f secondPoint) { Vector3f normal = new Vector3f(); normal.set(firstPoint).subtractLocal(rootPoint) .crossLocal(secondPoint.subtract(rootPoint)).normalizeLocal(); return normal; }
/** * <code>lookAt</code> is a convienence method for auto-setting the * quaternion based on a direction and an up vector. It computes * the rotation to transform the z-axis to point into 'direction' * and the y-axis to 'up'. * * @param direction * where to look at in terms of local coordinates * @param up * a vector indicating the local up direction. * (typically {0, 1, 0} in jME.) */ public void lookAt(Vector3f direction, Vector3f up) { TempVars vars = TempVars.get(); vars.vect3.set(direction).normalizeLocal(); vars.vect1.set(up).crossLocal(direction).normalizeLocal(); vars.vect2.set(direction).crossLocal(vars.vect1).normalizeLocal(); fromAxes(vars.vect1, vars.vect2, vars.vect3); vars.release(); }
public void fromFrame(Vector3f location, Vector3f direction, Vector3f up, Vector3f left) { TempVars vars = TempVars.get(); try { Vector3f fwdVector = vars.vect1.set(direction); Vector3f leftVector = vars.vect2.set(fwdVector).crossLocal(up); Vector3f upVector = vars.vect3.set(leftVector).crossLocal(fwdVector); m00 = leftVector.x; m01 = leftVector.y; m02 = leftVector.z; m03 = -leftVector.dot(location); m10 = upVector.x; m11 = upVector.y; m12 = upVector.z; m13 = -upVector.dot(location); m20 = -fwdVector.x; m21 = -fwdVector.y; m22 = -fwdVector.z; m23 = fwdVector.dot(location); m30 = 0f; m31 = 0f; m32 = 0f; m33 = 1f; } finally { vars.release(); } }
public static Vector3f importanceSampleGGX(Vector4f xi, float a2, Vector3f normal, Vector3f store, TempVars vars) { if (store == null) { store = new Vector3f(); } float cosTheta = sqrt((1f - xi.x) / (1f + (a2 - 1f) * xi.x)); float sinTheta = sqrt(1f - cosTheta * cosTheta); float sinThetaCosPhi = sinTheta * xi.z;//xi.z is cos(phi) float sinThetaSinPhi = sinTheta * xi.w;//xi.w is sin(phi) Vector3f upVector = Vector3f.UNIT_X; if (abs(normal.z) < 0.999) { upVector = Vector3f.UNIT_Y; } Vector3f tangentX = vars.vect3.set(upVector).crossLocal(normal).normalizeLocal(); Vector3f tangentY = vars.vect4.set(normal).crossLocal(tangentX); // Tangent to world space tangentX.multLocal(sinThetaCosPhi); tangentY.multLocal(sinThetaSinPhi); vars.vect5.set(normal).multLocal(cosTheta); // Tangent to world space store.set(tangentX).addLocal(tangentY).addLocal(vars.vect5); return store; }
Vector3f newLeftNegate = vars.vect2; newLeft.set(worldUpVector).crossLocal(direction).normalizeLocal(); if (newLeft.equals(Vector3f.ZERO)) { if (direction.x != 0) { direction.set(worldUpVector).crossLocal(newLeftNegate).normalizeLocal(); if (direction.equals(Vector3f.ZERO)) { direction.set(Vector3f.UNIT_Z);
Vector3f newLeftNegate = vars.vect2; newLeft.set(worldUpVector).crossLocal(direction).normalizeLocal(); if (newLeft.equals(Vector3f.ZERO)) { if (direction.x != 0) { direction.set(worldUpVector).crossLocal(newLeftNegate).normalizeLocal(); if (direction.equals(Vector3f.ZERO)) { direction.set(Vector3f.UNIT_Z);
Vector3f perpDirection = vars.vect2.set(direction).crossLocal(plane.getNormal()).normalizeLocal().crossLocal(direction);
/** * <code>rotateUpTo</code> is a utility function that alters the * local rotation to point the Y axis in the direction given by newUp. * * @param newUp * the up vector to use - assumed to be a unit vector. */ public void rotateUpTo(Vector3f newUp) { TempVars vars = TempVars.get(); Vector3f compVecA = vars.vect1; Quaternion q = vars.quat1; // First figure out the current up vector. Vector3f upY = compVecA.set(Vector3f.UNIT_Y); Quaternion rot = localTransform.getRotation(); rot.multLocal(upY); // get angle between vectors float angle = upY.angleBetween(newUp); // figure out rotation axis by taking cross product Vector3f rotAxis = upY.crossLocal(newUp).normalizeLocal(); // Build a rotation quat and apply current local rotation. q.fromAngleNormalAxis(angle, rotAxis); q.mult(rot, rot); vars.release(); setTransformRefresh(); }
newLeft.set(newUp).crossLocal(newDirection).normalizeLocal(); if (newLeft.equals(Vector3f.ZERO)) { if (newDirection.x != 0) { newUp.set(newDirection).crossLocal(newLeft).normalizeLocal();
@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); } }