77 using System.Collections.Generic;
78 using SiliconStudio.Core.Mathematics;
80 namespace SiliconStudio.
Paradox.Graphics
82 public partial class GeometricPrimitive
101 return new GeometricPrimitive(device, New(diameter, thickness, tessellation, toLeftHanded));
113 public static GeometricMeshData<VertexPositionNormalTexture>
New(
float diameter = 1.0f,
float thickness = 0.33333f,
int tessellation = 32,
bool toLeftHanded =
false)
115 var vertices =
new List<VertexPositionNormalTexture>();
116 var indices =
new List<int>();
118 if (tessellation < 3)
119 throw new ArgumentOutOfRangeException(
"tessellation",
"tessellation parameter out of range");
121 int stride = tessellation + 1;
124 for (
int i = 0; i <= tessellation; i++)
126 float u = (float) i/tessellation;
128 float outerAngle = i*MathUtil.TwoPi/tessellation - MathUtil.PiOverTwo;
132 var transform = Matrix.Translation(diameter/2, 0, 0)*
Matrix.
RotationY(outerAngle);
135 for (
int j = 0; j <= tessellation; j++)
137 float v = 1 - (float) j/tessellation;
139 float innerAngle = j*MathUtil.TwoPi/tessellation + MathUtil.Pi;
140 float dx = (float) Math.Cos(innerAngle), dy = (float) Math.Sin(innerAngle);
143 var normal =
new Vector3(dx, dy, 0);
144 var position = normal*thickness/2;
145 var textureCoordinate =
new Vector2(u, v);
147 Vector3.TransformCoordinate(ref position, ref transform, out position);
148 Vector3.TransformNormal(ref normal, ref transform, out normal);
153 int nextI = (i + 1)%stride;
154 int nextJ = (j + 1)%stride;
156 indices.Add(i*stride + j);
157 indices.Add(i*stride + nextJ);
158 indices.Add(nextI*stride + j);
160 indices.Add(i*stride + nextJ);
161 indices.Add(nextI*stride + nextJ);
162 indices.Add(nextI*stride + j);
167 return new GeometricMeshData<VertexPositionNormalTexture>(vertices.ToArray(), indices.ToArray(), toLeftHanded) { Name =
"Torus" };
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
A geometric primitive. Use Cube, Cylinder, GeoSphere, Plane, Sphere, Teapot, Torus. See Draw+vertices to learn how to use it.
static GeometricMeshData< VertexPositionNormalTexture > New(float diameter=1.0f, float thickness=0.33333f, int tessellation=32, bool toLeftHanded=false)
Creates a torus primitive.
Describes a custom vertex format structure that contains position, normal and texture information...
static void RotationY(float angle, out Matrix result)
Creates a matrix that rotates around the y-axis.
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.
static GeometricPrimitive New(GraphicsDevice device, float diameter=1.0f, float thickness=0.33333f, int tessellation=32, bool toLeftHanded=false)
Creates a torus primitive.
SiliconStudio.Core.Mathematics.Vector3 Vector3
Represents a 4x4 mathematical matrix.