/** * 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 ); }
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; }
/** * 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; }
v01.sub(vertices[0], vertices[1]); v21.sub(vertices[2], vertices[1]); normal.cross(v21, v01); normal.normalize(); UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format);
v01.sub(vertices[0], vertices[1]); v21.sub(vertices[2], vertices[1]); normal.cross(v21, v01); normal.normalize(); UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format);
cross.cross(yunit, v);