4 using System.Collections.Generic;
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
9 namespace SiliconStudio.
Paradox.Graphics
11 public partial class GeometricMultiTexcoordPrimitive
19 private static Vector3 GetCircleVector(
int i,
int tessellation)
21 var angle = (float)(i * 2.0 * Math.PI / tessellation);
22 var dx = (float)Math.Sin(angle);
23 var dz = (float)Math.Cos(angle);
29 private static void CreateCylinderCap(List<VertexPositionNormalTangentMultiTexture> vertices, List<int> indices,
int tessellation,
float height,
float radius,
bool isTop)
32 for (
int i = 0; i < tessellation - 2; i++)
34 int i1 = (i + 1) % tessellation;
35 int i2 = (i + 2) % tessellation;
39 Utilities.Swap(ref i1, ref i2);
42 int vbase = vertices.Count;
44 indices.Add(vbase + i1);
45 indices.Add(vbase + i2);
49 var normal = Vector3.UnitY;
50 var textureScale =
new Vector2(-0.5f);
55 textureScale.X = -textureScale.X;
59 for (
int i = 0; i < tessellation; i++)
61 var circleVector = GetCircleVector(i, tessellation);
62 var position = (circleVector * radius) + (normal * height);
63 var textureCoordinate =
new Vector2(circleVector.X * textureScale.X + 0.5f, circleVector.Z * textureScale.Y + 0.5f);
94 public static GeometricMeshData<VertexPositionNormalTangentMultiTexture>
New(
float height = 1.0f,
float diameter = 1.0f,
int tessellation = 32,
bool toLeftHanded =
false)
97 throw new ArgumentOutOfRangeException(
"tessellation",
@"tessellation must be >= 3");
99 var vertices =
new List<VertexPositionNormalTangentMultiTexture>();
100 var indices =
new List<int>();
104 var topOffset = Vector3.UnitY * height;
106 float radius = diameter / 2;
107 int stride = tessellation + 1;
110 for (
int i = 0; i <= tessellation; i++)
112 var normal = GetCircleVector(i, tessellation);
114 var sideOffset = normal * radius;
116 var textureCoordinate =
new Vector2((
float)i / tessellation, 0);
118 var tangent =
new Vector4(normal.Z, 0, -normal.X, 0);
123 indices.Add((i * 2 + 2) % (stride * 2));
124 indices.Add(i * 2 + 1);
126 indices.Add(i * 2 + 1);
127 indices.Add((i * 2 + 2) % (stride * 2));
128 indices.Add((i * 2 + 3) % (stride * 2));
132 CreateCylinderCap(vertices, indices, tessellation, height, radius,
true);
133 CreateCylinderCap(vertices, indices, tessellation, height, radius,
false);
136 return new GeometricMeshData<VertexPositionNormalTangentMultiTexture>(vertices.ToArray(), indices.ToArray(), toLeftHanded) { Name =
"Cylinder" };
static GeometricMultiTexcoordPrimitive New(GraphicsDevice device, float height=1.0f, float diameter=1.0f, int tessellation=32, bool toLeftHanded=false)
Creates a cylinder primitive.
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Represents a two dimensional mathematical vector.
static readonly Vector2 UnitY
The Y unit SiliconStudio.Core.Mathematics.Vector2 (0, 1).
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...
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.
Represents a four dimensional mathematical vector.
SiliconStudio.Core.Mathematics.Vector3 Vector3
static GeometricMeshData< VertexPositionNormalTangentMultiTexture > New(float height=1.0f, float diameter=1.0f, int tessellation=32, bool toLeftHanded=false)
Creates a cylinder primitive.