Пример #1
0
        /// <summary>
        /// Create a transform centered at origin with its Z axis pointing
        /// along up.
        /// </summary>
        /// <param name="origin">The origin of the transform.</param>
        /// <param name="z">The vector which will define the Z axis of the transform.</param>
        /// <param name="rotation">An optional rotation around the z axis.</param>
        public Transform(Vector3 origin, Vector3 z, double rotation = 0.0)
        {
            Vector3 x = Vector3.XAxis;
            Vector3 y = Vector3.YAxis;

            if (!z.IsParallelTo(Vector3.ZAxis))
            {
                // Project up onto the ortho plane
                var p    = new Plane(origin, z);
                var test = Vector3.ZAxis.Project(p);
                x = test.Cross(z).Unitized();
                y = x.Cross(z.Negate()).Unitized();
            }
            else
            {
                // Ensure that we have a right-handed coordinate system.
                if (z.Dot(Vector3.ZAxis).ApproximatelyEquals(-1))
                {
                    y = Vector3.YAxis.Negate();
                }
            }

            this.Matrix = new Matrix(x, y, z, Vector3.Origin);
            ApplyRotationAndTranslation(rotation, z, origin);
        }
Пример #2
0
        /// <summary>
        /// Create a transform centered at origin with its Z axis pointing
        /// along up.
        /// </summary>
        /// <param name="origin">The origin of the transform.</param>
        /// <param name="z">The vector which will define the Z axis of the transform.</param>
        /// <param name="rotation">An optional rotation around the z axis.</param>
        public Transform(Vector3 origin, Vector3 z, double rotation = 0.0)
        {
            Vector3 x = Vector3.XAxis;
            Vector3 y = Vector3.YAxis;

            if (!z.IsParallelTo(Vector3.ZAxis))
            {
                // Project up onto the ortho plane
                var p    = new Plane(origin, z);
                var test = Vector3.ZAxis.Project(p);
                x = test.Cross(z).Unitized();
                y = x.Cross(z.Negate()).Unitized();
            }

            this.Matrix = new Matrix(x, y, z, Vector3.Origin);
            ApplyRotationAndTranslation(rotation, z, origin);
        }