Advertisement
Krythic

Dirty fix

Aug 3rd, 2020
2,622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using SharpDX;
  2. using SharpDX.Direct3D11;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.CompilerServices;
  6.  
  7. namespace VoidwalkerEngine.Framework.DirectX.Rendering
  8. {
  9.     public static class Wireframe
  10.     {
  11.         public static ModelMesh GenerateWireframeSphere(Device device, Vector3 location, float radius)
  12.         {
  13.             float pi = (float)Math.PI;
  14.             List<Vertex> vertices = new List<Vertex>();
  15.             float twoPi = 2 * pi;
  16.             float angleStep = (twoPi / 16f);
  17.             for (float angle = 0f; angle <= twoPi; angle += angleStep)
  18.             {
  19.                 float x = radius * (float)Math.Sin(angle);
  20.                 float y = radius * (float)Math.Cos(angle);
  21.                 float z = 0;
  22.                 vertices.Add(new Vertex(location.X + x, location.Y + y, location.Z + z));
  23.             }
  24.             // A Dirty, nasty, ugly, horrific fix.
  25.             List<Vertex> additions = new List<Vertex>();
  26.             for(int i = 0; i < vertices.Count; i += 2)
  27.             {
  28.                 if(i + 2 < vertices.Count)
  29.                 {
  30.                     Vertex vertex1 = vertices[i + 1];
  31.                     Vertex vertex2 = vertices[i + 2];
  32.                     additions.Add(vertex1);
  33.                     additions.Add(vertex2);
  34.                 }
  35.                 else
  36.                 {
  37.                     additions.Add(vertices[vertices.Count - 1]);
  38.                     additions.Add(vertices[0]);
  39.                 }
  40.                
  41.             }
  42.             vertices.AddRange(additions);
  43.             for (float angle = 0f; angle <= twoPi; angle += angleStep)
  44.             {
  45.                 float x = radius * (float)Math.Sin(angle);
  46.                 float y = 0;
  47.                 float z = radius * (float)Math.Cos(angle);
  48.                 vertices.Add(new Vertex(location.X + x, location.Y + y, location.Z + z));
  49.             }
  50.             for (float angle = 0f; angle <= twoPi; angle += angleStep)
  51.             {
  52.                 float x = 0;
  53.                 float y = radius * (float)Math.Sin(angle);
  54.                 float z = radius * (float)Math.Cos(angle);
  55.                 vertices.Add(new Vertex(location.X + x, location.Y + y, location.Z + z));
  56.             }
  57.             ModelMesh mesh = new ModelMesh(device, vertices.ToArray());
  58.             return mesh;
  59.         }
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement