|
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <iostream>
#pragma comment( lib, "osgd.lib")
#pragma comment( lib, "osgViewerd.lib")
#pragma comment( lib, "osgDBd.lib")
#pragma comment( lib, "OpenThreadsd.lib")
#pragma comment( lib, "osgUtild.lib")
#pragma comment( lib, "osgGAd.lib")
#pragma comment( lib, "osgTextd.lib")
#pragma comment( lib, "osgSimd.lib")
osg::Vec3d postMult(double _mat[][4],osg::Vec3d v)
{
osg::Vec3d::value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]);
return osg::Vec3d((_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d);
}
osg::Vec3d preMult(double _mat[][4],osg::Vec3d v)
{
osg::Vec3d::value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
return osg::Vec3f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
}
int _tmain(int argc, _TCHAR* argv[])
{
osg::Vec3d b;
b.set(1,2,3);
double _mat[4][4] = {
1,0,0,0,
0,1,0,0,
0,0,1,0,
4,0,1,1
};
osg::Vec3d f = preMult(_mat,b);//f=5,2,4
osg::Vec3d f2 = postMult(_mat,b);//f=0.125,0.25,0.375
getchar();
return 0;
}
|
|