Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
		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 (new warp_Vector (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;

		}