Exemplo n.º 1
0
        protected Vector3[] RotateMatrix(Node root, float angle)
        {
            //Rotate the verticies matrix
            LightMatrix rotatedMatrix = modifiedVerticesMatrix.Duplicate();

            for (int i = 0; i < rotatorData.listRotationDimension.Length; i++)
            {
                LightMatrix rotationMatrix = LightMatrixRotationND.Rotation(
                    angle,
                    root.dimension,
                    rotatorData.listRotationDimension[i].x,
                    rotatorData.listRotationDimension[i].y);

                rotatedMatrix = LightMatrix.Multiply(rotatedMatrix, rotationMatrix);
            }

            Vector3[] rotatedVertices = new Vector3[rotatedMatrix.rows];

            //Convert matrix to 3D coordinate
            for (int i = 0; i < rotatedMatrix.rows; i++)
            {
                Vector3 position = rotatorData.dimensionReader.NDtoVector3(rotatedMatrix.GetRow(i));
                rotatedVertices[i] = position * rotatorData.size;
            }
            return(rotatedVertices);
        }
Exemplo n.º 2
0
 void CalculateVerticesMatrix(Node root)
 {
     verticesMatrix = new LightMatrix(root.vertices.Count, root.dimension);
     for (int i = 0; i < root.vertices.Count; i++)
     {
         verticesMatrix.SetRow(i, root.vertices[i].GetValues());
     }
     modifiedVerticesMatrix = verticesMatrix.Duplicate();
 }
Exemplo n.º 3
0
        public LightMatrix Duplicate()
        {
            LightMatrix matrix = new LightMatrix(rows, cols);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    matrix[i, j] = mat[i, j];
                }
            }
            return(matrix);
        }
Exemplo n.º 4
0
        private void PartialRotation()
        {
            if (verticesMatrix == null)
            {
                return;
            }

            for (int i = 0; i < rotatorData.rotationByDimension.Length; i++)
            {
                LightMatrix previousMatrix = (i == 0) ? verticesMatrix : modifiedVerticesMatrix;
                rotatorData.rotationByDimension[i].Update();
                modifiedVerticesMatrix = rotatorData.rotationByDimension[i].RotatePartialMatrix(previousMatrix);
            }
        }
Exemplo n.º 5
0
        public LightMatrix RotatePartialMatrix(LightMatrix matrix)
        {
            //Concept

            /* On rotate une matrice par l'angle et les dimensions
             * Si on rotate par la 2ieme dimension, il y a 4 vertex
             * Donc on alterne en 4 vertex de la  matrice orinal et de la rotated
             *
             * Si on rotate par la 3ième, il y a 8 vertex.. même chose
             * Si on rotate par la Nième dimension, il y a (2 ^ n) vertex
             */

            LightMatrix partialRotatedMatrix = new LightMatrix(matrix.rows, matrix.cols);
            LightMatrix rotationMatrix       = LightMatrixRotationND.Rotation(angle * Mathf.Deg2Rad, matrix.cols, rotationAroundDimension.x, rotationAroundDimension.y);

            LightMatrix fullyRotatedMatrix = LightMatrix.Multiply(matrix, rotationMatrix);

            int  twoPowerOfDimension = (int)Mathf.Pow(2, dimension);
            bool takeFromOriginal    = true;
            int  internalCounter     = 0;

            for (int i = 0; i < matrix.rows; i++)
            {
                if (takeFromOriginal)
                {
                    partialRotatedMatrix.SetRow(i, matrix.GetRow(i));
                }
                else
                {
                    partialRotatedMatrix.SetRow(i, fullyRotatedMatrix.GetRow(i));
                }

                internalCounter++;
                if (internalCounter == twoPowerOfDimension)
                {
                    internalCounter  = 0;
                    takeFromOriginal = !takeFromOriginal;
                }
            }
            return(partialRotatedMatrix);
        }
Exemplo n.º 6
0
        public static LightMatrix Multiply(LightMatrix m1, LightMatrix m2)
        {
            if (m1.cols != m2.rows)
            {
                throw new System.Exception("Wrong dimensions of matrix!");
            }

            LightMatrix result = new LightMatrix(m1.rows, m2.cols);

            for (int i = 0; i < result.rows; i++)
            {
                for (int j = 0; j < result.cols; j++)
                {
                    for (int k = 0; k < m1.cols; k++)
                    {
                        result[i, j] += m1[i, k] * m2[k, j];
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
 public static LightMatrix operator *(LightMatrix m1, LightMatrix m2)
 {
     return(LightMatrix.Multiply(m1, m2));
 }