Ejemplo n.º 1
0
        public void IsValidTest()
        {
            var m = Matrix44F.CreateTranslation(1, 2, 3) * Matrix44F.CreateRotationY(0.1f) * Matrix44F.CreateScale(-2, 3, 4);

            Assert.IsTrue(SrtTransform.IsValid(m));

            // Concatenating to SRTs creates a skew.
            m = Matrix44F.CreateRotationZ(0.1f) * Matrix44F.CreateScale(-2, 3, 4) * m;
            Assert.IsFalse(SrtTransform.IsValid(m));
        }
Ejemplo n.º 2
0
        public void FromToMatrixTest()
        {
            var t = new Vector3F(1, 2, 3);
            var r = new QuaternionF(1, 2, 3, 4).Normalized;
            var s = new Vector3F(2, 7, 9);
            var m = Matrix44F.CreateTranslation(t) * Matrix44F.CreateRotation(r) * Matrix44F.CreateScale(s);

            var srt = SrtTransform.FromMatrix(m);

            Assert.IsTrue(Vector3F.AreNumericallyEqual(t, srt.Translation));
            Assert.IsTrue(QuaternionF.AreNumericallyEqual(r, srt.Rotation));
            Assert.IsTrue(Vector3F.AreNumericallyEqual(s, srt.Scale));

            // XNA:
            srt = SrtTransform.FromMatrix((Matrix)m);
            Assert.IsTrue(Vector3F.AreNumericallyEqual(t, srt.Translation));
            Assert.IsTrue(QuaternionF.AreNumericallyEqual(r, srt.Rotation));
            Assert.IsTrue(Vector3F.AreNumericallyEqual(s, srt.Scale));

            // With negative scale, the decomposition is not unique (many possible combinations of
            // axis mirroring + rotation).
            t   = new Vector3F(1, 2, 3);
            r   = new QuaternionF(1, 2, 3, 4).Normalized;
            s   = new Vector3F(2, -7, 9);
            m   = Matrix44F.CreateTranslation(t) * Matrix44F.CreateRotation(r) * Matrix44F.CreateScale(s);
            srt = SrtTransform.FromMatrix(m);
            var m2 = (Matrix44F)srt;

            Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, m2));

            m2 = srt.ToMatrix44F();
            Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, m2));

            m2 = srt;
            Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, m2));

            Matrix mXna = srt.ToXna();

            Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, (Matrix44F)mXna));

            mXna = srt;
            Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, (Matrix44F)mXna));
        }
Ejemplo n.º 3
0
        private void UpdateCamera(CameraNode camera)
        {
            // Camera distance from CameraTarget.
            float distance = (camera.PoseWorld.Position - CameraTarget).Length;

            // Re-orthogonalize to remove numerical errors which could add up.
            var minor = _transform.Minor;

            minor.Orthogonalize();
            _transform.Minor = minor;

            // Create view matrix for look at origin (ignoring CameraTarget).
            camera.View = Matrix44F.CreateTranslation(0, 0, -distance) * _transform;

            // Apply translation to look at CameraTarget.
            var pose = camera.PoseWorld;

            pose.Position   += CameraTarget;
            camera.PoseWorld = pose;
        }