Exemplo n.º 1
0
        // Two CreateRotation functions below are adapted from the implementation of getRotation in
        // the VisualizationLibrary SDK (sources at http://visualizationlibrary.org/ )

        /// <summary>
        /// Creates a rotation matrix converting from a starting direction to a desired direction.
        /// </summary>
        /// <param name="fromDirection">Starting direction</param>
        /// <param name="toDirection">Desired direction</param>
        /// <returns>the matrix that applied to <see paramref="fromDirection"/> results in <see paramref="toDirection"/></returns>
        public static XbimMatrix3D CreateRotation(XbimPoint3D fromDirection, XbimPoint3D toDirection)
        {
            var a = new XbimVector3D(toDirection.X, toDirection.Y, toDirection.Z);
            var b = new XbimVector3D(fromDirection.X, fromDirection.Y, fromDirection.Z);

            a = a.Normalized();
            b = b.Normalized();

            double cosa = a.DotProduct(b);

            cosa = clamp(cosa, -1, +1);

            var    axis  = XbimVector3D.CrossProduct(a, b).Normalized();
            double alpha = Math.Acos(cosa);

            return(CreateRotation(alpha, axis));
        }
Exemplo n.º 2
0
        // Microsoft.Xna.Framework.Matrix
        public static XbimMatrix3D CreateLookAt(XbimVector3D cameraPosition, XbimVector3D cameraTarget, XbimVector3D cameraUpVector)
        {
            // prepare vectors
            XbimVector3D vector = cameraPosition - cameraTarget;

            vector.Normalized();
            XbimVector3D vector2 = XbimVector3D.CrossProduct(cameraUpVector, vector);

            vector2.Normalized();
            XbimVector3D vector3 = XbimVector3D.CrossProduct(vector, vector2);

            // prepare matrix
            XbimMatrix3D result = new XbimMatrix3D(
                vector2.X, vector3.X, vector.X, 0.0,
                vector2.Y, vector3.Y, vector.Y, 0.0,
                vector2.Z, vector3.Z, vector.Z, 0.0,
                -XbimVector3D.DotProduct(vector2, cameraPosition), -XbimVector3D.DotProduct(vector3, cameraPosition), -XbimVector3D.DotProduct(vector, cameraPosition), 1.0);

            return(result);
        }
Exemplo n.º 3
0
 public double DotProduct(XbimVector3D v2)
 {
     return(XbimVector3D.DotProduct(this, v2));
 }