[Closed] SDK – get rotation and scale of object as x y z
I’ve tried everything I can think of now.
But I’m out of luck.
How can I get the rotation and scale of an object as x y z (like in the type in dialog) with the SDK.
I’m probably just missing something very easy.
I use the
nodeTM.GetTrans();
for getting the translation, but there is no “getRot \ scale”,
so any help is appreciated.
thanks in advance.
I think you looking for this one.
node->GetTMController()->GetPositionController()->GetValue();
node->GetTMController()->GetRotationController()->GetValue();
node->GetTMController()->GetScaleController()->GetValue();
Hi, thanks for your reply, I was unable to make that work, is there a chance you could elaborate on how it’s properly used?
thanks again.
try this one.
this code for position only
for rotation and scale exactly the same approach.
TimeValue t = GetCOREInterface()->GetTime();
float x,y,z;
node->GetTMController()->GetPositionController()->GetXController()->GetValue(t,&x,FOREVER,CTRL_ABSOLUTE);
node->GetTMController()->GetPositionController()->GetYController()->GetValue(t,&y,FOREVER,CTRL_ABSOLUTE);
node->GetTMController()->GetPositionController()->GetZController()->GetValue(t,&z,FOREVER,CTRL_ABSOLUTE);
hi again, thanks for the additional code!
I modified it to include rotation.
But something strange is going on, what I’m trying to do is to export a bone’s position, rotation, scale. the bone can have IK chain applied and so on, so I need the “world state” of this object.
The position works fine already,
but now when I add the code above, it does not look correct to me.
This is the result from the code:
<rotation x="0.000000" y="0.000000" z="-4.553800" />
this is what it says in 3dsmax gui (which is the value I need it to print out through code):
90.0 9.0 0.0
I also tested with a teapot, same result.
So do I need to convert the value? or is there something else I’m missing?
thanks again.
Ok.
Controllers store values in local space.
if you want in world space i think the best way will be to get node transform and then decompose its parts to position rotation and scale
you can do it with
decomp_affine(Matrix3 A, AffineParts *parts)
code will look something like that…
// in header file
#include <decomp.h>
// in cpp file
AffineParts parts;
decomp_affine(nodeTm,&parts);
//parts contains all portions of transform in different properties
Hi again, I’m still out of luck.
I implemented the code like this:
AffineParts parts;
decomp_affine(nodeTM,&parts);
mprintf("AffineParts q: %f %f %f
",parts.q.x,parts.q.y,parts.q.z);
mprintf("AffineParts f: %f
",parts.f);
mprintf("AffineParts k: %f %f %f
",parts.k.x,parts.k.y,parts.k.z);
mprintf("AffineParts t: %f %f %f
",parts.t.x,parts.t.y,parts.t.z);
mprintf("AffineParts u: %f %f %f
",parts.u.x,parts.u.y,parts.u.z);
I did this to print out all the values it could give me.
It returns this:
AffineParts q: -0.176183 0.684806 -0.684806
AffineParts f: 1.000000
AffineParts k: 1.000000 1.000000 1.000000
AffineParts t: 55.952255 0.000001 21.998579
AffineParts u: -0.000000 -0.000000 -0.000000
The translation part (which is the T) returns as it should, the rest does not.
The rotation xyz in max is:
x -90
y 28,856
z -180
I also found this function:
QuatToEuler()
I tried it this way:
Point3 ang;
QuatToEuler(objTM,ang,0,false);
mprintf("Ang: %f %f %f
",ang.x,ang.y,ang.z);
but this also returns same as previous. (and not as I expect).
I tried some other ways too, but I was unable to make it work.
Ang: -1.570796 -0.503626 -3.141593
your result is correct but it’s in radians
all you need is to convert it to degrees
in maxscript
radtodeg()
#define RadToDeg ( rad ) (((float)rad)*RAD_TO_DEG)
in SDk
thank you! It works perfectly now!
I implemented it like you said.
example:
Point3 ang;
QuatToEuler(objTM,ang,0,false);
mprintf("RadToDeg: %f %f %f
",RadToDeg_float(ang.x),RadToDeg_float(ang.y),RadToDeg_float(ang.z));
this returns the expected result.
Thank you again for your help! I really appreciate it.