Exemple #1
0
        private static Vector2 GenerateSphericalCoordiantesfor(Vector3 position, UVMappingTypes mapping)
        {
            Vector2 tex;
            double  u = 0.0;
            double  v = 0.0;
            double  x = position.X;
            double  y = position.Y;
            double  z = position.Z;
            double  r
                = Math.Sqrt(Math.Pow(x, 2.0) + Math.Pow(y, 2.0) + Math.Pow(z, 2.0));

            x /= r;
            y /= r;
            z /= r;


            switch (mapping)
            {
            case UVMappingTypes.Spherical_Coordinates:
                u = z >= 0 ? Math.Atan2(position.X, position.Z) : Math.Atan2(position.X, -position.Z);
                v = Math.Acos(position.Y / r);
                break;

            case UVMappingTypes.Central:
                u = x;
                v = y;
                break;

            case UVMappingTypes.Stereographic:
                u = z >= 0 ? x / (1 + z) : x / (1 - z);
                v = z >= 0 ? y / (1 + z) : y / (1 - z);
                break;
            }

            //TODO: Log to file
            #if DEBUG
            //if(u < 0.0 || u >1.0 || v < 0.0 || v > 1.0)
            //Console.Error.WriteLine($"Texturecoordinates Out of Range - u:{u}, v:{v}");
            #endif

            tex.X = u.ToFloat();
            tex.Y = v.ToFloat();

            return(tex);
        }
Exemple #2
0
        public static void GenerateSphericalTextureCoordinatesFor(Mesh <VertexPositionNormalTextureTangent> mesh, UVMappingTypes mapping)
        {
            var vertices = mesh.Vertices;

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i].TextureCoordinates = GenerateSphericalCoordiantesfor(vertices[i].Position, mapping);
            }
        }