secondTraceOffset.normalize(); secondTraceOffset.scale(checkingOffset); fromWorld.add(secondTraceOffset);
Vector3f lookAheadOffset = new Vector3f(direction.x, direction.y, direction.z); lookAheadOffset.y = 0; lookAheadOffset.normalize(); lookAheadOffset.scale(checkForwardDistance); Vector3f fromWorld = new Vector3f(hitPointWorld);
/** * 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 DropItemAction(@Nonnull ItemStack stack, double x, double y, double z, float vx, float vy, float vz) { this.stack = stack; this.x = x; this.y = y; this.z = z; this.v = new Vector3f(vx, vy, vz); final Vector3f nv = new Vector3f(); nv.normalize(this.v); this.pitch = -(float)Math.toDegrees(Math.asin(nv.y)); this.yaw = -(float)Math.toDegrees(Math.atan2(nv.x, nv.z)); }
public void mouseClicked(final MouseEvent _evt) { if (SwingUtilities.isLeftMouseButton(_evt)) { final Vector3f old = new Vector3f(vecteur_); final int x = _evt.getX(); final int y = _evt.getY(); switch (((Carre) _evt.getSource()).getMode()) { case 0: vecteur_.x = x - centreX_; vecteur_.z = y - centreY_; break; case 1: vecteur_.y = x - centreX_; vecteur_.z = y - centreY_; break; case 2: vecteur_.z = x - centreX_; vecteur_.x = y - centreY_; break; default: // TODO ajouter des instructions au cas "default" } repaint(); if (!old.equals(vecteur_)) { final Vector3f v = new Vector3f(-vecteur_.x, vecteur_.y, vecteur_.z); v.normalize(); pcs_.firePropertyChange("direction", old, v); } } }
private static void test(FaceClassifier classifier, EnumFacing result, float x, float y, float z) { Vector3f v = new Vector3f(x, y, z); v.normalize(); Assert.assertEquals(Optional.of(result), classifier.classify(v)); }
private static void test(FaceClassifier classifier, float x, float y, float z) { Vector3f v = new Vector3f(x, y, z); v.normalize(); Assert.assertEquals(Optional.empty(), classifier.classify(v)); }
private Vector3f calculateTriangleNormal( Point3f p1, Point3f p2, Point3f p3 ) { Vector3f first = new Vector3f(); first.sub( p3, p1 ); Vector3f second = new Vector3f(); second.sub( p3, p2 ); Vector3f normal = new Vector3f(); normal.cross( first, second ); normal.normalize(); return normal; }
/** * Get a matrix usable for zero calibration (only position and compass direction) */ public float[] getCalibrationMatrix() { float[] t = new float[3]; float[] m = new float[16]; mFrame.getCamera().getPose().getTranslation(t, 0); float[] z = mFrame.getCamera().getPose().getZAxis(); Vector3f zAxis = new Vector3f(z[0], z[1], z[2]); zAxis.y = 0; zAxis.normalize(); double rotate = Math.atan2(zAxis.x, zAxis.z); Matrix.setIdentityM(m, 0); Matrix.translateM(m, 0, t[0], t[1], t[2]); Matrix.rotateM(m, 0, (float) Math.toDegrees(rotate), 0, 1, 0); return m; }
/** * Computes the normal of this triangle. This method only computes the * normal if the normal is not up to date. The normal is defined as outdated * whenever a new node has been assigned. */ private void computeNormal() { if (!normalUpToDate) { Point3f p1 = nodeOne.getLocation(); Point3f p2 = nodeTwo.getLocation(); Point3f p3 = nodeThree.getLocation(); Vector3f v1 = new Vector3f( p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); Vector3f v2 = new Vector3f(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z); normal = new Vector3f(); normal.cross(v1, v2); normal.normalize(); normalUpToDate = true; } }
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; }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if(usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data[0], data[1], data[2], 1f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if(usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if (usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data[0], data[1], data[2], 1f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if (usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if (usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data); vec.setW(1.0f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if (usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
/** * @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); }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if (usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data); vec.setW(1.0f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if (usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
public Point3f getNearestIntersection(Point3f origin, Vector3f direction) direction.normalize(); float dx, dy, dz, dot; double distanceToLine, distance;
direction.normalize(); float dx, dy, dz, dot; double distanceToLine, distance;
v21.sub(vertices[2], vertices[1]); normal.cross(v21, v01); normal.normalize(); UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format); EnumFacing quadFacing = EnumFacing.getFacingFromVector(normal.x, normal.y, normal.z);
v21.sub(vertices[2], vertices[1]); normal.cross(v21, v01); normal.normalize(); UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format); EnumFacing quadFacing = EnumFacing.getFacingFromVector(normal.x, normal.y, normal.z);