Functions for moving object relative to object space?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
exal
Posts: 60
Joined: Tue Feb 24, 2004 9:05 am

Functions for moving object relative to object space?

Post by exal »

Hi

I am looking for a way to move my object in Z according to the rotation of the object I have. But there is seems to be no way for me to get the matrix of the object if I don't inherit the SceneNode.

Asuming I have rotated the object around Y 45 degrees moving it forward in Z would move it in and right. how do I do that ?
Gonosz
Posts: 24
Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)

Post by Gonosz »

ISceneNode::

Code: Select all

virtual core::matrix4  getRelativeTransformation () const 
core::matrix4 &  getAbsoluteTransformation () 
virtual void  setPosition (const core::vector3df &newpos) 
virtual void  setRotation (const core::vector3df &rotation) 
virtual void  setScale (const core::vector3df &scale) 
The three set methods update the relative transformations of the object. Note that getAbsoluteTransformation returns a reference to the matrix, so you can change it, however, getRelativeTransformation does not, because the relative transform's are stored separately as a pos/rot/scale triple, as the manual says.

Hope that helped with the matrix stuff :)

Gonosz
Guest

Post by Guest »

Hmm still can't figure out how to move the object in the direction it's facing. can someone tell me the match or function usage for that? Right now the object is just moving along the world space axis.
exal
Posts: 60
Joined: Tue Feb 24, 2004 9:05 am

Post by exal »

Ok finally got it to work. So I want to give the code to all you novices like.
This will move the object in worldspace according to the rotation of the object in it's own space.

core::matrix4 m = node.getRelativeTransformation();
core::vector3df v;

//Note that it doesn't compensate for the speed of the computer
//Move along objects Z
v.X = m.M[8] * 0.01f;
v.Y = m.M[9] * 0.01f;
v.Z = m.M[10] * 0.01f;

//Add to last position
m.M[12] = v.X + m.M[12];
m.M[13] = v.Y + m.M[13];
m.M[14] = v.Z + m.M[14];

//Set the new position
node.setPosition(core::vector3df(m.M[12], m.M[13], m.M[14]));

//This code is written from my head. I hope it's correct.
Post Reply