4 using System.Collections.Generic;
6 using SiliconStudio.Core.Mathematics;
8 namespace SiliconStudio.
Paradox.Graphics
10 public partial class GeometricMultiTexcoordPrimitive
41 public static GeometricMeshData<VertexPositionNormalTangentMultiTexture>
New(
float diameter = 1.0f,
float thickness = 0.33333f,
int tessellation = 32,
bool toLeftHanded =
false)
43 var vertices =
new List<VertexPositionNormalTangentMultiTexture>();
44 var indices =
new List<int>();
47 throw new ArgumentOutOfRangeException(
"tessellation");
49 int stride = tessellation + 1;
52 for (
int i = 0; i <= tessellation; i++)
54 float u = (float)i / tessellation;
56 float outerAngle = i * MathUtil.TwoPi / tessellation - MathUtil.PiOverTwo;
60 var transform = Matrix.Translation(diameter / 2, 0, 0) *
Matrix.
RotationY(outerAngle);
63 for (
int j = 0; j <= tessellation; j++)
65 float v = 1 - (float)j / tessellation;
67 float innerAngle = j * MathUtil.TwoPi / tessellation + MathUtil.Pi;
68 float dx = (float)Math.Cos(innerAngle), dy = (float)Math.Sin(innerAngle);
71 var normal =
new Vector3(dx, dy, 0);
72 var position = normal * thickness / 2;
73 var textureCoordinate =
new Vector2(u, v);
75 Vector3.TransformCoordinate(ref position, ref transform, out position);
76 Vector3.TransformNormal(ref normal, ref transform, out normal);
78 var tangent =
new Vector4((
float)Math.Sin(outerAngle), 0, -(float)Math.Cos(outerAngle), 0);
82 int nextI = (i + 1) % stride;
83 int nextJ = (j + 1) % stride;
85 indices.Add(i * stride + j);
86 indices.Add(i * stride + nextJ);
87 indices.Add(nextI * stride + j);
89 indices.Add(i * stride + nextJ);
90 indices.Add(nextI * stride + nextJ);
91 indices.Add(nextI * stride + j);
96 return new GeometricMeshData<VertexPositionNormalTangentMultiTexture>(vertices.ToArray(), indices.ToArray(), toLeftHanded) { Name =
"Torus" };
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
A geometric primitive. Use Sphere to learn how to use it.
Describes a custom vertex format structure that contains position, color and 10 texture coordinates i...
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.
Represents a four dimensional mathematical vector.
static GeometricMeshData< VertexPositionNormalTangentMultiTexture > New(float diameter=1.0f, float thickness=0.33333f, int tessellation=32, bool toLeftHanded=false)
Creates a torus primitive.
SiliconStudio.Core.Mathematics.Vector3 Vector3
static GeometricMultiTexcoordPrimitive New(GraphicsDevice device, float diameter=1.0f, float thickness=0.33333f, int tessellation=32, bool toLeftHanded=false)
Creates a torus primitive.
Represents a 4x4 mathematical matrix.