예제 #1
0
 private static void Rotate(VertexDataPosNormalUV[] vertices, Rotor3 q)
 {
     for (var i = 0; i < vertices.Length; i++)
     {
         var v = vertices[i];
         v.Normal    = Rotor3.Rotate(q, v.Normal);
         v.Position  = Rotor3.Rotate(q, v.Position);
         vertices[i] = v;
     }
 }
예제 #2
0
        public static VertexDataPosNormalUV[] GetCube(Vector3 size, Vector3 translate)
        {
            var lines = new List <Vector3>();

            lines.Add(Vector3.UnitX);
            lines.Add(Vector3.UnitY);
            lines.Add(Vector3.UnitZ);

            var directions = new List <Vector3>();

            foreach (var line in lines)
            {
                directions.Add(line);
                directions.Add(-line);
            }

            var vertices = new List <VertexDataPosNormalUV>();

            foreach (var direction in directions)
            {
                var quad = VertexDataPosNormalUV.DefaultQuad.ToPolygonVertices();

                Translate(quad, new Vector3(0, 0, 0.5f));

                Rotate(quad, new Rotor3(Vector3.UnitZ, -Vector3.UnitY));

                Rotor3 r;
                if (direction == -Vector3.UnitY)
                {
                    r = Rotor3.Identity;
                }
                else if (direction == Vector3.UnitY)
                {
                    r = new Rotor3(0, 1, 0, 0);
                }
                else
                {
                    r = new Rotor3(-Vector3.UnitY, direction);
                }

                Rotate(quad, r);
                Scale(quad, size);
                if (translate != Vector3.Zero)
                {
                    Translate(quad, translate);
                }

                RoundSmooth(quad);

                vertices.AddRange(quad);
                //break;
            }

            return(vertices.ToArray());
        }