public void setDimension(float dim){ this.dimension.set(dim, dim, dim); this.invDim.set(1,1,1).divideLocal(dimension); }
public void setDimension(float x, float y, float z){ this.dimension.set(x,y,z); this.invDim.set(1,1,1).divideLocal(dimension); }
public void setDimension(Vector3f dimension) { this.dimension.set(dimension); this.invDim.set(1,1,1).divideLocal(dimension); }
/** * @return the centroid of the face */ public Vector3f computeCentroid() { Vector3f result = new Vector3f(); List<Vector3f> vertices = temporalMesh.getVertices(); for (Integer index : indexes) { result.addLocal(vertices.get(index)); } return result.divideLocal(indexes.size()); }
/** * @return the centroid of the edge */ public Vector3f computeCentroid() { return this.getFirstVertex().add(this.getSecondVertex()).divideLocal(2); }
public Vector3f transformInverseVector(final Vector3f in, Vector3f store){ if (store == null) store = new Vector3f(); // The author of this code should look above and take the inverse of that // But for some reason, they didn't .. // in.subtract(translation, store).divideLocal(scale); // rot.inverse().mult(store, store); in.subtract(translation, store); rot.inverse().mult(store, store); store.divideLocal(scale); return store; }
/** * The method computes the face's normal vector. * @param face * the face of the mesh * @return face's normal vector */ private Vector3f computeFaceNormal(Face face) { Vector3f result = new Vector3f(); for (Integer index : face.getIndexes()) { result.addLocal(face.getTemporalMesh().getNormals().get(index)); } result.divideLocal(face.getIndexes().size()); return result; }
/** * Converts the given position from world space to screen space. * * @see Camera#getScreenCoordinates(Vector3f, Vector3f) */ public Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store) { if (store == null) { store = new Vector3f(); } // TempVars vars = vars.lock(); // Quaternion tmp_quat = vars.quat1; // tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 ); // viewProjectionMatrix.mult(tmp_quat, tmp_quat); // tmp_quat.multLocal( 1.0f / tmp_quat.getW() ); // store.x = ( ( tmp_quat.getX() + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth(); // store.y = ( ( tmp_quat.getY() + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight(); // store.z = ( tmp_quat.getZ() + 1 ) / 2; // vars.release(); float w = viewProjectionMatrix.multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (viewPortRight - viewPortLeft) / 2f + viewPortLeft) * getWidth(); store.y = ((store.y + 1f) * (viewPortTop - viewPortBottom) / 2f + viewPortBottom) * getHeight(); store.z = (store.z + 1f) / 2f; return store; }
private Vector3f getClipCoordinates(Vector3f worldPosition, Vector3f store, Camera cam) { float w = cam.getViewProjectionMatrix().multProj(worldPosition, store); store.divideLocal(w); store.x = ((store.x + 1f) * (cam.getViewPortRight() - cam.getViewPortLeft()) / 2f + cam.getViewPortLeft()); store.y = ((store.y + 1f) * (cam.getViewPortTop() - cam.getViewPortBottom()) / 2f + cam.getViewPortBottom()); store.z = (store.z + 1f) / 2f; return store; }
/** * Saves the current bone state as its binding pose, including its children. */ void setBindingPose() { bindPos.set(localPos); bindRot.set(localRot); bindScale.set(localScale); if (modelBindInversePos == null) { modelBindInversePos = new Vector3f(); modelBindInverseRot = new Quaternion(); modelBindInverseScale = new Vector3f(); } // Save inverse derived position/scale/orientation, used for calculate offset transform later modelBindInversePos.set(modelPos); modelBindInversePos.negateLocal(); modelBindInverseRot.set(modelRot); modelBindInverseRot.inverseLocal(); modelBindInverseScale.set(Vector3f.UNIT_XYZ); modelBindInverseScale.divideLocal(modelScale); for (Bone b : children) { b.setBindingPose(); } }
private Vector3f getClosestPoint(TempVars vars, Vector3f point) { // non normalized direction Vector3f dir = vars.vect2.set(point).subtractLocal(transform.getTranslation()); // initialize the closest point with box center Vector3f closestPoint = vars.vect3.set(transform.getTranslation()); //store extent in an array float[] r = vars.fWdU; r[0] = transform.getScale().x; r[1] = transform.getScale().y; r[2] = transform.getScale().z; // computing closest point to sphere center for (int i = 0; i < 3; i++) { // extract the axis from the 3x3 matrix Vector3f axis = getScaledAxis(i, vars.vect1); // nomalize (here we just divide by the extent axis.divideLocal(r[i]); // distance to the closest point on this axis. float d = FastMath.clamp(dir.dot(axis), -r[i], r[i]); closestPoint.addLocal(vars.vect4.set(axis).multLocal(d)); } return closestPoint; }
/** * Calculates the minimum bounding sphere of 3 points. Used in welzl's * algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(Vector3f O, Vector3f A, Vector3f B) { Vector3f a = A.subtract(O); Vector3f b = B.subtract(O); Vector3f acrossB = a.cross(b); float Denominator = 2.0f * acrossB.dot(acrossB); if (Denominator == 0) { center.set(0, 0, 0); radius = 0; } else { Vector3f o = acrossB.cross(a).multLocal(b.lengthSquared()).addLocal(b.cross(acrossB).multLocal(a.lengthSquared())).divideLocal(Denominator); radius = o.length() * RADIUS_EPSILON; O.add(o, center); } }
public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); } else { box = (BoundingBox) store; } TempVars vars = TempVars.get(); float w = trans.multProj(center, box.center); box.center.divideLocal(w); Matrix3f transMatrix = vars.tempMat3; trans.toRotationMatrix(transMatrix); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); vars.vect1.set(xExtent, yExtent, zExtent); transMatrix.mult(vars.vect1, vars.vect1); // Assign the biggest rotations after scales. box.xExtent = FastMath.abs(vars.vect1.getX()); box.yExtent = FastMath.abs(vars.vect1.getY()); box.zExtent = FastMath.abs(vars.vect1.getZ()); vars.release(); return box; }
public void update(float tpf) { if (enabled && spatial != null) { Quaternion localRotationQuat = spatial.getLocalRotation(); Vector3f localLocation = spatial.getLocalTranslation(); if (!applyLocal && spatial.getParent() != null) { getPhysicsLocation(localLocation); localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); spatial.setLocalTranslation(localLocation); if (useViewDirection) { localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } else { spatial.setLocalTranslation(getPhysicsLocation()); localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } }
public void update(float tpf) { if (enabled && spatial != null) { Quaternion localRotationQuat = spatial.getLocalRotation(); Vector3f localLocation = spatial.getLocalTranslation(); if (!applyLocal && spatial.getParent() != null) { getPhysicsLocation(localLocation); localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); spatial.setLocalTranslation(localLocation); if (useViewDirection) { localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } else { spatial.setLocalTranslation(getPhysicsLocation()); localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } }
/** * applies the current transform to the given jme Node if the location has been updated on the physics side * @param spatial */ public boolean applyTransform(Spatial spatial) { if (!physicsLocationDirty) { return false; } if (!applyPhysicsLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotationQuat); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotationQuat); } physicsLocationDirty = false; return true; }
public void applyWheelTransform() { if (wheelSpatial == null) { return; } Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); Vector3f localLocation = wheelSpatial.getLocalTranslation(); if (!applyLocal && wheelSpatial.getParent() != null) { localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(wheelWorldRotation); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); wheelSpatial.setLocalTranslation(localLocation); wheelSpatial.setLocalRotation(localRotationQuat); } else { wheelSpatial.setLocalTranslation(wheelWorldLocation); wheelSpatial.setLocalRotation(wheelWorldRotation); } }
/** * Apply this wheel's physics location and orientation to its associated * spatial, if any. */ public void applyWheelTransform() { if (wheelSpatial == null) { return; } Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); Vector3f localLocation = wheelSpatial.getLocalTranslation(); if (!applyLocal && wheelSpatial.getParent() != null) { localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(wheelWorldRotation); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); wheelSpatial.setLocalTranslation(localLocation); wheelSpatial.setLocalRotation(localRotationQuat); } else { wheelSpatial.setLocalTranslation(wheelWorldLocation); wheelSpatial.setLocalRotation(wheelWorldRotation); } }
/** * Apply a physics transform to the spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) { if (enabled && spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (!applyLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } }
/** * Apply the specified location and orientation to the specified spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) * @param spatial where to apply (may be null) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) { if (spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } } }