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 ?
Functions for moving object relative to object space?
ISceneNode::
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
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)
Hope that helped with the matrix stuff
Gonosz
-
Guest
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.
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.