Wrong thinking

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

Wrong thinking

Post by kevinsbro »

Can someone help me understand why when

Code: Select all

vector3df rot, pos;
pos.set(9.0,17.0,8.0);
rot.set(67.0,90.0,50.0);
 
pos.set(rot.rotationToDirection(pos));
rot.invert();
pos.set(rot.rotationToDirection(pos));
 
position doesn't still equal [9.0,17.0,8.0] ????

All its doing is rotating a vector and then rotating it back right?
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Wrong thinking

Post by shadowslair »

Because rotationToDirection() returns a unit (normalized) vector? It just rotates a unit vector by the euler angles. IMO the last part of code doesn`t make much sense at all.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Wrong thinking

Post by smso »

I guess "rot" in your case means the orientation of the scene node and it is different from the rotation operation. If the rotation operation is done by matrix, then

Code: Select all

core::vector3df pos(9.0f, 17.0f, 8.0f);
printf("(%f,%f,%f)\n", pos.X, pos.Y, pos.Z);
 
core::vector3df zdir(0.0f, 0.0f, 1.0f);
core::vector3df rot(67.0f, 90.0f, 50.0f);
core::vector3df dir = rot.rotationToDirection(zdir);
// or core::vector3df dir = rot.rotationToDirection();
// since arg. defaults to zdir 
 
 
core::matrix4 mat;
mat.buildRotateFromTo(zdir, dir);
mat.transformVect(pos);
printf("(%f,%f,%f)\n", pos.X, pos.Y, pos.Z);
 
mat.buildRotateFromTo(dir, zdir);
mat.transformVect(pos);
printf("(%f,%f,%f)\n", pos.X, pos.Y, pos.Z);
Regards
smso
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

Re: Wrong thinking

Post by kevinsbro »

Thank you so much! I still don't understand why my code didn't work though. rotationToDirection takes the vector you want to rotate as a parameter. Shouldn't my code just be rotating it and the rotating it right back?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Wrong thinking

Post by smso »

Don't be misled by the function name "rotationToDirection". It really means "orientationToDirection" or "getDirectionVectorFromOrientation". The argument of "rotationToDirection" is the reference direction or heading of the scene node when

Code: Select all

node->getRotation().equals(core::vector3df(0.0f))
Also

Code: Select all

core::vector3df rot(67.0f, 90.0f, 50.0f);
does not represent operations on the scene node of :
first rotating it about xaxis by 67.0f deg,
then rotating it about yaxis by 90.0f deg,
...

Regards
smso
Post Reply