Пример #1
0
        public void Transform()
        {
            // TScale
            Vector3D vi = new Vector3D(1, 1, 1);
            TScale   s  = new TScale(1, 1, 2);
            Vector3D vo = s * vi;

            Assert.True(AlmostEqual(vi.x * s.x, vo.x));
            Assert.True(AlmostEqual(vi.y * s.y, vo.y));
            Assert.True(AlmostEqual(vi.z * s.z, vo.z));

            // TTranslate
            TTranslate t1 = new TTranslate(1, 0, 1);

            vo = t1 * vi;
            Assert.True(AlmostEqual(vi.x + t1.x, vo.x));

            TTranslate t2 = new TTranslate(vi);

            vo = t2 * vi;
            Assert.True(AlmostEqual(2 * vi.x, vo.x));
            Assert.True(AlmostEqual(2 * vi.y, vo.y));
            Assert.True(AlmostEqual(2 * vi.z, vo.z));

            // Rotate origin
            vi = new Vector3D(1, 0, 0);
            TRotateOrigin ro = new TRotateOrigin(0, 0, 1, Math.PI);

            vo = ro * vi;
            Assert.True(AlmostEqual(-vi.x, vo.x));
            ro = new TRotateOrigin(0, 1, 0, Math.PI);
            vo = ro * vi;
            Assert.True(AlmostEqual(-vi.x, vo.x));
            ro = new TRotateOrigin(1, 0, 0, Math.PI / 2);
            vo = ro * vi;
            Assert.True(AlmostEqual(vi.x, vo.x));
            ro = new TRotateOrigin(1, 0, 1, Math.PI);
            vo = ro * vi;
            Assert.True(AlmostEqual(vi.x, vo.z));

            // Rotate X
            vi = new Vector3D(1, 1, 0);
            TRotateX rx = new TRotateX(Math.PI / 2);

            vo = rx * vi;
            Assert.True(AlmostEqual(vi.x, vo.x));
            Assert.True(AlmostEqual(vi.y, vo.z));

            // Rotate Y
            vi = new Vector3D(1, 0, 0);
            TRotateY ry = new TRotateY(Math.PI);

            vo = ry * vi;
            Assert.True(AlmostEqual(vi.x, -vo.x));

            // Rotate Z
            vi = new Vector3D(1, 1, 1);
            TRotateZ rz = new TRotateZ(Math.PI);

            vo = rz * vi;
            Assert.True(AlmostEqual(vi.x, -vo.x));
            Assert.True(AlmostEqual(vi.y, -vo.y));
        }
        public void Transform()
        {
            // TScale
            Vector3D vi = new Vector3D(1, 1, 1);
            TScale s = new TScale(1, 1, 2);
            Vector3D vo = s * vi;
            
            Assert.True(AlmostEqual(vi.x * s.x, vo.x));
            Assert.True(AlmostEqual(vi.y * s.y, vo.y));
            Assert.True(AlmostEqual(vi.z * s.z, vo.z));

            // TTranslate
            TTranslate t1 = new TTranslate(1, 0, 1);
            vo = t1 * vi;
            Assert.True(AlmostEqual(vi.x + t1.x, vo.x));

            TTranslate t2 = new TTranslate(vi);
            vo = t2 * vi;
            Assert.True(AlmostEqual(2 * vi.x, vo.x));
            Assert.True(AlmostEqual(2 * vi.y, vo.y));
            Assert.True(AlmostEqual(2 * vi.z, vo.z));

            // Rotate origin
            vi = new Vector3D(1, 0, 0);
            TRotateOrigin ro = new TRotateOrigin(0, 0, 1, Math.PI);
            vo = ro * vi;
            Assert.True(AlmostEqual(-vi.x, vo.x));
            ro = new TRotateOrigin(0, 1, 0, Math.PI);
            vo = ro * vi;
            Assert.True(AlmostEqual(-vi.x, vo.x));
            ro = new TRotateOrigin(1, 0, 0, Math.PI/2);
            vo = ro * vi;
            Assert.True(AlmostEqual(vi.x, vo.x));
            ro = new TRotateOrigin(1, 0, 1, Math.PI);
            vo = ro * vi;
            Assert.True(AlmostEqual(vi.x, vo.z));

            // Rotate X
            vi = new Vector3D(1, 1, 0);
            TRotateX rx = new TRotateX(Math.PI / 2);
            vo = rx * vi;
            Assert.True(AlmostEqual(vi.x, vo.x));
            Assert.True(AlmostEqual(vi.y, vo.z));

            // Rotate Y
            vi = new Vector3D(1, 0, 0);
            TRotateY ry = new TRotateY(Math.PI);
            vo = ry * vi;
            Assert.True(AlmostEqual(vi.x, -vo.x));

            // Rotate Z
            vi = new Vector3D(1, 1, 1);
            TRotateZ rz = new TRotateZ(Math.PI);
            vo = rz * vi;
            Assert.True(AlmostEqual(vi.x, -vo.x));
            Assert.True(AlmostEqual(vi.y, -vo.y));
        }