77 using SiliconStudio.Core.Mathematics;
79 namespace SiliconStudio.
Paradox.Graphics
99 return new GeometricPrimitive(device, New(height, radius, tessellation, toLeftHanded));
110 public static GeometricMeshData<VertexPositionNormalTexture>
New(
float height = 1.0f,
float radius = 0.5f,
int tessellation = 16,
bool toLeftHanded =
false)
112 if (tessellation < 3)
throw new ArgumentOutOfRangeException(
"tessellation",
"Must be >= 3");
114 int verticalSegments = tessellation;
115 int horizontalSegments = tessellation * 2;
118 var indices =
new int[(verticalSegments) * (horizontalSegments + 1) * 6];
120 var middle = verticalSegments / 2;
124 for (
int i = 0; i <= verticalSegments; i++)
126 float v = 1.0f - (float)i / verticalSegments;
128 var latitude = (float)((i * Math.PI / verticalSegments) - Math.PI / 2.0);
129 var dy = (float)Math.Sin(latitude);
130 var dxz = (float)Math.Cos(latitude);
132 var deltaY = latitude <= 0.0f ? -height : height;
136 for (
int j = 0; j <= horizontalSegments; j++)
138 float u = (float)j / horizontalSegments;
140 var longitude = (float)(j * 2.0 * Math.PI / horizontalSegments);
141 var dx = (float)Math.Sin(longitude);
142 var dz = (float)Math.Cos(longitude);
147 var normal =
new Vector3(dx, dy, dz);
148 var textureCoordinate =
new Vector2(u, v);
155 int stride = horizontalSegments + 1;
158 for (
int i = 0; i < verticalSegments; i++)
160 for (
int j = 0; j <= horizontalSegments; j++)
163 int nextJ = (j + 1) % stride;
165 indices[indexCount++] = (i * stride + j);
166 indices[indexCount++] = (nextI * stride + j);
167 indices[indexCount++] = (i * stride + nextJ);
169 indices[indexCount++] = (i * stride + nextJ);
170 indices[indexCount++] = (nextI * stride + j);
171 indices[indexCount++] = (nextI * stride + nextJ);
177 return new GeometricMeshData<VertexPositionNormalTexture>(vertices, indices, toLeftHanded) { Name =
"Capsule" };
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
static GeometricMeshData< VertexPositionNormalTexture > New(float height=1.0f, float radius=0.5f, int tessellation=16, bool toLeftHanded=false)
Creates a sphere primitive.
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...
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 height=1.0f, float radius=0.5f, int tessellation=16, bool toLeftHanded=false)
Creates a sphere primitive.
SiliconStudio.Core.Mathematics.Vector3 Vector3