Example #1
0
        public static Matrix4x4d TranslateRotateScale(Vector3d t, Vector4d q, Vector3d e)
        {
            Matrix4x4d mt = Translate(t.X, t.Y, t.Z);
            Matrix4x4d mr = RotateQuat(q);
            Matrix4x4d me = Scale(e.X, e.Y, e.Z);

            // mt * mr * me
            Matrix4x4d m = mt;

            m.Mul(mr);
            m.Mul(me);
            return(m);
        }
Example #2
0
        /// <summary>
        ///     <see cref="http://adndevblog.typepad.com/autocad/2012/08/remove-scaling-from-transformation-matrix.html" />
        /// </summary>
        public static Matrix4x4d RemoveScaling(Matrix4x4d m, double scalingValue = 1)
        {
            Vector3d v0 = new Vector3d(m.M00, m.M01, m.M02).Unit.Mul(scalingValue);
            Vector3d v1 = new Vector3d(m.M10, m.M11, m.M12).Unit.Mul(scalingValue);
            Vector3d v2 = new Vector3d(m.M20, m.M21, m.M22).Unit.Mul(scalingValue);

            return(new Matrix4x4d(
                       new[, ]
            {
                { v0.X, v0.Y, v0.Z, m.M02 },
                { v1.X, v1.Y, v1.Z, m.M12 },
                { v2.X, v2.Y, v2.Z, m.M22 },
                { m.M30, m.M31, m.M32, m.M33 }
            }));
        }
Example #3
0
        /// <summary>
        ///     Crea una matriz con la traslacion, rotacion y escala.
        /// </summary>
        /// <param name="tx">Traslacion x.</param>
        /// <param name="ty">Traslacion y.</param>
        /// <param name="tz">Traslacion z.</param>
        /// <param name="rx">Angulo en radianes x respecto al plano YZ.</param>
        /// <param name="ry">Angulo en radianes y respecto al plano XZ.</param>
        /// <param name="rz">Angulo en radianes z respecto al plano XY.</param>
        /// <param name="ex">Escala x.</param>
        /// <param name="ey">Escala y.</param>
        /// <param name="ez">Escala z.</param>
        /// <returns>Matriz de escala, rotacion y traslacion.</returns>
        public static Matrix4x4d TranslateRotateScale(
            double tx, double ty, double tz,
            double rx, double ry, double rz,
            double ex, double ey, double ez)
        {
            Matrix4x4d mt = Translate(tx, ty, tz);
            Matrix4x4d mr = Rotate(rx, ry, rz);
            Matrix4x4d me = Scale(ex, ey, ez);

            // mt * mr * me
            Matrix4x4d m = mt;

            m.Mul(mr);
            m.Mul(me);
            return(m);
        }
Example #4
0
        /// <summary>
        ///     Crea una matriz que coloca la camara en <c>posicion</c> mirando en direccion <c>dir</c>.
        ///     La direccion <c>up</c> marca la coordenada Y.
        /// </summary>
        /// <param name="eye">Posicion de la camara.</param>
        /// <param name="dir">Direccion a la que mira la camara.</param>
        /// <param name="up">Direccion Y de la camara.</param>
        /// <returns></returns>
        public static Matrix4x4d LookAt(Point3d eye, Vector3d dir, Vector3d up)
        {
            Vector3d fN  = dir.Unit;
            Vector3d upN = up.Unit;

            Vector3d sN = fN.Cross(upN);
            Vector3d uN = sN.Cross(fN);

            Matrix4x4d m = new Matrix4x4d(
                sN.X, sN.Y, sN.Z, 0,
                uN.X, uN.Y, uN.Z, 0,
                -fN.X, -fN.Y, -fN.Z, 0,
                0, 0, 0, 1);

            m.Mul(Translate(eye.X, eye.Y, eye.Z));
            return(m);
        }
Example #5
0
        public override ITransform3 Concat(ITransform3 transform)
        {
            if (transform is Transform3Identity)
            {
                return(transform);
            }

            Transform3Matrix tmatrix = transform as Transform3Matrix;

            if (tmatrix == null)
            {
                throw new NotImplementedException();
            }

            Matrix4x4d result = this.Matrix.Clone();

            result.Mul(tmatrix.Matrix);
            return(new Transform3Matrix(result, true));
        }
Example #6
0
 public Transform3Matrix(Matrix4x4d matrix, bool share = true)
 {
     this.Matrix = (share ? matrix : matrix.Clone());
 }
Example #7
0
 public override void GetMatrix(Matrix4x4d matrix)
 {
     matrix.Set(this.Matrix);
 }