Example #1
0
        /// <summary>
        /// Returns a copy of the Vector3k scaled to unit length.
        /// </summary>
        public Vector3k Normalized()
        {
            Vector3k v = this;

            v.Normalize();
            return(v);
        }
Example #2
0
        public static Vector3k CalculateSurfaceNormal(Vertex [] verts)
        {
            Vector3k normal = new Vector3k(Accum.Zero, Accum.Zero, Accum.Zero);
            Vertex   cur, next;
            int      vCount = verts.Length;

            for (int i = 0; i < vCount; i++)
            {
                cur  = verts [i];
                next = verts [(i + 1) % vCount];

                normal.X += (cur.Y - next.Y) * (cur.Z + next.Z);
                normal.Y += (cur.Z - next.Z) * (cur.X + next.X);
                normal.Z += (cur.X - next.X) * (cur.Y + next.Y);
            }

            normal.Normalize();

            return(normal);
        }