Трехмерная графика
Категория реферата: Рефераты по информатике, программированию
Теги реферата: реферат на тему жизнь, реферат по экологии
Добавил(а) на сайт: Суворов.
Предыдущая страница реферата | 1 2 3 4 5 6 7 8 | Следующая страница реферата
// Файл matrix.cpp
#include
#include "matrix.h"
Matrix :: Matrix ( double v )
{ int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) x [i][j] = ( i == j ) ? v : 0.0; x [3][3] = 1;
}
void Matrix :: Invert ()
{
Matrix Out ( 1 ); for ( int i = 0; i < 4; i++ ) { double d = x [i][i]; if ( d != 1.0 ) { for ( int j = 0; j < 4; j++ ) {
Out.x [i][j] /= d; x [i][j] /= d;
}
} for ( int j = 0; j < 4; j++ ) { if ( j != i ) { if ( x[j][i] != 0.0 ) { double mulby = x[j][i]; for ( int k = 0; k < 4; k++ ) { x [j][k] -= mulby * x [i][k];
Out.x [j][k] -= mulby * Out.x [i][k];
}
}
}
}
}
*this = Out;
}
void Matrix :: Transpose ()
{ double t; int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) if ( i != j ) { t = x [i][j]; x [i][j] = x [j][i]; x [j][i] = t;
}
}
Matrix& Matrix :: operator += ( const Matrix& A )
{ int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) x [i][j] += A.x [i][j]; return *this;
}
Matrix& Matrix :: operator -= ( const Matrix& A )
{ int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) x [i][j] -= A.x [i][j]; return *this;
}
Matrix& Matrix :: operator *= ( double v )
{ int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) x [i][j] *= v; return *this;
}
Matrix& Matrix :: operator *= ( const Matrix& A )
{
Matrix res = *this; int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) { double sum = 0; for ( int k = 0; k < 4; k++ ) sum += res.x [i][k] * A.x [k][j]; x [i][j] = sum;
} return *this;
}
Matrix operator + ( const Matrix& A, const Matrix& B )
{
Matrix res; int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) res.x [i][j] = A.x [i][j] + B.x [i][j]; return res;
}
Matrix operator - ( const Matrix& A, const Matrix& B )
{
Matrix res; int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) res.x [i][j] = A.x [i][j] - B.x [i][j]; return res;
}
Matrix operator * ( const Matrix& A, const Matrix& B )
{
Matrix res; int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) { double sum = 0; for ( int k = 0; k < 4; k++ ) sum += A.x [i][k] * B.x [k][j]; res.x [i][j] = sum;
} return res;
}
Matrix operator * ( const Matrix& A, double v )
{
Matrix res; int j; for ( int i = 0; i < 4; i++ ) for ( j = 0; j < 4; j++ ) res.x [i][j] = A.x [i][j] * v; return res;
}
Vector operator * ( const Matrix& M, const Vector& v )
{
Vector res; res.x = v.x * M.x [0][0] + v.y * M.x [1][0] + v.z * M.x [2][0] + M.x
[3][0]; res.y = v.x * M.x [0][1] + v.y * M.x [1][1] + v.z * M.x [2][1] + M.x
[3][1]; res.z = v.x * M.x [0][2] + v.y * M.x [1][2] + v.z * M.x [2][2] + M.x
[3][2]; double denom = v.x * M.x [0][3] + v.y * M.x [1][3] + v.z * M.x [2][3] + M.x[3][3]; if ( denom != 1.0 ) res /= denom; return res;
}
Рекомендуем скачать другие рефераты по теме: рефераты рб, культурология шпаргалки.
Предыдущая страница реферата | 1 2 3 4 5 6 7 8 | Следующая страница реферата