void rebuildMatrices() { if (!needsRebuild) { return; } needsRebuild = false; warp_Vector forward, up, right; forward = warp_Vector.sub(lookat, pos); up = new warp_Vector(0f, 1f, 0f); right = warp_Vector.getNormal(up, forward); up = warp_Vector.getNormal(forward, right); forward.normalize(); up.normalize(); right.normalize(); normalmatrix = new warp_Matrix(right, up, forward); normalmatrix.rotate(0, 0, rollfactor); matrix = normalmatrix.getClone(); matrix.shift(pos.x, pos.y, pos.z); normalmatrix = normalmatrix.inverse(); matrix = matrix.inverse(); }
public static warp_Object TUBE(warp_Vector[] path, float r, int steps, bool closed) { warp_Vector[] circle = new warp_Vector[steps]; float angle; for (int i = 0; i < steps; i++) { angle = 2 * 3.14159265f * (float)i / (float)steps; circle [i] = new warp_Vector(r * warp_Math.cos(angle), r * warp_Math.sin(angle), 0f); } warp_Object newObject = new warp_Object(); int segments = path.GetLength(0); warp_Vector forward, up, right; warp_Matrix frenetmatrix; warp_Vertex tempvertex; float relx, rely; int a, b, c, d; for (int i = 0; i < segments; i++) { // Calculate frenet frame matrix if (i != segments - 1) { forward = warp_Vector.sub(path [i + 1], path [i]); } else { if (!closed) { forward = warp_Vector.sub(path [i], path [i - 1]); } else { forward = warp_Vector.sub(path [1], path [0]); } } forward.normalize(); up = new warp_Vector(0f, 0f, 1f); right = warp_Vector.getNormal(forward, up); up = warp_Vector.getNormal(forward, right); frenetmatrix = new warp_Matrix(right, up, forward); frenetmatrix.shift(path [i].x, path [i].y, path [i].z); // Add nodes relx = (float)i / (float)(segments - 1); for (int k = 0; k < steps; k++) { rely = (float)k / (float)steps; tempvertex = new warp_Vertex(circle [k].transform(frenetmatrix)); tempvertex.u = relx; tempvertex.v = rely; newObject.addVertex(tempvertex); } } for (int i = 0; i < segments - 1; i++) { for (int k = 0; k < steps - 1; k++) { a = i * steps + k; b = a + 1; c = a + steps; d = b + steps; newObject.addTriangle(a, c, b); newObject.addTriangle(b, c, d); } a = (i + 1) * steps - 1; b = a + 1 - steps; c = a + steps; d = b + steps; newObject.addTriangle(a, c, b); newObject.addTriangle(b, c, d); } return(newObject); }
void rebuildMatrices () { if (!needsRebuild) return; needsRebuild = false; warp_Vector forward, up, right; forward = warp_Vector.sub (lookat, pos); up = new warp_Vector (0f, 1f, 0f); right = warp_Vector.getNormal (up, forward); up = warp_Vector.getNormal (forward, right); forward.normalize (); up.normalize (); right.normalize (); normalmatrix = new warp_Matrix (right, up, forward); normalmatrix.rotate (0, 0, rollfactor); matrix = normalmatrix.getClone (); matrix.shift (pos.x, pos.y, pos.z); normalmatrix = normalmatrix.inverse (); matrix = matrix.inverse (); }
public static warp_Object TUBE (warp_Vector[] path, float r, int steps, bool closed) { warp_Vector[] circle = new warp_Vector[steps]; float angle; for (int i = 0; i < steps; i++) { angle = 2 * 3.14159265f * (float)i / (float)steps; circle [i] = new warp_Vector (r * warp_Math.cos (angle), r * warp_Math.sin (angle), 0f); } warp_Object newObject = new warp_Object (); int segments = path.GetLength (0); warp_Vector forward, up, right; warp_Matrix frenetmatrix; warp_Vertex tempvertex; float relx, rely; int a, b, c, d; for (int i = 0; i < segments; i++) { // Calculate frenet frame matrix if (i != segments - 1) { forward = warp_Vector.sub (path [i + 1], path [i]); } else { if (!closed) { forward = warp_Vector.sub (path [i], path [i - 1]); } else { forward = warp_Vector.sub (path [1], path [0]); } } forward.normalize (); up = new warp_Vector (0f, 0f, 1f); right = warp_Vector.getNormal (forward, up); up = warp_Vector.getNormal (forward, right); frenetmatrix = new warp_Matrix (right, up, forward); frenetmatrix.shift (path [i].x, path [i].y, path [i].z); // Add nodes relx = (float)i / (float)(segments - 1); for (int k = 0; k < steps; k++) { rely = (float)k / (float)steps; tempvertex = new warp_Vertex (circle [k].transform (frenetmatrix)); tempvertex.u = relx; tempvertex.v = rely; newObject.addVertex (tempvertex); } } for (int i = 0; i < segments - 1; i++) { for (int k = 0; k < steps - 1; k++) { a = i * steps + k; b = a + 1; c = a + steps; d = b + steps; newObject.addTriangle (a, c, b); newObject.addTriangle (b, c, d); } a = (i + 1) * steps - 1; b = a + 1 - steps; c = a + steps; d = b + steps; newObject.addTriangle (a, c, b); newObject.addTriangle (b, c, d); } return newObject; }