Ejemplo n.º 1
0
        /// <summary>
        /// <para>Rotates all vertices in the mesh, from the origin, by the given rotation vector in degrees.</para>
        /// <para>This is useful for rotating an object before placing it in a ShapeGroup.</para>
        /// For camera rotation, use RotateCamera(rotationVector).
        /// </summary>
        public void RotateVerticesAboutOrigin(Vector3 rotationVectorDegrees)
        {
            foreach (var face in Faces)
            {
                for (var i = 0; i < face.VerticeCount; i++)
                {
                    face.Composition[i].Position =
                        Vector3.Transform(
                            face.Composition[i].Position,
                            Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (float)rotationVectorDegrees.X.ToRadians()));

                    face.Composition[i].Position =
                        Vector3.Transform(
                            face.Composition[i].Position,
                            Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)rotationVectorDegrees.Y.ToRadians()));

                    face.Composition[i].Position =
                        Vector3.Transform(
                            face.Composition[i].Position,
                            Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (float)rotationVectorDegrees.Z.ToRadians()));
                    if ((i + 1) % 3 == 0 && i != face.VerticeCount - 1)
                    {
                        var newNormal = ShapeHelpers.GetNormal(
                            face.Composition[i].Position,
                            face.Composition[i + 1].Position,
                            face.Composition[i + 2].Position);

                        face.Composition[i].Normal     = newNormal;
                        face.Composition[i + 1].Normal = newNormal;
                        face.Composition[i + 2].Normal = newNormal;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public FaceTriangle(
            Vector3 top,
            Vector3 bottomLeft,
            Vector3 bottomRight)
        {
            VerticeCount = 3;
            PolygonCount = 1;
            Composition  = new VertexPositionNormalTexture[VerticeCount];

            var normal = ShapeHelpers.GetNormal(top, bottomLeft, bottomRight);

            Composition[0] = new VertexPositionNormalTexture(top, normal, new Vector2(0.5f, 0));
            Composition[1] = new VertexPositionNormalTexture(bottomLeft, normal, new Vector2(0, 1));
            Composition[2] = new VertexPositionNormalTexture(bottomRight, normal, new Vector2(1, 1));
        }
Ejemplo n.º 3
0
        public FaceSquare(
            Vector3 topLeft,
            Vector3 topRight,
            Vector3 bottomLeft,
            Vector3 bottomRight)
        {
            VerticeCount = 6;
            PolygonCount = 2;
            Composition  = new VertexPositionNormalTexture[VerticeCount];

            var normal = ShapeHelpers.GetNormal(topLeft, topRight, bottomLeft);

            // Squares are made of two triangles. This makes it easier to process
            Composition[0] = new VertexPositionNormalTexture(topLeft, normal, new Vector2(0, 0));
            Composition[1] = new VertexPositionNormalTexture(topRight, normal, new Vector2(1, 0));
            Composition[2] = new VertexPositionNormalTexture(bottomLeft, normal, new Vector2(0, 1));

            normal = ShapeHelpers.GetNormal(bottomLeft, topRight, bottomRight);

            Composition[3] = new VertexPositionNormalTexture(bottomLeft, normal, new Vector2(0, 1));
            Composition[4] = new VertexPositionNormalTexture(topRight, normal, new Vector2(1, 0));
            Composition[5] = new VertexPositionNormalTexture(bottomRight, normal, new Vector2(1, 1));
        }