public static warp_Object ROTATIONOBJECT(warp_Vector[] path, int sides) { int steps = sides + 1; warp_Object newObject = new warp_Object(); double alpha = 2 * pi / ((double)steps - 1); float qx, qz; int nodes = path.GetLength(0); warp_Vertex vertex = null; float u, v; // Texture coordinates for (int j = 0; j < steps; j++) { u = (float)(steps - j - 1) / (float)(steps - 1); for (int i = 0; i < nodes; i++) { v = (float)i / (float)(nodes - 1); qx = (float)(path[i].x * Math.Cos(j * alpha) + path[i].z * Math.Sin(j * alpha)); qz = (float)(path[i].z * Math.Cos(j * alpha) - path[i].x * Math.Sin(j * alpha)); vertex = new warp_Vertex(qx, path[i].y, qz); vertex.u = u; vertex.v = v; newObject.addVertex(vertex); } } for (int j = 0; j < steps - 1; j++) { for (int i = 0; i < nodes - 1; i++) { newObject.addTriangle(i + nodes * j, i + nodes * (j + 1), i + 1 + nodes * j); newObject.addTriangle(i + nodes * (j + 1), i + 1 + nodes * (j + 1), i + 1 + nodes * j); } } for (int i = 0; i < nodes - 1; i++) { newObject.addTriangle(i + nodes * (steps - 1), i, i + 1 + nodes * (steps - 1)); newObject.addTriangle(i, i + 1, i + 1 + nodes * (steps - 1)); } return(newObject); }
public static warp_Object SIMPLEPLANE(float size, bool doubleSided) { warp_Object newObject = new warp_Object(); newObject.addVertex(new warp_Vertex(-size, 0f, size, 0, 0)); newObject.addVertex(new warp_Vertex(size, 0f, size, 1f, 0)); newObject.addVertex(new warp_Vertex(size, 0f, -size, 1f, 1f)); newObject.addVertex(new warp_Vertex(-size, 0f, -size, 0, 1f)); newObject.addTriangle(0, 3, 2); newObject.addTriangle(0, 2, 1); if (doubleSided) { newObject.addTriangle(0, 2, 3); newObject.addTriangle(0, 1, 2); } return(newObject); }
private void readPointList(BinaryReader inStream) { int v1, v2, v3; int triangles = readShort(inStream); for (int i = 0; i < triangles; i++) { v1 = readShort(inStream); v2 = readShort(inStream); v3 = readShort(inStream); readShort(inStream); currentObject.addTriangle(currentObject.vertex(v1), currentObject.vertex(v2), currentObject.vertex(v3)); } }
public warp_Object getClone() { warp_Object obj = new warp_Object(); rebuild(); for (int i = 0; i < vertices; i++) { obj.addVertex(fastvertex[i].getClone()); } for (int i = 0; i < triangles; i++) { obj.addTriangle(fasttriangle[i].getClone()); } obj.name = name + " [cloned]"; obj.material = material; obj.matrix = matrix.getClone(); obj.normalmatrix = normalmatrix.getClone(); obj.rebuild(); return(obj); }
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); }