0

应用于对象的 3D 点的这种旋转会产生“波浪比例效果”而不是旋转。这段代码在某处有问题吗?

//----------- Init Rot Matrix (with float rotX=45, rotY=45, rotZ=45) -------------

boost::numeric::ublas::vector<float> Axisboost (4);
Axisboost(0) = 0;
Axisboost(1) = 0;
Axisboost(2) = 0;
Axisboost(3) = 1;

//RotX Matrix
Axisboost (1) = 1;
boost::numeric::ublas::matrix<double> mRotAXIS_X = GeoMath::GetSingletonPtr()->FromAxisAngle4(Axisboost, rotX*M_PI/180.);

//RotY Matrix
Axisboost (1) = 0;//(cancel previous axis)
Axisboost (2) = 1;
boost::numeric::ublas::matrix<double> mRotAXIS_Y = GeoMath::GetSingletonPtr()->FromAxisAngle4(Axisboost, rotY*M_PI/180.);

//RotZ Matrix
Axisboost (2) = 0;//(cancel previous axis)
Axisboost (3) = 1;
boost::numeric::ublas::matrix<double> mRotAXIS_Z = GeoMath::GetSingletonPtr()->FromAxisAngle4(Axisboost, rotZ*M_PI/180.);

[...]

//--------- Try to apply rotation matrix on a Cube --------------
boost::numeric::ublas::matrix<double> coordsOrig(4, 4);
coordsOrig(3,3)=1;

float* ptr_pPosX, *ptr_pPosY, *ptr_pPosZ;
float* pPos = static_cast<float*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));//ptr to points of cube

for(int i=0; i<72; i+=3){ //72 = 3coords * 2pts * 12lines
     //Get coordinates of 1 point
     ptr_pPosX=pPos;
     coordsOrig(0,0)=(double)*pPos++;
     ptr_pPosY=pPos;
     coordsOrig(1,1)=(double)*pPos++;
     ptr_pPosZ=pPos;
     coordsOrig(2,2)=(double)*pPos++;

     //Try to rotate 1 point around X, Y and Z axis       
     boost::numeric::ublas::matrix<double> afterRotX = boost::numeric::ublas::prod(coordsOrig, mRotAXIS_X);

     boost::numeric::ublas::matrix<double> afterRotXY = boost::numeric::ublas::prod(afterRotX, mRotAXIS_Y);

     boost::numeric::ublas::matrix<double> afterRotXYZ = boost::numeric::ublas::prod(afterRotXY, mRotAXIS_Z);

     //Set rotation result of 1 point
     *ptr_pPosX = (float)afterRotXYZ(0,0);
     *ptr_pPosY = (float)afterRotXYZ(1,1);
     *ptr_pPosZ = (float)afterRotXYZ(2,2);  
}
4

0 回答 0