AngleFromXY() public static method

public static AngleFromXY ( float x, float y ) : float
x float
y float
return float
Beispiel #1
0
        public static MeshData CreateGeosphere(float radius, SubdivisionCount numSubdivisions)
        {
            var tempMesh = new MeshData {
                Vertices = IcosahedronVertices.Select(p => new Vertex {
                    Position = p
                }).ToList(),
                Indices = IcosahedronIndices
            };

            var mh = new Subdivider();

            for (var i = 0; i < (int)numSubdivisions; i++)
            {
                mh.Subdivide4(tempMesh);
            }

            // Project vertices onto sphere and scale.
            for (var i = 0; i < tempMesh.Vertices.Count; i++)
            {
                // Project onto unit sphere.
                var n = Vector3.Normalize(tempMesh.Vertices[i].Position);
                // Project onto sphere.
                var p = radius * n;

                // Derive texture coordinates from spherical coordinates.
                var theta = MathF.AngleFromXY(tempMesh.Vertices[i].Position.X, tempMesh.Vertices[i].Position.Z);
                var phi   = MathUtils.Acos(tempMesh.Vertices[i].Position.Y / radius);
                var texC  = new Vector2(theta / (2 * MathF.PI), phi / MathF.PI);

                // Partial derivative of P with respect to theta
                var tangent = new Vector3(
                    -radius * MathUtils.Sin(phi) * MathUtils.Sin(theta),
                    0,
                    radius * MathUtils.Sin(phi) * MathUtils.Cos(theta));
                tangent.Normalize();

                tempMesh.Vertices[i] = new Vertex(p, n, tangent, texC);
            }
            return(tempMesh);
        }
Beispiel #2
0
        public static MeshData CreateGeosphere(float radius, SubdivisionCount numSubdivisions)
        {
            var tempMesh = new MeshBuilder {
                VerticesBuffer = IcosahedronVertices.Select(p => new Vertex(p)).ToArray(),
                IndicesBuffer  = IcosahedronIndices
            };

            for (var i = 0; i < (int)numSubdivisions; i++)
            {
                Subdivide4(tempMesh);
            }

            // Project vertices onto sphere and scale.
            for (var i = 0; i < tempMesh.VerticesCount; i++)
            {
                // Project onto unit sphere.
                var n = Vector3.Normalize(tempMesh.VerticesBuffer[i].Position);

                // Project onto sphere.
                var p = radius * n;

                // Derive texture coordinates from spherical coordinates.
                var theta = MathF.AngleFromXY(tempMesh.VerticesBuffer[i].Position.X, tempMesh.VerticesBuffer[i].Position.Z);
                var phi   = (tempMesh.VerticesBuffer[i].Position.Y / radius).Acos();
                var texC  = new Vector2(theta / (2 * MathF.PI), phi / MathF.PI);

                // Partial derivative of P with respect to theta
                var tangent = new Vector3(
                    -radius * phi.Sin() * theta.Sin(),
                    0,
                    radius * phi.Sin() * theta.Cos());
                tangent.Normalize();

                tempMesh.VerticesBuffer[i] = new Vertex(p, n, texC, tangent);
            }

            return(tempMesh.Seal());
        }