77 using System.Collections.Generic;
78 using SiliconStudio.Core;
79 using SiliconStudio.Core.Mathematics;
81 namespace SiliconStudio.
Paradox.Graphics
83 public partial class GeometricPrimitive
91 private static Vector3 GetCircleVector(
int i,
int tessellation)
93 var angle = (float) (i*2.0*Math.PI/tessellation);
94 var dx = (float) Math.Sin(angle);
95 var dz = (float) Math.Cos(angle);
101 private static void CreateCylinderCap(List<VertexPositionNormalTexture> vertices, List<int> indices,
int tessellation,
float height,
float radius,
float textureTiling,
bool isTop)
104 for (
int i = 0; i < tessellation - 2; i++)
106 int i1 = (i + 1)%tessellation;
107 int i2 = (i + 2)%tessellation;
111 Utilities.Swap(ref i1, ref i2);
114 int vbase = vertices.Count;
116 indices.Add(vbase + i1);
117 indices.Add(vbase + i2);
121 var normal = Vector3.UnitY;
122 var textureScale =
new Vector2(-0.5f);
127 textureScale.X = -textureScale.X;
131 for (
int i = 0; i < tessellation; i++)
133 var circleVector = GetCircleVector(i, tessellation);
134 var position = (circleVector*radius) + (normal*height);
135 var textureCoordinate =
new Vector2(textureTiling * (circleVector.X * textureScale.X + 0.5f), textureTiling * (circleVector.Z * textureScale.Y + 0.5f));
155 return new GeometricPrimitive(device, New(height, diameter, tessellation, textureTiling, toLeftHanded));
168 public static GeometricMeshData<VertexPositionNormalTexture>
New(
float height = 1.0f,
float diameter = 1.0f,
int tessellation = 32,
float textureTiling = 1,
bool toLeftHanded =
false)
170 if (tessellation < 3)
171 throw new ArgumentOutOfRangeException(
"tessellation",
"tessellation must be >= 3");
173 var vertices =
new List<VertexPositionNormalTexture>();
174 var indices =
new List<int>();
178 var topOffset = Vector3.UnitY*height;
180 float radius = diameter/2;
181 int stride = tessellation + 1;
184 for (
int i = 0; i <= tessellation; i++)
186 var normal = GetCircleVector(i, tessellation);
188 var sideOffset = normal*radius;
190 var textureCoordinate =
new Vector2(textureTiling * (
float) i/tessellation, 0);
196 indices.Add((i*2 + 2)%(stride*2));
197 indices.Add(i*2 + 1);
199 indices.Add(i*2 + 1);
200 indices.Add((i*2 + 2)%(stride*2));
201 indices.Add((i*2 + 3)%(stride*2));
205 CreateCylinderCap(vertices, indices, tessellation, height, radius, textureTiling,
true);
206 CreateCylinderCap(vertices, indices, tessellation, height, radius, textureTiling,
false);
209 return new GeometricMeshData<VertexPositionNormalTexture>(vertices.ToArray(), indices.ToArray(), toLeftHanded) {Name =
"Cylinder"};
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Represents a two dimensional mathematical vector.
static GeometricMeshData< VertexPositionNormalTexture > New(float height=1.0f, float diameter=1.0f, int tessellation=32, float textureTiling=1, bool toLeftHanded=false)
Creates a cylinder primitive.
static readonly Vector2 UnitY
The Y unit SiliconStudio.Core.Mathematics.Vector2 (0, 1).
A geometric primitive. Use Cube, Cylinder, GeoSphere, Plane, Sphere, Teapot, Torus. See Draw+vertices to learn how to use it.
Describes a custom vertex format structure that contains position, normal and texture information...
static GeometricPrimitive New(GraphicsDevice device, float height=1.0f, float diameter=1.0f, int tessellation=32, float textureTiling=1, bool toLeftHanded=false)
Creates a cylinder primitive.
Represents a three dimensional mathematical vector.
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
SiliconStudio.Core.Mathematics.Vector3 Vector3