Example #1
0
 private void Refresh()
 {
     if (!isdrity)
     {
         return;
     }
     isdrity    = false;
     _matrix    = UMatrix4x4.TRS(_localPos, _localRot, _localScale);
     _invmatrix = _matrix.Inverted();
 }
Example #2
0
        /// <summary>
        /// Looks at position, target and up.
        /// </summary>
        /// <returns>The <see cref="UMath.UMatrix4x4"/>.</returns>
        /// <param name="eye">Position.</param>
        /// <param name="target">Target.</param>
        /// <param name="up">Up.</param>
        public static UMatrix4x4 LookAt(UVector3 eye, UVector3 target, UVector3 up)
        {
            var w = (target - eye);

            w.Normalized();
            var u = UVector3.Cross(up, w);

            u.Normalized();
            var v = UVector3.Cross(w, u);

            v.Normalized();
            var trans = CreateTranslate(-eye);
            var m     = new UMatrix4x4(
                u.x, v.x, w.x, 0,
                u.y, v.y, w.y, 0,
                u.z, v.z, w.z, 0,
                0, 0, 0, 1);

            return(trans * m);
        }
Example #3
0
 /// <summary>
 /// Looks the rotation.
 /// </summary>
 /// <returns>The rotation.</returns>
 /// <param name="forward">Forward.</param>
 /// <param name="up">Up.</param>
 public static UQuaternion LookRotation(UVector3 forward, UVector3 up)
 {
     return(UMatrix4x4.LookAt(UVector3.zero, forward, up).Rotation);
 }
Example #4
0
 /// <summary>
 /// Decompose the specified m, trans, rotation and scale.
 /// </summary>
 /// <param name="m">M.</param>
 /// <param name="trans">Trans.</param>
 /// <param name="rotation">Rotation.</param>
 /// <param name="scale">Scale.</param>
 public static void Decompose(UMatrix4x4 m, out UVector3 trans, out UQuaternion rotation, out UVector3 scale)
 {
     trans    = m.Translate;
     rotation = m.Rotation;
     scale    = m.Scale;
 }