Workaround to do 3 axis MeshgroupTransform
This is a little bit of code to fix the problem if you still need to use MeshgroupTransform
bool MeshGroupRotate(VESSEL2 *vs, VISHANDLE vis, MESHGROUP_TRANSFORM &mt)
{
// Test to see if speacial code needed to over come bug is needed
if(mt.P.rotparam.axis.x!=0 && mt.P.rotparam.axis.y!=0 && mt.P.rotparam.axis.z!=0)
{
// calculate the angle of the axis from the xz plane
double tmp_angle;
if(mt.P.rotparam.axis.x>=0.0 && mt.P.rotparam.axis.y>=0.0)
tmp_angle=atan2(mt.P.rotparam.axis.x,mt.P.rotparam.axis.y);
else
if(mt.P.rotparam.axis.x>=0.0 && mt.P.rotparam.axis.y<0.0)
tmp_angle=PI-atan2(mt.P.rotparam.axis.x,-mt.P.rotparam.axis.y);
else
if(mt.P.rotparam.axis.x<0.0 && mt.P.rotparam.axis.y<0.0)
tmp_angle=atan2(-mt.P.rotparam.axis.x,-mt.P.rotparam.axis.y)-PI;
else
if(mt.P.rotparam.axis.x<0.0 && mt.P.rotparam.axis.y>=0.0)
tmp_angle=-atan2(-mt.P.rotparam.axis.x,mt.P.rotparam.axis.y);
// save the existing axis and angle
VECTOR3 save_axis=mt.P.rotparam.axis;
float save_angle=mt.P.rotparam.angle;
// create the two new axis vectors
VECTOR3 temp_axis={sqrt(save_axis.x*save_axis.x+save_axis.y*save_axis.y),0.0,save_axis.z};
VECTOR3 z_axis={0.0,0.0,1.0};
//temp_axis=NormalizeVector(temp_axis); No need to normalize it is already normalized.
// first rotate to the xz plane
mt.P.rotparam.angle=(float)(-tmp_angle);
mt.P.rotparam.axis=z_axis;
if(!vs->MeshgroupTransform(vis,mt))
{
// return the MESHGROUP_TRANSFORM to the way it was before exit
mt.P.rotparam.angle=save_angle;
mt.P.rotparam.axis=save_axis;
return false; //failed
}
// now rotate around the the two axis value of the intended rotation
mt.P.rotparam.angle=save_angle;
mt.P.rotparam.axis=temp_axis;
bool b=vs->MeshgroupTransform(vis,mt);
// finally rotate back the way we came away from the xz plane
mt.P.rotparam.angle=(float)(tmp_angle);
mt.P.rotparam.axis=z_axis;
b= (vs->MeshgroupTransform(vis,mt) && b);
// return the MESHGROUP_TRANSFORM to the way it was before exit
mt.P.rotparam.angle=save_angle;
mt.P.rotparam.axis=save_axis;
return b; //succesful
}
else
return vs->MeshgroupTransform(vis,mt);
}