Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / MY / MATRIX

.CPP
Скачиваний:
22
Добавлен:
16.04.2013
Размер:
1.91 Кб
Скачать
//Є« бб ¬ ваЁжл ЇаҐ®Ўа §®ў ­Ё©
#include "point.cpp"

class Matrix {
	public :
		float mtx [4][4];     //¬ ваЁж  ЇаҐ®а §®ў ­Ё©
		Matrix ();            //Є®­бвагЄв®а
		void Identity ();
		void Rotate_Y ( float yy );
		void Rotate_X ( float xx );
		void Rotate_Z ( float zz );
		void Multiply ( int n, Point *In, Point *Out);
	};

Matrix :: Matrix ()
{
	Identity ();
}

void Matrix :: Identity ()
{
 /* ᮧ¤ Ґ¬ Ґ¤Ё­Ёз­го ¬ ваЁжг
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1     */

	mtx [0][0] = 1.0;
	mtx [0][1] = 0.0;
	mtx [0][2] = 0.0;
	mtx [0][3] = 0.0;

	mtx [1][0] = 0.0;
	mtx [1][1] = 1.0;
	mtx [1][2] = 0.0;
	mtx [1][3] = 0.0;

	mtx [2][0] = 0.0;
	mtx [2][1] = 0.0;
	mtx [2][2] = 1.0;
	mtx [2][3] = 0.0;

	mtx [3][0] = 0.0;
	mtx [3][1] = 0.0;
	mtx [3][2] = 0.0;
	mtx [3][3] = 1.0;
}

void Matrix :: Rotate_Y ( float yy )
{
	float Sin, Cos;

	Sin = sin ( yy );
	Cos = cos ( yy );
	mtx [0][0] = Cos;
	mtx [0][2] = -Sin;
	mtx [2][0] = Sin;
	mtx [2][2] = Cos;
}

void Matrix :: Rotate_X ( float xx )
{
	float Sin, Cos;

	Sin = sin ( xx );
	Cos = cos ( xx );
	mtx [1][1] = Cos;
	mtx [1][2] = Sin;
	mtx [2][1] = -Sin;
	mtx [2][2] = Cos;
}

void Matrix :: Rotate_Z ( float zz )
{
	float Sin, Cos;

	Sin = sin ( zz );
	Cos = cos ( zz );
	mtx [0][0] = Cos;
	mtx [0][1] = Sin;
	mtx [1][0] = -Sin;
	mtx [1][1] = Cos;
}



void Matrix :: Multiply ( int n, Point *In, Point *Out )
{
	float	x0, y0, z0;

	/*	Transform all
		of the points.	*/
	while ( --n >= 0 ) {

		x0 = In [n].x;
		y0 = In [n].y;
		z0 = In [n].z;

		/*	Now multiply and
			store back.	*/
		Out [n].x = ( x0 * mtx [0][0] ) + ( y0 * mtx [0][1] ) +
				( z0 * mtx [0][2] );
		Out [n].y = ( x0 * mtx [1][0] ) + ( y0 * mtx [1][1] ) +
				( z0 * mtx [1][2] );
		Out [n].z = ( x0 * mtx [2][0] ) + ( y0 * mtx [2][1] ) +
				( z0 * mtx [2][2] );
	}
}
Соседние файлы в папке MY