about math and forward movements

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
Warren
Posts: 60
Joined: Fri Jul 07, 2006 11:41 pm
Location: Santiago De Compostela, Spain

about math and forward movements

Post by Warren »

hi there,

I was taking a look to this code snipet by Nick_Japan
http://irrlicht.sourceforge.net/phpBB2/ ... t=rotation.

i find it perfect to implement a node movement based just on the XZ coordinates. But trying to make a rocket launch from a weapon i would like to care about the Y coordinate to get not just a horizontal movement.
So i Thought that the Y increase is expressed by the sine of the angle on the X axis, just like that:

Code: Select all

float factX= sin( radianes(p->Node->getRotation().Y) );
float factZ= cos( radianes(p->Node->getRotation().Y) );

float factY= sin( radianes(p->Node->getRotation().X) );

float speed= 1; //scalar factor for the speed

Node->setPosition( vector3df(Node->getPosition().X+ factX*speed,
                                        Node->getPosition().Y- factY*speed,
                                        Node->getPosition().Z+ factZ*speed) );
the result is not the correct, first of all, i have to decrease the factY instead of increase like X and Z factors to set the Node to follow the correct direction but not the exact angle.
Maybe i have to do some better stuff, maybe have to play with matrix or quaternions???

i will thanks every help
thx in advance
------------------------------------------------
Irrlicht Ussers Map
Join now!!
http://www.frappr.com/irrlichtusers
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

To make a node move 'forwards' you can use matrix calculations. First off you define which axis is 'forward' for your node, depends on how the model is aligned basically so trial and error comes in here. It's most likely to be +/- on one of the 3 axes.

So let's say +Z is forward so we have our direction vector:

core::vector3df dir(0,0,1);

then we grab our node's transformation matrix:

core::matrix4 mat = node->getAbsoluteTransformation();

then we use that matrix to transform our direction vector so it now points in the same direction as the node is facing.

mat.rotateVect(dir);

Et voila, job done! You can now use that dir vector to move the node in its current direction like so:

node->setPosition(node->getPosition() + dir);
Image Image Image
Warren
Posts: 60
Joined: Fri Jul 07, 2006 11:41 pm
Location: Santiago De Compostela, Spain

Post by Warren »

so, in my case, the direction vector could be calculated as i do from the Node align, for example:

Code: Select all

Node->setRotation(45,90,45);

vector3df dir= vector3df( sin( radianes(Node->getRotation().Y)) 
                            , sin( radianes(Node->getRotation().X))
                            , cos( radianes(Node->getRotation().Y)) );

that previous line would set dir( 1, 0.7, 0) ???
and then i could do the rest of the stuff???

I just trying!!!
i will notice!

Thnx!!!!!!!!!!!!
------------------------------------------------
Irrlicht Ussers Map
Join now!!
http://www.frappr.com/irrlichtusers
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

No you don't calculate the direction yourself, it's dependent on your model you're using really...

A node doesn't have a direction it's facing at all, it has no idea of direction so you have to basically choose which direction is 'forwards' for it. So if your node is a rocket, created from a mesh then you look at the mesh and say my mesh is facing along the positive Z axis so my direction is 0,0,1. Try using 0,0,1 as your direction and see if your rocket flies in the direction which it should appear to, i.e. the node of the rocket should fly forward.
Image Image Image
Warren
Posts: 60
Joined: Fri Jul 07, 2006 11:41 pm
Location: Santiago De Compostela, Spain

Post by Warren »

ouuo It works!!!!
thx JP,
So, mat.rotateVect(dir) aplyies the transformation to this direction vector and then you just have to add to this position the new facing coordinates as a scalar.

Thnx !!!
------------------------------------------------
Irrlicht Ussers Map
Join now!!
http://www.frappr.com/irrlichtusers
Post Reply