Пример #1
0
 public static void ToVector4(ref Color4 color, out Vector4 vector)
 {
     vector.X = color.R / 255f;
     vector.Y = color.G / 255f;
     vector.Z = color.B / 255f;
     vector.W = color.A / 255f;
 }
Пример #2
0
 public TriangleColorComponent(Vector4 color1, Vector4 color2, Vector4 color3)
 {
     Colors = new Vector4[3] {color1, color2, color3};
 }
        public VertexProcessor(SoftwareVertex vertex, Vector4[] colors, Vector3[] normals, Vector2[] uvs, HardwareMeshProcessor mesh)
        {
            Positions = new Vector3[mesh.positions.Count];
            for (int i = 0; i != Positions.Length; ++i)
            {
                Positions[i] = mesh.positions[i][vertex.Index];
            }

            Colors = colors;
            Normals = normals;
            UVs = uvs;

            mesh.Verticies.AddLast(this);
        }
        public TriangleProcessor(SoftwareTriangle triangle, HardwareMeshProcessor mesh, bool loadColors, bool loadUVs, bool loadNormals)
        {
            // get color components
            var colors = new Vector4[3][];
            if (loadColors)
            {
                int componentCount = mesh.colorComponents.Count;
                for (int i = 0; i != colors.Length; ++i)
                {
                    colors[i] = new Vector4[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var colorComponent = mesh.colorComponents[i][triangle.Index].Colors;
                    colors[0][i] = colorComponent[0];
                    colors[1][i] = colorComponent[1];
                    colors[2][i] = colorComponent[2];
                }
            }

            // get normal components
            var normals = new Vector3[3][];
            if (loadNormals)
            {
                int componentCount = mesh.normalComponents.Count;
                for (int i = 0; i != normals.Length; ++i)
                {
                    normals[i] = new Vector3[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var normalComponent = mesh.normalComponents[i][triangle.Index].Normals;
                    normals[0][i] = normalComponent[0];
                    normals[1][i] = normalComponent[1];
                    normals[2][i] = normalComponent[2];
                }
            }

            // get uv components
            var uvs = new Vector2[3][];
            if (loadUVs)
            {
                int componentCount = mesh.uvComponents.Count;
                for (int i = 0; i != uvs.Length; ++i)
                {
                    uvs[i] = new Vector2[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var normalComponent = mesh.uvComponents[i][triangle.Index].UVs;
                    uvs[0][i] = normalComponent[0];
                    uvs[1][i] = normalComponent[1];
                    uvs[2][i] = normalComponent[2];
                }
            }

            // add verticies
            var vertex1 = new VertexProcessor(triangle.Verticies[0], colors[0], normals[0], uvs[0], mesh);
            var vertex2 = new VertexProcessor(triangle.Verticies[1], colors[1], normals[1], uvs[1], mesh);
            var vertex3 = new VertexProcessor(triangle.Verticies[2], colors[2], normals[2], uvs[2], mesh);
            Verticies = new VertexProcessor[3] {vertex1, vertex2, vertex3};

            mesh.Triangles.Add(this);
        }
Пример #5
0
 public Vector3 UnProjectNormalized(Vector2 screenPosition)
 {
     var pos = new Vector4(screenPosition, 0, 1);
     var near = pos.UnProject(TransformInverseMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height);
     pos.Z = 1;
     var far = pos.UnProject(TransformInverseMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height);
     return (far - near).ToVector3().Normalize();
 }
Пример #6
0
 public Vector4 UnProject(Vector4 screenPosition)
 {
     return screenPosition.UnProject(TransformInverseMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height);
 }
Пример #7
0
 public Vector4 UnProject(Vector2 screenPosition)
 {
     var pos = new Vector4(screenPosition, 0, 1);
     return pos.UnProject(TransformInverseMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height);
 }
Пример #8
0
 public Vector4 Project(Vector4 position)
 {
     return position.Project(ProjectionMatrix, ViewMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height);
 }
Пример #9
0
 public Vector2 Project(Vector3 position)
 {
     var pos = new Vector4(position, 1);
     return pos.Project(ProjectionMatrix, ViewMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height).ToVector2();
 }