@Override public void awakenArea(org.terasology.math.geom.Vector3f pos, float radius) { Vector3f min = new Vector3f(VecMath.to(pos)); min.sub(new Vector3f(0.6f, 0.6f, 0.6f)); Vector3f max = new Vector3f(VecMath.to(pos)); max.add(new Vector3f(0.6f, 0.6f, 0.6f)); discreteDynamicsWorld.awakenRigidBodiesInArea(min, max); }
/** * Re-calculates the Orientation of this quad, * optionally the normal vector. * * @param setNormal If the normal vector should be updated. */ public void calculateOrientation( boolean setNormal ) { this.v1.set( this.vertices[3].vec ); this.t.set( this.vertices[1].vec ); this.v1.sub( this.t ); this.v2.set( this.vertices[2].vec ); this.t.set( this.vertices[0].vec ); this.v2.sub( this.t ); this.normal.cross( this.v2, this.v1 ); this.normal.normalize(); if( this.format.hasNormal && setNormal) { for( Vertex vertex : this.vertices ) { vertex.normal[0] = this.normal.x; vertex.normal[1] = this.normal.y; vertex.normal[2] = this.normal.z; vertex.normal[3] = 0; } } this.orientation = EnumFacing.getFacingFromVector( this.normal.x, this.normal.y, this.normal.z ); }
public void decrementDisp(double x, double y, double z) { disp.sub(new Vector3f((float)x, (float)y, (float)z)); // disp.set(1, disp.get(1) - y); } }
/** * @param newPoint * @param lastPoint * @return */ public static boolean distanceCheck(Vector3f newPoint, Vector3f lastPoint) { Vector3f temp = new Vector3f(); temp.sub(newPoint, lastPoint); if (temp.length() > AppSettings.getMinDistance()) { return true; } return false; } }
public static void assertTuple3fEquals(String message, Tuple3f expected, Tuple3f actual, float delta) { boolean areEqual = expected.epsilonEquals(actual, delta); if (message.equals("")) { message = "Tuple3ds are not Equal!"; } if (!areEqual) { Vector3f difference = new Vector3f(actual); difference.sub(expected); fail(message + " Expected = " + expected + ", actual = " + actual + ". norm of difference = " + difference.length()); } }
private static Vector3f[] findNormalsPerFace(int[] indices, Point3f[] vertices) { Vector3f[] normalsPerFace = new Vector3f[indices.length / 3]; // Abuse integer division. Vector3f firstVector = new Vector3f(); Vector3f secondVector = new Vector3f(); Point3f[] faceVertices = new Point3f[3]; for (int face = 0; face < normalsPerFace.length; face++) { normalsPerFace[face] = new Vector3f(); for (int i = 0; i < faceVertices.length; i++) { faceVertices[i] = vertices[indices[face * 3 + i]]; } firstVector.set(faceVertices[2]); firstVector.sub(faceVertices[0]); secondVector.set(faceVertices[2]); secondVector.sub(faceVertices[1]); normalsPerFace[face].cross(firstVector, secondVector); normalsPerFace[face].normalize(); } return normalsPerFace; }
distance.sub(new Vector3f(mLastFramePosition[0], mLastFramePosition[1], mLastFramePosition[2]));
/** * @param point * @param viewportSize * @param viewProjMtx * @return */ public static Ray screenPointToRay(Vector2f point, Vector2f viewportSize, float[] viewProjMtx) { point.y = viewportSize.y - point.y; float x = point.x * 2.0F / viewportSize.x - 1.0F; float y = point.y * 2.0F / viewportSize.y - 1.0F; float[] farScreenPoint = new float[]{x, y, 1.0F, 1.0F}; float[] nearScreenPoint = new float[]{x, y, -1.0F, 1.0F}; float[] nearPlanePoint = new float[4]; float[] farPlanePoint = new float[4]; float[] invertedProjectionMatrix = new float[16]; Matrix.setIdentityM(invertedProjectionMatrix, 0); Matrix.invertM(invertedProjectionMatrix, 0, viewProjMtx, 0); Matrix.multiplyMV(nearPlanePoint, 0, invertedProjectionMatrix, 0, nearScreenPoint, 0); Matrix.multiplyMV(farPlanePoint, 0, invertedProjectionMatrix, 0, farScreenPoint, 0); Vector3f direction = new Vector3f(farPlanePoint[0] / farPlanePoint[3], farPlanePoint[1] / farPlanePoint[3], farPlanePoint[2] / farPlanePoint[3]); Vector3f origin = new Vector3f(new Vector3f(nearPlanePoint[0] / nearPlanePoint[3], nearPlanePoint[1] / nearPlanePoint[3], nearPlanePoint[2] / nearPlanePoint[3])); direction.sub(origin); direction.normalize(); return new Ray(origin, direction); }