void rebuildMatrices() { if (!needsRebuild) { return; } needsRebuild = false; warp_Vector forward, up, right; forward = warp_Vector.sub(lookat, pos); if (Math.Abs(forward.x) < 0.001f && Math.Abs(forward.z) < 0.001f) { right = new warp_Vector(1f, 0f, 0f); if (forward.y < 0) { up = new warp_Vector(0f, 0f, 1f); } else { up = new warp_Vector(0f, 0f, -1f); } } else { up = new warp_Vector(0f, 1f, 0f); right = warp_Vector.getNormal(up, forward); up = warp_Vector.getNormal(forward, right); } forward.normalize(); normalmatrix = new warp_Matrix(right, up, forward); if (rollfactor != 0) { normalmatrix.rotate(0, 0, rollfactor); } matrix = normalmatrix.getClone(); matrix.shift(pos.x, pos.y, pos.z); matrix = matrix.inverse(); normalmatrix = normalmatrix.inverse(); if (isOrthographic) { projmatrix.m00 = screenwidth / orthoViewWidth; projmatrix.m03 = halfscreenwidth; projmatrix.m11 = -screenheight / orthoViewHeight; projmatrix.m13 = halfscreenheight; projmatrix.m22 = 1.0f; } else { float screenscale = (screenwidth < screenheight) ? screenwidth : screenheight; projmatrix.m00 = screenscale / fovfact; projmatrix.m03 = 0; projmatrix.m11 = -screenscale / fovfact; projmatrix.m13 = 0; projmatrix.m22 = 1.0f; } matrix = warp_Matrix.multiply(projmatrix, matrix); }
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); }
public void shift(float dx, float dy, float dz) { matrix.shift(dx, dy, dz); }