5 using SiliconStudio.Core.Mathematics;
7 namespace SiliconStudio.
Paradox.Graphics
9 public partial class GeometricMultiTexcoordPrimitive
39 public static GeometricMeshData<VertexPositionNormalTangentMultiTexture>
New(
float diameter = 1.0f,
int tessellation = 16,
bool toLeftHanded =
false)
41 if (tessellation < 3)
throw new ArgumentOutOfRangeException(
"tessellation",
"Must be >= 3");
43 int verticalSegments = tessellation;
44 int horizontalSegments = tessellation * 2;
47 var indices =
new int[(verticalSegments) * (horizontalSegments + 1) * 6];
49 float radius = diameter / 2;
53 for (
int i = 0; i <= verticalSegments; i++)
55 float v = 1.0f - (float)i / verticalSegments;
57 var latitude = (float)((i * Math.PI / verticalSegments) - Math.PI / 2.0);
58 var dy = (float)Math.Sin(latitude);
59 var dxz = (float)Math.Cos(latitude);
62 for (
int j = 0; j <= horizontalSegments; j++)
64 float u = (float)j / horizontalSegments;
66 var longitude = (float)(j * 2.0 * Math.PI / horizontalSegments);
67 var dx = (float)Math.Sin(longitude);
68 var dz = (float)Math.Cos(longitude);
73 var normal =
new Vector3(dx, dy, dz);
74 var textureCoordinate =
new Vector2(u, v);
76 var tangent =
new Vector4(normal.Z, 0, -normal.X, 0);
82 int stride = horizontalSegments + 1;
85 for (
int i = 0; i < verticalSegments; i++)
87 for (
int j = 0; j <= horizontalSegments; j++)
90 int nextJ = (j + 1) % stride;
92 indices[indexCount++] = (i * stride + j);
93 indices[indexCount++] = (nextI * stride + j);
94 indices[indexCount++] = (i * stride + nextJ);
96 indices[indexCount++] = (i * stride + nextJ);
97 indices[indexCount++] = (nextI * stride + j);
98 indices[indexCount++] = (nextI * stride + nextJ);
104 return new GeometricMeshData<VertexPositionNormalTangentMultiTexture>(vertices, indices, toLeftHanded) { Name =
"Sphere" };
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
static GeometricMultiTexcoordPrimitive New(GraphicsDevice device, float diameter=1.0f, int tessellation=16, bool toLeftHanded=false)
Creates a sphere primitive.
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...
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, int tessellation=16, bool toLeftHanded=false)
Creates a sphere primitive.
SiliconStudio.Core.Mathematics.Vector3 Vector3