00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <freecloth/geom/geMatrix4.h>
00020
00021
00022
00023
00024 FREECLOTH_NAMESPACE_START
00025
00026
00027
00028
00029 const GeMatrix4 GeMatrix4::IDENTITY(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
00030 const GeMatrix4 GeMatrix4::ZERO(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0);
00031
00032
00033
00034
00035 GeMatrix4 GeMatrix4::colMajor ( const Float data[ 16 ] )
00036 {
00037 GeMatrix4 result;
00038 ::memcpy( result._data, data, sizeof( result._data ) );
00039 return result;
00040 }
00041
00042
00043
00044 GeMatrix4 GeMatrix4::rowMajor ( const Float data[ 16 ] )
00045 {
00046 GeMatrix4 result;
00047 for( UInt32 r = 0; r < 4; ++r ) {
00048 for( UInt32 c = 0; c < 4; ++c ) {
00049 result._data[ c*4 + r ] = data[ r*4 + c ];
00050 }
00051 }
00052 return result;
00053 }
00054
00055
00056
00057 GeMatrix4 GeMatrix4::operator*( const GeMatrix4& rhs ) const
00058 {
00059 GeMatrix4 result;
00060 for ( UInt32 r = 0; r < 4; ++r ) {
00061 for ( UInt32 c = 0; c < 4; ++c ) {
00062 Float val = 0;
00063 for ( UInt32 i = 0; i < 4; ++i ) {
00064 val += operator()( r, i ) * rhs( i, c );
00065 }
00066 result( r, c ) = val;
00067 }
00068 }
00069 return result;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079 std::ostream& operator<<( std::ostream& out, const GeMatrix4& m )
00080 {
00081 out << "M4(" << std::endl;
00082 out << " " << m(0,0) << " " << m(0,1) << " "
00083 << m(0,2) << " " << m(0,3) << std::endl;
00084 out << " " << m(1,0) << " " << m(1,1) << " "
00085 << m(1,2) << " " << m(1,3) << std::endl;
00086 out << " " << m(2,0) << " " << m(2,1) << " "
00087 << m(2,2) << " " << m(2,3) << std::endl;
00088 out << " " << m(3,0) << " " << m(3,1) << " "
00089 << m(3,2) << " " << m(3,3) << std::endl;
00090 out << ")";
00091 return out;
00092 }
00093
00094 FREECLOTH_NAMESPACE_END