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;
- 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>();
- List<Vertex> segments = new List<Vertex>();
- float twoPi = 2 * pi;
- float angleStep = twoPi / (16 * (1 + (radius / 16f)));
- int iterator = 0;
- int firstIndex = 0;
- 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));
- if (iterator != 0 && iterator % 2 == 0)
- {
- segments.Add(new Vertex(vertices[iterator]));
- segments.Add(new Vertex(vertices[iterator - 1]));
- }
- if (angle >= twoPi - angleStep) // Wrap around and eat that tail like a good chompy boi Jörmungandr.
- {
- segments.Add(new Vertex(vertices[firstIndex]));
- segments.Add(new Vertex(vertices[iterator]));
- }
- iterator++;
- }
- firstIndex = vertices.Count;
- 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));
- if (iterator != 0 && iterator % 2 == 0)
- {
- segments.Add(new Vertex(vertices[iterator]));
- segments.Add(new Vertex(vertices[iterator - 1]));
- }
- if (angle >= twoPi - angleStep) // Wrap around and eat that tail like a good chompy boi Jörmungandr.
- {
- segments.Add(new Vertex(vertices[firstIndex]));
- segments.Add(new Vertex(vertices[iterator]));
- }
- iterator++;
- }
- firstIndex = vertices.Count;
- 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));
- if (iterator != 0 && iterator % 2 == 0)
- {
- segments.Add(new Vertex(vertices[iterator]));
- segments.Add(new Vertex(vertices[iterator - 1]));
- }
- if (angle >= twoPi - angleStep) // Wrap around and eat that tail like a good chompy boi Jörmungandr.
- {
- segments.Add(new Vertex(vertices[firstIndex]));
- segments.Add(new Vertex(vertices[iterator]));
- }
- iterator++;
- }
- vertices.AddRange(segments);
- ModelMesh mesh = new ModelMesh(device, vertices.ToArray());
- return mesh;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement