예제 #1
0
        protected virtual Tuple <Matrix3D, Matrix3D?> GetTransformationMatrix(float height)
        {
            var scale    = Scale;
            var position = Position;

            // scale matrix
            var scaleMatrix = new Matrix3D();

            scaleMatrix.SetScaling(scale.X, scale.Y, scale.Z);

            // translation matrix
            var transMatrix = new Matrix3D();

            transMatrix.SetTranslation(position.X, position.Y, position.Z + height);

            // rotation matrix
            var rotMatrix = new Matrix3D();

            rotMatrix.RotateZMatrix(RotationZ);

            var fullMatrix = scaleMatrix.Clone();

            fullMatrix.Multiply(rotMatrix);
            fullMatrix.Multiply(transMatrix);
            scaleMatrix.SetScaling(1.0f, 1.0f, 1.0f);
            fullMatrix.Multiply(scaleMatrix);

            return(new Tuple <Matrix3D, Matrix3D?>(fullMatrix, null));
        }
예제 #2
0
        static int Solve3D(string[] initialState)
        {
            int w = 21;
            int h = 21;
            int d = 21;

            var current = new Matrix3D <char>(w, h, d, Enumerable.Repeat('.', w * h * d).ToArray());
            int cx      = 6;
            int cy      = 6;
            int cz      = 10;

            for (int y = 0; y < initialState.Length; y++)
            {
                for (int x = 0; x < initialState[0].Length; x++)
                {
                    current[cx + x, cy + y, cz] = initialState[y][x];
                }
            }

            var next = current.Clone();

            for (int i = 1; i <= 6; i++)
            {
                for (int z = 0; z < d; z++)
                {
                    for (int y = 0; y < h; y++)
                    {
                        for (int x = 0; x < w; x++)
                        {
                            var state           = current[x, y, z];
                            int activeNeighbors = CountNeighbors(current, x, y, z);
                            if (state == '#')
                            {
                                next[x, y, z] = (activeNeighbors == 2 || activeNeighbors == 3) ? '#' : '.';
                            }
                            else
                            {
                                next[x, y, z] = activeNeighbors == 3 ? '#' : '.';
                            }
                        }
                    }
                }
                var tmp = current;
                current = next;
                next    = tmp;
            }
            return(current.Array.Count(c => c == '#'));
        }
예제 #3
0
        public void TestClone()
        {
            var m = new Matrix3D();

            m.SetRow(0, -3.41F, 8.06F, -22.01F);
            m.SetRow(1, 14.26F, -11.47F, 28.21F);
            m.SetRow(2, 12.71F, -9.61F, 23.87F);

            var c = m.Clone();

            Assert.IsTrue(Matrix3D.AreEqual(m, c));

            c[1, 1] = 20;

            Assert.IsFalse(Matrix3D.AreEqual(m, c));
        }
예제 #4
0
        protected override Tuple <Matrix3D, Matrix3D> GetTransformationMatrix(Table.Table table)
        {
            // scale matrix
            var scaleMatrix = new Matrix3D();

            scaleMatrix.SetScaling(Scale.X, Scale.Y, Scale.Z);

            // translation matrix
            var transMatrix = new Matrix3D();

            transMatrix.SetTranslation(Position.X, Position.Y, Position.Z + table.TableHeight);

            // translation + rotation matrix
            var rotTransMatrix = new Matrix3D();

            rotTransMatrix.SetTranslation(_data.RotAndTra[3], _data.RotAndTra[4], _data.RotAndTra[5]);

            var tempMatrix = new Matrix3D();

            tempMatrix.RotateZMatrix(MathF.DegToRad(_data.RotAndTra[2]));
            rotTransMatrix.Multiply(tempMatrix);
            tempMatrix.RotateYMatrix(MathF.DegToRad(_data.RotAndTra[1]));
            rotTransMatrix.Multiply(tempMatrix);
            tempMatrix.RotateXMatrix(MathF.DegToRad(_data.RotAndTra[0]));
            rotTransMatrix.Multiply(tempMatrix);

            tempMatrix.RotateZMatrix(MathF.DegToRad(_data.RotAndTra[8]));
            rotTransMatrix.Multiply(tempMatrix);
            tempMatrix.RotateYMatrix(MathF.DegToRad(_data.RotAndTra[7]));
            rotTransMatrix.Multiply(tempMatrix);
            tempMatrix.RotateXMatrix(MathF.DegToRad(_data.RotAndTra[6]));
            rotTransMatrix.Multiply(tempMatrix);

            var fullMatrix = scaleMatrix.Clone();

            fullMatrix.Multiply(rotTransMatrix);
            fullMatrix.Multiply(transMatrix);              // fullMatrix = Smatrix * RTmatrix * Tmatrix
            scaleMatrix.SetScaling(1.0f, 1.0f, table.GetScaleZ());
            fullMatrix.Multiply(scaleMatrix);

            return(new Tuple <Matrix3D, Matrix3D>(fullMatrix, null));
        }
예제 #5
0
 public void SetLocalMatrix(Matrix3D mat3D)
 {
     m_mat = mat3D.Clone();
 }
예제 #6
0
		public void TestClone()
		{
			var m = new Matrix3D();
			m.SetRow(0, -3.41F, 8.06F, -22.01F);
			m.SetRow(1, 14.26F, -11.47F, 28.21F);
			m.SetRow(2, 12.71F, -9.61F, 23.87F);

			var c = m.Clone();

			Assert.IsTrue(Matrix3D.AreEqual(m, c));

			c[1, 1] = 20;

			Assert.IsFalse(Matrix3D.AreEqual(m, c));
		}