return res;
}
Matrix operator * ( float v, const Matrix& a )
{
Matrix res;
for ( register int i = 0; i < 4; i++ )
for ( register int j = 0; j < 4; j++ ) res.x [i][j] = a.x [i]0] * v;
return res;
}
Vector3D operator * ( const Matrix& m, const Vector3D& v ) {
Vector3D res;
res.x = m.x [0][0] * v.x + m.x [0][1] * v.y +
m.x [0][2] * v.z + m.x [0][3]; res.y = m.x [1][0] * v.x + m.x [1][1] * v.y +
m.x [1][2]* v.z + m.x [1][3]; res.z = m.x [2][0] * v.x + m.x [2][1] * v.y +
m.x [2][2] * v.z + m.x [2][3];
float denom = m.x [3][0]* v.x + m.x [3][1]* v.y + m.x [3][2] * v.z + m.x [3][3];
if ( denom != 1.0 )
res /= denom;
return res;
}
//////////////// Derived functions /////////////////
Matrix translate^ const Vector3D& loc )
{
Matrix res ( 1 ); '
res.x [0][3] = loc.x; res.x [1][3] = loc.y; res.x [2][3] = loc.z;
return res;
}
Matrix scale ( const Vector3D& v )
{
Matrix res ( 1 ); res.x [0][0] = v.x; res.x [1][1] = v.y; res.x [2][2] = v.z;
9. ripeo6pa30BaHM5i b npodpaHCTBe, npoeicrnpoBaHM
return res;
}
Matrix rotateX (float angle )
{
Matrix res (1 );
float cosine = cos ( angle );
float sine = sin ( angle );
res.x [1][1] = cosine; res.x [1][2] = -sine; res.x [2][1] = sine; res.x [2][2] = cosine;
return res;
}
Matrix rotateY (float angle )
{
Matrix res (1 );
float cosine = cos ( angle );
float sine = sin ( angle );
res.x [0][0] = cosine; res.x [0][2] = -sine; res.x [2][0] = sine; res.x [2][2] = cosine;
return res; 1
}
Matrix rotateZ (float angle )
{
Matrix res (1 );
float cosine = cos ( angle );
float sine = sin ( angle );
res.x [0][0] = cosine; res.x [0][1] = -sine; res.x [1][0] = sine; res.x [1][1] = cosine;
return res;
}
Matrix rotation ( const Vector3D& axis, float angle )
{ -
Matrix res (1 );
float cosine = cos ( angle );
float sine = sin ( angle );
res.x [0][0] = axis.x*axis.x+(1-axis.x*axis.x )*cosine; res.x [1][0] = axis.x*axis.y*(1-cosine)+axis.z*sine; res.x [2][0] = axis.x*axis.z*(1-cosine)-axis.y*sine; res.x [3][0] = 0;
res.x [0][1] = axis.x*axis.y*(1-cosine)-axis.z*sine; res.x [1][1] = axis.y*axis.y+(1-axis.y*axis.y)*cosine; res.x [2][1] = axis.y*axis.z*(1-cosine)+axis.x*sine; res.x [3][1] = 0;

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