77 using SiliconStudio.Core.Mathematics;
79 namespace SiliconStudio.
Paradox.Graphics
81 public partial class GeometricPrimitive
110 public static GeometricMeshData<VertexPositionNormalTexture>
New(
float diameter = 1.0f,
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 float radius = diameter / 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);
133 for (
int j = 0; j <= horizontalSegments; j++)
135 float u = (float)j / horizontalSegments;
137 var longitude = (float)(j * 2.0 * Math.PI / horizontalSegments);
138 var dx = (float)Math.Sin(longitude);
139 var dz = (float)Math.Cos(longitude);
144 var normal =
new Vector3(dx, dy, dz);
145 var textureCoordinate =
new Vector2(u, v);
152 int stride = horizontalSegments + 1;
155 for (
int i = 0; i < verticalSegments; i++)
157 for (
int j = 0; j <= horizontalSegments; j++)
160 int nextJ = (j + 1) % stride;
162 indices[indexCount++] = (i * stride + j);
163 indices[indexCount++] = (nextI * stride + j);
164 indices[indexCount++] = (i * stride + nextJ);
166 indices[indexCount++] = (i * stride + nextJ);
167 indices[indexCount++] = (nextI * stride + j);
168 indices[indexCount++] = (nextI * stride + nextJ);
173 return new GeometricMeshData<VertexPositionNormalTexture>(vertices, indices, toLeftHanded) {Name =
"Sphere"};
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
static GeometricMeshData< VertexPositionNormalTexture > New(float diameter=1.0f, 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 diameter=1.0f, int tessellation=16, bool toLeftHanded=false)
Creates a sphere primitive.
SiliconStudio.Core.Mathematics.Vector3 Vector3