private void drawSpherePrimitives() { TangentVertex[] vertices; short[] sIndices; SphereMesh.CreateUnitSphereVerticesAndIndices(20, out vertices, out sIndices); int[] indices = new int[sIndices.Length]; for (int i = 0; i < sIndices.Length; i++) { indices[i] = sIndices[i]; } GraphicsDevice.VertexDeclaration = tangentVertexDeclaration; GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, sIndices, 0, sIndices.Length / 3); }
public void TestSphereMesh() { XNAGame game = new XNAGame(); List <SphereMesh> meshes = new List <SphereMesh>(); TangentVertex[] vertices; short[] indices; SphereMesh.CreateUnitSphereVerticesAndIndices(4, out vertices, out indices); bool wireframe = false; game.InitializeEvent += delegate { SphereMesh mesh; mesh = new SphereMesh(1, 4, Color.Green); mesh.Initialize(game); meshes.Add(mesh); mesh = new SphereMesh(1, 5, Color.PowderBlue); mesh.WorldMatrix = Matrix.CreateTranslation(3, 0, 0); mesh.Initialize(game); meshes.Add(mesh); mesh = new SphereMesh(1, 12, Color.Yellow); mesh.WorldMatrix = Matrix.CreateTranslation(6, 0, 0); mesh.Initialize(game); meshes.Add(mesh); mesh = new SphereMesh(1, 30, Color.Turquoise); mesh.WorldMatrix = Matrix.CreateTranslation(9, 0, 0); mesh.Initialize(game); meshes.Add(mesh); mesh = new SphereMesh(40, 100, Color.Red); mesh.WorldMatrix = Matrix.CreateTranslation(0, 0, -60); mesh.Initialize(game); meshes.Add(mesh); mesh = new SphereMesh(40, 13, Color.Red); mesh.WorldMatrix = Matrix.CreateTranslation(100, 0, -60); mesh.Initialize(game); meshes.Add(mesh); }; game.UpdateEvent += delegate { if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.W)) { wireframe = !wireframe; } }; game.DrawEvent += delegate { game.LineManager3D.AddAABB(meshes[1].BoundingBox, Matrix.Identity, Color.Red); int i; if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.R)) { for (i = 0; i < meshes.Count; i++) { meshes[i].ReloadShader(game); } } game.GraphicsDevice.RenderState.FillMode = FillMode.Solid; game.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; if (!wireframe) { for (i = 1; i < meshes.Count; i++) { meshes[i].Render(game); } } i = 0; meshes[i].Color = Color.LightGreen; meshes[i].Render(game); game.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; meshes[i].Color = Color.Red; meshes[i].Render(game); game.GraphicsDevice.RenderState.FillMode = FillMode.WireFrame; game.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; meshes[i].Color = Color.Black; meshes[i].Render(game); if (wireframe) { for (i = 1; i < meshes.Count; i++) { meshes[i].Render(game); } } for (i = 0; i < vertices.Length; i++) { game.LineManager3D.AddCenteredBox(vertices[i].pos, 0.05f, Color.Red); } }; game.Run(); }