Esempio n. 1
0
	public static void SyncMatrix(Movie movie)
	{
		int matrixId = movie.matrixId;
		float scaleX = 1;
		float scaleY = 1;
		float rotation = 0;
		Matrix matrix;
		if ((matrixId & (int)Constant.MATRIX_FLAG) == 0) {
			Translate translate = movie.lwf.data.translates[matrixId];
			matrix = new Matrix(scaleX, scaleY,
				0, 0, translate.translateX, translate.translateY);
		} else {
			matrixId &= ~(int)Constant.MATRIX_FLAG_MASK;
			matrix = movie.lwf.data.matrices[matrixId];
			bool md = GetMatrixDeterminant(matrix);
			scaleX = (float)Math.Sqrt(
				matrix.scaleX * matrix.scaleX + matrix.skew1 * matrix.skew1);
			if (md)
				scaleX = -scaleX;
			scaleY = (float)Math.Sqrt(
				matrix.scaleY * matrix.scaleY + matrix.skew0 * matrix.skew0);
			if (md)
				rotation = (float)Math.Atan2(matrix.skew1, -matrix.scaleX);
			else
				rotation = (float)Math.Atan2(matrix.skew1, matrix.scaleX);
			rotation = rotation / (float)Math.PI * 180.0f;
		}

		movie.SetMatrix(matrix, scaleX, scaleY, rotation);
	}
Esempio n. 2
0
        public static void GetMatrix(Movie movie)
        {
            int    matrixId = movie.matrixId;
            float  scaleX   = 1;
            float  scaleY   = 1;
            float  rotation = 0;
            Matrix matrix;

            if ((matrixId & (int)Constant.MATRIX_FLAG) == 0)
            {
                Translate translate = movie.lwf.data.translates[matrixId];
                matrix = new Matrix(scaleX, scaleY,
                                    0, 0, translate.translateX, translate.translateY);
            }
            else
            {
                matrixId &= ~(int)Constant.MATRIX_FLAG_MASK;
                matrix    = movie.lwf.data.matrices[matrixId];
                bool md = GetMatrixDeterminant(matrix);
                scaleX = (float)Math.Sqrt(
                    matrix.scaleX * matrix.scaleX + matrix.skew1 * matrix.skew1);
                if (md)
                {
                    scaleX = -scaleX;
                }
                scaleY = (float)Math.Sqrt(
                    matrix.scaleY * matrix.scaleY + matrix.skew0 * matrix.skew0);
                if (md)
                {
                    rotation = (float)Math.Atan2(matrix.skew1, -matrix.scaleX);
                }
                else
                {
                    rotation = (float)Math.Atan2(matrix.skew1, matrix.scaleX);
                }
                rotation = rotation / (float)Math.PI * 180.0f;
            }

            movie.SetMatrix(matrix, scaleX, scaleY, rotation);
        }