Пример #1
0
        private void Update(SceneState sceneState)
        {
            Vector3D eye = sceneState.Camera.Eye;

            //
            // Eye change means view matrix changed, so recompute
            // model-view-perspective relative to center.
            //
            if (_eye != eye)
            {
                _eye = eye;

                Matrix4D m = sceneState.ModelViewMatrix;
                Vector4D centerEye = m * new Vector4D(_center, 1.0);
                Matrix4D mv = new Matrix4D(
                    m.Column0Row0, m.Column1Row0, m.Column2Row0, centerEye.X,
                    m.Column0Row1, m.Column1Row1, m.Column2Row1, centerEye.Y,
                    m.Column0Row2, m.Column1Row2, m.Column2Row2, centerEye.Z,
                    m.Column0Row3, m.Column1Row3, m.Column2Row3, m.Column3Row3);

                _modelViewPerspectiveMatrixRelativeToCenter.Value =
                    (sceneState.PerspectiveMatrix * mv).ToMatrix4F();
            }

            _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
        }
Пример #2
0
        private void Update(SceneState sceneState)
        {
            Vector3D eye = sceneState.Camera.Eye;

            if (_eye != eye)
            {
                _eye = eye;

                Matrix4D m = sceneState.ModelViewMatrix;
                Matrix4D mv = new Matrix4D(
                    m.Column0Row0, m.Column1Row0, m.Column2Row0, 0.0,
                    m.Column0Row1, m.Column1Row1, m.Column2Row1, 0.0,
                    m.Column0Row2, m.Column1Row2, m.Column2Row2, 0.0,
                    m.Column0Row3, m.Column1Row3, m.Column2Row3, m.Column3Row3);

                _modelViewPerspectiveMatrixRelativeToEye.Value = 
                    (sceneState.PerspectiveMatrix * mv).ToMatrix4F();

                for (int i = 0; i < _positions.Length; ++i)
                {
                    _positionsRelativeToEye[i] = (_positions[i] - eye).ToVector3F();
                }

                _positionBuffer.CopyFromSystemMemory(_positionsRelativeToEye);
            }

            _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
        }
Пример #3
0
        public void Construct1()
        {
            Matrix4D m = new Matrix4D(1.0);

            for (int i = 0; i < m.NumberOfComponents; ++i)
            {
                Assert.AreEqual(1.0, m.ReadOnlyColumnMajorValues[0], 1e-14);
            }
        }
Пример #4
0
        public void Construct2()
        {
            Matrix4D m = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0);

            Assert.AreEqual(1.0, m.Column0Row0);
            Assert.AreEqual(2.0, m.Column1Row0);
            Assert.AreEqual(3.0, m.Column2Row0);
            Assert.AreEqual(4.0, m.Column3Row0);
            Assert.AreEqual(5.0, m.Column0Row1);
            Assert.AreEqual(6.0, m.Column1Row1);
            Assert.AreEqual(7.0, m.Column2Row1);
            Assert.AreEqual(8.0, m.Column3Row1);
            Assert.AreEqual(9.0, m.Column0Row2);
            Assert.AreEqual(10.0, m.Column1Row2);
            Assert.AreEqual(11.0, m.Column2Row2);
            Assert.AreEqual(12.0, m.Column3Row2);
            Assert.AreEqual(13.0, m.Column0Row3);
            Assert.AreEqual(14.0, m.Column1Row3);
            Assert.AreEqual(15.0, m.Column2Row3);
            Assert.AreEqual(16.0, m.Column3Row3);

            Assert.AreEqual(1.0, m.ReadOnlyColumnMajorValues[0]);
            Assert.AreEqual(5.0, m.ReadOnlyColumnMajorValues[1]);
            Assert.AreEqual(9.0, m.ReadOnlyColumnMajorValues[2]);
            Assert.AreEqual(13.0, m.ReadOnlyColumnMajorValues[3]);
            Assert.AreEqual(2.0, m.ReadOnlyColumnMajorValues[4]);
            Assert.AreEqual(6.0, m.ReadOnlyColumnMajorValues[5]);
            Assert.AreEqual(10.0, m.ReadOnlyColumnMajorValues[6]);
            Assert.AreEqual(14.0, m.ReadOnlyColumnMajorValues[7]);
            Assert.AreEqual(3.0, m.ReadOnlyColumnMajorValues[8]);
            Assert.AreEqual(7.0, m.ReadOnlyColumnMajorValues[9]);
            Assert.AreEqual(11.0, m.ReadOnlyColumnMajorValues[10]);
            Assert.AreEqual(15.0, m.ReadOnlyColumnMajorValues[11]);
            Assert.AreEqual(4.0, m.ReadOnlyColumnMajorValues[12]);
            Assert.AreEqual(8.0, m.ReadOnlyColumnMajorValues[13]);
            Assert.AreEqual(12.0, m.ReadOnlyColumnMajorValues[14]);
            Assert.AreEqual(16.0, m.ReadOnlyColumnMajorValues[15]);
        }
Пример #5
0
        public void Equals()
        {
            Matrix4D a = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0);
            Matrix4D b = new Matrix4D(0.0);
            Matrix4D c = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0);

            Assert.IsTrue(a.Equals(c));
            Assert.IsTrue(c.Equals(a));
            Assert.IsTrue(a == c);
            Assert.IsTrue(c == a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
            Assert.IsFalse(a == b);
            Assert.IsFalse(b == a);
            Assert.IsTrue(a != b);
            Assert.IsTrue(b != a);

            object objA = a;
            object objB = b;
            object objC = c;

            Assert.IsTrue(a.Equals(objA));
            Assert.IsTrue(a.Equals(objC));
            Assert.IsFalse(a.Equals(objB));

            Assert.IsTrue(objA.Equals(objC));
            Assert.IsFalse(objA.Equals(objB));

            Assert.IsFalse(a.Equals(null));
            Assert.IsFalse(a.Equals(5));
        }
Пример #6
0
        private void Update(SceneState sceneState)
        {
            Vector3D eye = sceneState.Camera.Eye;

            if (_eye != eye)
            {
                _eye = eye;

                Vector3F eyeHigh;
                Vector3F eyeLow;
                Vector3DToTwoVector3F(eye, out eyeHigh, out eyeLow);
                _cameraEyeHigh.Value = eyeHigh;
                _cameraEyeLow.Value = eyeLow;

                Matrix4D m = sceneState.ModelViewMatrix;
                Matrix4D mv = new Matrix4D(
                    m.Column0Row0, m.Column1Row0, m.Column2Row0, 0.0,
                    m.Column0Row1, m.Column1Row1, m.Column2Row1, 0.0,
                    m.Column0Row2, m.Column1Row2, m.Column2Row2, 0.0,
                    m.Column0Row3, m.Column1Row3, m.Column2Row3, m.Column3Row3);

                _modelViewPerspectiveMatrixRelativeToEye.Value =
                    (sceneState.PerspectiveMatrix * mv).ToMatrix4F();
            }

            _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
        }
Пример #7
0
        public bool Equals(Matrix4D other)
        {
            if (Matrix4D.ReferenceEquals(other, null))
            {
                return false;
            }

            for (int i = 0; i < _values.Length; ++i)
            {
                if (!_values[i].Equals(other._values[i]))
                {
                    return false;
                }
            }

            return true;
        }
Пример #8
0
        public static Matrix4D LookAt(Vector3D eye, Vector3D target, Vector3D up)
        {
            Vector3D f = (target - eye).Normalize();
            Vector3D s = f.Cross(up).Normalize();
            Vector3D u = s.Cross(f).Normalize();

            Matrix4D rotation = new Matrix4D(
                 s.X,  s.Y,  s.Z, 0.0,
                 u.X,  u.Y,  u.Z, 0.0,
                -f.X, -f.Y, -f.Z, 0.0,
                 0.0,  0.0,  0.0, 1.0);
            Matrix4D translation = new Matrix4D(
                1.0, 0.0, 0.0, -eye.X,
                0.0, 1.0, 0.0, -eye.Y,
                0.0, 0.0, 1.0, -eye.Z,
                0.0, 0.0, 0.0, 1.0);
            return rotation * translation;
        }
Пример #9
0
        public void DoubleToFloat()
        {
            Matrix4D m = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0);

            Matrix4F mf = m.ToMatrix4F();

            Assert.AreEqual(1.0f, mf.Column0Row0, 1e-7);
            Assert.AreEqual(2.0f, mf.Column1Row0, 1e-7);
            Assert.AreEqual(3.0f, mf.Column2Row0, 1e-7);
            Assert.AreEqual(4.0f, mf.Column3Row0, 1e-7);
            Assert.AreEqual(5.0f, mf.Column0Row1, 1e-7);
            Assert.AreEqual(6.0f, mf.Column1Row1, 1e-7);
            Assert.AreEqual(7.0f, mf.Column2Row1, 1e-7);
            Assert.AreEqual(8.0f, mf.Column3Row1, 1e-7);
            Assert.AreEqual(9.0f, mf.Column0Row2, 1e-7);
            Assert.AreEqual(10.0f, mf.Column1Row2, 1e-7);
            Assert.AreEqual(11.0f, mf.Column2Row2, 1e-7);
            Assert.AreEqual(12.0f, mf.Column3Row2, 1e-7);
            Assert.AreEqual(13.0f, mf.Column0Row3, 1e-7);
            Assert.AreEqual(14.0f, mf.Column1Row3, 1e-7);
            Assert.AreEqual(15.0f, mf.Column2Row3, 1e-7);
            Assert.AreEqual(16.0f, mf.Column3Row3, 1e-7);
        }
Пример #10
0
        public void TestGetHashCode()
        {
            Matrix4D a = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0);
            Matrix4D b = new Matrix4D(0.0);
            Matrix4D c = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0);

            Assert.AreEqual(a.GetHashCode(), c.GetHashCode());
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Пример #11
0
 public void MultiplyVector2()
 {
     Matrix4D m = new Matrix4D(
         1.0, 0.0, 2.0, 0.0,
         0.0, 1.0, 0.0, 2.0,
         2.0, 0.0, 1.0, 0.0,
         0.0, 2.0, 0.0, 1.0);
     Vector4D v = new Vector4D(1.0, 2.0, 3.0, 4.0);
     Vector4D result = new Vector4D(7.0, 10.0, 5.0, 8.0);
     Assert.AreEqual(result, m * v);
 }
Пример #12
0
        public void Transpose()
        {
            Matrix4D m = new Matrix4D(
                1.0, 2.0, 3.0, 4.0,
                5.0, 6.0, 7.0, 8.0,
                9.0, 10.0, 11.0, 12.0,
                13.0, 14.0, 15.0, 16.0).Transpose();

            Assert.AreEqual(1.0, m.Column0Row0);
            Assert.AreEqual(5.0, m.Column1Row0);
            Assert.AreEqual(9.0, m.Column2Row0);
            Assert.AreEqual(13.0, m.Column3Row0);
            Assert.AreEqual(2.0, m.Column0Row1);
            Assert.AreEqual(6.0, m.Column1Row1);
            Assert.AreEqual(10.0, m.Column2Row1);
            Assert.AreEqual(14.0, m.Column3Row1);
            Assert.AreEqual(3.0, m.Column0Row2);
            Assert.AreEqual(7.0, m.Column1Row2);
            Assert.AreEqual(11.0, m.Column2Row2);
            Assert.AreEqual(15.0, m.Column3Row2);
            Assert.AreEqual(4.0, m.Column0Row3);
            Assert.AreEqual(8.0, m.Column1Row3);
            Assert.AreEqual(12.0, m.Column2Row3);
            Assert.AreEqual(16.0, m.Column3Row3);
        }
Пример #13
0
 public void MultiplyVector0()
 {
     Matrix4D zero = new Matrix4D(0.0);
     Vector4D v = new Vector4D(1.0, 2.0, 3.0, 4.0);
     Assert.AreEqual(Vector4D.Zero, zero * v);
 }
Пример #14
0
        public void Multiply4()
        {
            Matrix4D m = new Matrix4D() * null;
			GC.KeepAlive(m);	// Fix MonoDevelop 2.2.1 CS0219 Warning
        }
Пример #15
0
 public void Multiply2()
 {
     Matrix4D left = new Matrix4D(1.0);
     Matrix4D right = new Matrix4D(1.0);
     Matrix4D result = new Matrix4D(
         4.0, 4.0, 4.0, 4.0,
         4.0, 4.0, 4.0, 4.0,
         4.0, 4.0, 4.0, 4.0,
         4.0, 4.0, 4.0, 4.0);
     Assert.AreEqual(result, left * right);
 }
Пример #16
0
 public void Multiply1()
 {
     Matrix4D m = new Matrix4D(
         1.0, 2.0, 3.0, 4.0,
         5.0, 6.0, 7.0, 8.0,
         9.0, 10.0, 11.0, 12.0,
         13.0, 14.0, 15.0, 16.0);
     Assert.AreEqual(m, Matrix4D.Identity * m);
 }
Пример #17
0
 public void Multiply0()
 {
     Matrix4D zero = new Matrix4D(0.0);
     Matrix4D m = new Matrix4D(
         1.0, 2.0, 3.0, 4.0,
         5.0, 6.0, 7.0, 8.0,
         9.0, 10.0, 11.0, 12.0,
         13.0, 14.0, 15.0, 16.0);
     Assert.AreEqual(zero, zero * m);
 }