Example #1
0
        public void SetLookAt(Vector3 eye, Vector3 target, Vector3 up)
        {
            // Make rotation matrix
            // Z vector
            Vector3 zAxis = eye - target;

            zAxis.Normalize();

            Vector3 yAxis = up;

            Vector3 xAxis = yAxis.Cross(zAxis);

            // Recompute Y = Z cross X
            yAxis = zAxis.Cross(xAxis);

            xAxis.Normalize();
            yAxis.Normalize();

            basis = Basis.CreateFromAxes(xAxis, yAxis, zAxis);

            origin = eye;
        }
Example #2
0
        public void SetLookAt(Vector3 eye, Vector3 target, Vector3 up)
        {
            // Make rotation matrix
            // Z vector
            Vector3 column2 = eye - target;

            column2.Normalize();

            Vector3 column1 = up;

            Vector3 column0 = column1.Cross(column2);

            // Recompute Y = Z cross X
            column1 = column2.Cross(column0);

            column0.Normalize();
            column1.Normalize();

            basis = new Basis(column0, column1, column2);

            origin = eye;
        }
Example #3
0
 /// <summary>
 /// Constructs a transformation matrix from 4 vectors (matrix columns).
 /// </summary>
 /// <param name="column0">The X vector, or column index 0.</param>
 /// <param name="column1">The Y vector, or column index 1.</param>
 /// <param name="column2">The Z vector, or column index 2.</param>
 /// <param name="origin">The origin vector, or column index 3.</param>
 public Transform3D(Vector3 column0, Vector3 column1, Vector3 column2, Vector3 origin)
 {
     basis       = new Basis(column0, column1, column2);
     this.origin = origin;
 }
Example #4
0
        /// <summary>
        /// Scales the transform by the given 3D <paramref name="scale"/> factor.
        /// The operation is done in the local frame, equivalent to
        /// multiplying the matrix from the right.
        /// </summary>
        /// <param name="scale">The scale to introduce.</param>
        /// <returns>The scaled transformation matrix.</returns>
        public Transform3D ScaledLocal(Vector3 scale)
        {
            Basis tmpBasis = Basis.FromScale(scale);

            return(new Transform3D(basis * tmpBasis, origin));
        }
Example #5
0
        /// <summary>
        /// Rotates the transform around the given <paramref name="axis"/> by <paramref name="angle"/> (in radians).
        /// The axis must be a normalized vector.
        /// The operation is done in the local frame, equivalent to
        /// multiplying the matrix from the right.
        /// </summary>
        /// <param name="axis">The axis to rotate around. Must be normalized.</param>
        /// <param name="angle">The angle to rotate, in radians.</param>
        /// <returns>The rotated transformation matrix.</returns>
        public Transform3D RotatedLocal(Vector3 axis, real_t angle)
        {
            Basis tmpBasis = new Basis(axis, angle);

            return(new Transform3D(basis * tmpBasis, origin));
        }
Example #6
0
        /// <summary>
        /// Returns the inverse of the transform, under the assumption that
        /// the transformation is composed of rotation and translation
        /// (no scaling, use <see cref="AffineInverse"/> for transforms with scaling).
        /// </summary>
        /// <returns>The inverse matrix.</returns>
        public Transform3D Inverse()
        {
            Basis basisTr = basis.Transposed();

            return(new Transform3D(basisTr, basisTr.Xform(-origin)));
        }
Example #7
0
        /// <summary>
        /// Returns the inverse of the transform, under the assumption that
        /// the transformation is composed of rotation, scaling, and translation.
        /// </summary>
        /// <seealso cref="Inverse"/>
        /// <returns>The inverse transformation matrix.</returns>
        public Transform3D AffineInverse()
        {
            Basis basisInv = basis.Inverse();

            return(new Transform3D(basisInv, basisInv.Xform(-origin)));
        }
 /// <summary>
 /// Constructs a transformation matrix from the given quaternion and origin vector.
 /// </summary>
 /// <param name="quat">The <see cref="Godot.Quat"/> to create the basis from.</param>
 /// <param name="origin">The origin vector, or column index 3.</param>
 public Transform(Quat quat, Vector3 origin)
 {
     basis       = new Basis(quat);
     this.origin = origin;
 }
Example #9
0
 // Constructors
 public Transform(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 origin)
 {
     basis       = Basis.CreateFromAxes(xAxis, yAxis, zAxis);
     this.origin = origin;
 }
Example #10
0
 /// <summary>
 /// Constructs a <see cref="Quaternion"/> from the given <see cref="Basis"/>.
 /// </summary>
 /// <param name="basis">The <see cref="Basis"/> to construct from.</param>
 public Quaternion(Basis basis)
 {
     this = basis.Quaternion();
 }
Example #11
0
        public Vector3 GetEuler()
        {
            var basis = new Basis(this);

            return(basis.GetEuler());
        }
Example #12
0
        public Transform inverse()
        {
            Basis basisTr = basis.transposed();

            return(new Transform(basisTr, basisTr.xform(-origin)));
        }
Example #13
0
        public Transform affine_inverse()
        {
            Basis basisInv = basis.inverse();

            return(new Transform(basisInv, basisInv.xform(-origin)));
        }
Example #14
0
 public Transform(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 origin)
 {
     this.basis  = Basis.create_from_axes(xAxis, yAxis, zAxis);
     this.origin = origin;
 }
Example #15
0
 /// <summary>
 /// Constructs a transformation matrix from the given <paramref name="quaternion"/>
 /// and <paramref name="origin"/> vector.
 /// </summary>
 /// <param name="quaternion">The <see cref="Quaternion"/> to create the basis from.</param>
 /// <param name="origin">The origin vector, or column index 3.</param>
 public Transform3D(Quaternion quaternion, Vector3 origin)
 {
     basis       = new Basis(quaternion);
     this.origin = origin;
 }
Example #16
0
 /// <summary>
 /// Constructs a transformation matrix from the given <paramref name="basis"/> and
 /// <paramref name="origin"/> vector.
 /// </summary>
 /// <param name="basis">The <see cref="Basis"/> to create the basis from.</param>
 /// <param name="origin">The origin vector, or column index 3.</param>
 public Transform3D(Basis basis, Vector3 origin)
 {
     this.basis  = basis;
     this.origin = origin;
 }
Example #17
0
 public Quat(Basis basis)
 {
     this = basis.Quat();
 }