Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SharpDX;
- using SharpDX.Direct3D11;
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- namespace VoidwalkerEngine.Framework.DirectX.Rendering
- {
- public static class Wireframe
- {
- public static ModelMesh GenerateWireframeSphere(Device device, Vector3 location, float radius)
- {
- float pi = (float)Math.PI;
- List<Vertex> vertices = new List<Vertex>();
- float twoPi = 2 * pi;
- float angleStep = (twoPi / 16f);
- for (float angle = 0f; angle <= twoPi; angle += angleStep)
- {
- float x = radius * (float)Math.Sin(angle);
- float y = radius * (float)Math.Cos(angle);
- float z = 0;
- vertices.Add(new Vertex(location.X + x, location.Y + y, location.Z + z));
- }
- // A Dirty, nasty, ugly, horrific fix.
- List<Vertex> additions = new List<Vertex>();
- for(int i = 0; i < vertices.Count; i += 2)
- {
- if(i + 2 < vertices.Count)
- {
- Vertex vertex1 = vertices[i + 1];
- Vertex vertex2 = vertices[i + 2];
- additions.Add(vertex1);
- additions.Add(vertex2);
- }
- else
- {
- additions.Add(vertices[vertices.Count - 1]);
- additions.Add(vertices[0]);
- }
- }
- vertices.AddRange(additions);
- for (float angle = 0f; angle <= twoPi; angle += angleStep)
- {
- float x = radius * (float)Math.Sin(angle);
- float y = 0;
- float z = radius * (float)Math.Cos(angle);
- vertices.Add(new Vertex(location.X + x, location.Y + y, location.Z + z));
- }
- for (float angle = 0f; angle <= twoPi; angle += angleStep)
- {
- float x = 0;
- float y = radius * (float)Math.Sin(angle);
- float z = radius * (float)Math.Cos(angle);
- vertices.Add(new Vertex(location.X + x, location.Y + y, location.Z + z));
- }
- ModelMesh mesh = new ModelMesh(device, vertices.ToArray());
- return mesh;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement