public static ShapeData CreateSphere(int slices, int stacks, float radius, Color color) { ShapeData shapeData = new ShapeData((slices + 1) * (stacks + 1), (slices * stacks * 6)); float phi = 0f; float theta = 0f; ; float deltaPhi = MathHelper.Pi / stacks; float dtheta = MathHelper.TwoPi / slices; float x, y, z, sc; short index = 0; for (int stack = 0; stack <= stacks; stack++) { phi = MathHelper.PiOver2 - (stack * deltaPhi); y = radius * (float)Math.Sin(phi); sc = -radius * (float)Math.Cos(phi); for (int slice = 0; slice <= slices; slice++) { theta = slice * dtheta; x = sc * (float)Math.Sin(theta); z = sc * (float)Math.Cos(theta); //s_sphereVertices[index++] = new VertexPositionNormalTexture(new IndexedVector3(x, y, z), // new IndexedVector3(x, y, z), // new Vector2((float)slice / (float)slices, (float)stack / (float)stacks)); shapeData.m_verticesArray[index++] = new VertexPositionColor(new Vector3(x, y, z), color); } } int stride = slices + 1; index = 0; for (int stack = 0; stack < stacks; stack++) { for (int slice = 0; slice < slices; slice++) { shapeData.m_indexList[index++] = (short)((stack + 0) * stride + slice); shapeData.m_indexList[index++] = (short)((stack + 1) * stride + slice); shapeData.m_indexList[index++] = (short)((stack + 0) * stride + slice + 1); shapeData.m_indexList[index++] = (short)((stack + 0) * stride + slice + 1); shapeData.m_indexList[index++] = (short)((stack + 1) * stride + slice); shapeData.m_indexList[index++] = (short)((stack + 1) * stride + slice + 1); } } return shapeData; }
public static ShapeData CreateBox(IndexedVector3 position, IndexedVector3 sideLength, Color color, ref IndexedMatrix transform) { ShapeData shapeData = new ShapeData(8, 36); int index = 0; shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(0, 0, 0))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(sideLength.X, 0, 0))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(sideLength.X, 0, sideLength.Z))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(0, 0, sideLength.Z))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(0, sideLength.Y, 0))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(sideLength.X, sideLength.Y, 0))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(sideLength.X, sideLength.Y, sideLength.Z))).ToVector3(), color); shapeData.m_verticesArray[index++] = new VertexPositionColor((transform * (position + new IndexedVector3(0, sideLength.Y, sideLength.Z))).ToVector3(), color); shapeData.m_indexArray = DrawHelper.s_cubeIndices; return shapeData; }