``````Matrix3D a ( 1.0 ); a.x [0][0] = -1.0; return a;
}
Matrix3D mirrorY ()
{ .
Matrix3D a ( 1.0 ); a.x[1][1] = -1.0; return a;
}
Matrix3D mirrorZ () {
Matrix3D a ( 1.0 ); a.x [2][2] = -1.0; return a;
}
21 // File matrix.h
#ifndef_MATRIX___ #define __MATRIX__
#include <mem.h> #include "VectorSD.h"
class Matrix {
public:
float x [4][4];
Matrix () {}
Matrix (float);
Matrix ( const Matrix& m )
{
memcpy ( & x [0][0], &m.x [0][0], 16*sizeof (float));
}
Matrix& operator += ( const Matrix& ); Matrix& operator -= ( const Matrix& ); Matrix& operator *= ( const Matrix& ); Matrix& operator *= (float); Matrix& operator /= (float);
9. npeo6pa30BaHHjR b npodpaHCTBe, npoeKTHpoB
float * operator [] ( int i ) {
return & x[i][0];
< }
void invert ();
void transpose ();
friend Matrix operator + (const Matrix&, const Matrix&);
friend Matrix operator - (const Matrix&, const Matrix&);
friend Matrix operator * (const Matrix&, float); friend Matrix operator * (float, const Matrix&);
friend Matrix operator * (const Matrix&, const Matrix&);
friend Vector3D operator * (const Matrix&, const Vector3D&);
};
Matrix translate ( const Vector3D& );
Matrix scale ( const Vector3D& );
Matrix rotateX (float);
Matrix rotateY ( float );
Matrix rotateZ ( float );
Matrix rotate ( const Vector3D& v, float );
Matrix mirrorX ();
Matrix mirrorY ();
Matrix mirrorZ ();
#endif
(21 // File matrix.cpp #include <math.h> #include "Matrix.h"
Matrix :: Matrix ( float v ) {
for ( int i = 0; i < 4; i++)
for(int j = 0;j < 4;j++)
x [i]fl] = (i == j) ? v : 0.0;
x[3][3] = 1;
}
void Matrix :: invert () {
Matrix out ( 1 );
for ( int i = 0; i < 4; i++ ) {
float d = x [i][i];
if ( d != 1.0) {
for ( int j = 0; j < 4; j++ ) {
out.x [i]Q] /= d; x[i]D] /=d;
}
}``````

Компьютерная графика. Полигональные модели

``````for (int j = 0; j < 4: i++ ) {
if(j!=i) {
if ( x mi != 0.0)
{``````

⇐ Предыдущая| |Следующая ⇒