Problem MeshgroupTransform no 3-axis rotation ?

Mindblast

Donator
Donator
Joined
Aug 29, 2008
Messages
169
Reaction score
0
Points
16
Location
Berlin
Website
www.nestadlinn.de
I'm trying to do some manual animations using clbkAnimate and manipulating my meshgroups with MeshgroupTransform. I noticed the following: When i try to do a rotation around an axis vector that has 1 or 2 of its components set to nonzero the rotation works, if i use a vector that has all 3 components nonzero the rotation is not carried out. Semi automatic animations using MGROUP_ROTATE and AddAnimationComponent etc. don't seem to have this problem. Has anyone had the same problem? Might be a bug in the API i think. (I just tested this with the 2006 release, not with the current beta)

---------- Post added at 10:45 AM ---------- Previous post was at 09:37 AM ----------

Just tested it in the beta and i have the same problem there.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,605
Reaction score
2,327
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Did you remember making sure that the rotation axis vector has to be normalized?

I can't remember ever having had such problems.
 

Mindblast

Donator
Donator
Joined
Aug 29, 2008
Messages
169
Reaction score
0
Points
16
Location
Berlin
Website
www.nestadlinn.de
Yes i tested it with _V(0.577350269, 0.577350269, 0.577350269) for the axis vector. With the semi automatic animation it works, with MeshgroupTransform it does nothing, whereas if i use _V(0.707106781, 0.707106781, 0) it works both ways.
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Looking at the code, you are correct. Rotation around a general axis is currently not supported with MeshgroupTransform. I have regarded this method as somewhat obsolete with the arrival of the animation component mechanism using the MGROUP_TRANSFORM classes, so I never updated the transformation code for MeshgroupTransform. If this is still regarded useful, I can try to bring it up to date for the next beta.
 

Mindblast

Donator
Donator
Joined
Aug 29, 2008
Messages
169
Reaction score
0
Points
16
Location
Berlin
Website
www.nestadlinn.de
It would certainly be useful for me. I'm trying to do a somewhat complicated landing gear animation with inverse kinematic like features (pneumatic cylinders and such) so i decided to use the clbkAnimate method for better control of the non-linear rotations. I probably could have done it with the MGROUP_TRANSFORM too but i had the impression it would have been more complicated.

Maybe you could make a MeshgroupTransform like function that takes a MGROUP_TRANSFORM pointer as a parameter just like AddAnimationComponent does ? So the MESHGROUP_TRANSFORM structure could go obsolete.

---------- Post added at 03:26 PM ---------- Previous post was at 03:06 PM ----------

Hmmmm.. actually now looking at the documentation for MGROUP_TRANSFORM and AddAnimationComponent.. maybe i was wrong.. especially being able to track Vectors through the animation would simplify things alot for me as i do that manually now. I guess i'll rewrite my code to use this.. so never mind Martin. :)
 

JLBarnes

New member
Joined
May 23, 2010
Messages
1
Reaction score
0
Points
0
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);
}
 
Top