Ejemplo n.º 1
0
        /// <summary>
        /// Build a world space to camera space matrix
        /// </summary>
        /// <param name="eye">Eye (camera) position in world space</param>
        /// <param name="target">Target position in world space</param>
        /// <param name="up">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param>
        /// <returns>A SCNMatrix4 that transforms world space to camera space</returns>
        public static SCNMatrix4 LookAt(SCNVector3 eye, SCNVector3 target, SCNVector3 up)
        {
            SCNVector3 z = SCNVector3.Normalize(eye - target);
            SCNVector3 x = SCNVector3.Normalize(SCNVector3.Cross(up, z));
            SCNVector3 y = SCNVector3.Normalize(SCNVector3.Cross(z, x));

            SCNMatrix4 rot = new SCNMatrix4(new SCNVector4(x.X, y.X, z.X, 0.0f),
                                            new SCNVector4(x.Y, y.Y, z.Y, 0.0f),
                                            new SCNVector4(x.Z, y.Z, z.Z, 0.0f),
                                            SCNVector4.UnitW);

            SCNMatrix4 trans = SCNMatrix4.CreateTranslation(-eye);

            return(trans * rot);
        }
Ejemplo n.º 2
0
 public static void Multiply(ref SCNQuaternion left, ref SCNQuaternion right, out SCNQuaternion result)
 {
     result = new SCNQuaternion(
         right.W * left.Xyz + left.W * right.Xyz + SCNVector3.Cross(left.Xyz, right.Xyz),
         left.W * right.W - SCNVector3.Dot(left.Xyz, right.Xyz));
 }
Ejemplo n.º 3
0
 public static SCNQuaternion Mult(SCNQuaternion left, SCNQuaternion right)
 {
     return(new SCNQuaternion(
                right.W * left.Xyz + left.W * right.Xyz + SCNVector3.Cross(left.Xyz, right.Xyz),
                left.W * right.W - SCNVector3.Dot(left.Xyz, right.Xyz)));
 }