How to get direction vector

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
siny
Posts: 10
Joined: Fri Apr 20, 2007 11:59 am

How to get direction vector

Post by siny »

Hi.

I have this situation:

Image

and I dont know how to get direction vector (marked on red). I need it to show Newton dynamics the direction in which the cannonball will fly.

Thanks for help
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Should be sceneNode.getRotation(), maybe needs to be normalized. If you have a parent scene node attached to it you have to get the AbsoluteTransformation.getRotation() which is in Euler angles, though.
vi-wer
Posts: 93
Joined: Sun May 20, 2007 7:15 pm
Location: Germany
Contact:

Post by vi-wer »

I had the same problem with a character model.

I've created a frontDirection vector that shows the initial rotation and rotated it with the SceneNode.

If the getRotation() method doesn't work you could try this:
Create an empty SceneNode. Set position as initial direction (direction of your meshSceneNode):

Code: Select all

x=1,y=0,z=0 => direction vector showing along +X-axis.
Set that empty node as child of your meshSceneNode. If the meshSceneNode is rotated, the empty node is rotated too.

You can get the direction vector like this:

Code: Select all

vector3df dir = emptyNode->getAbsolutePosition() - meshNode->getAbsolutPosition();
dir.normalize();
not sure if it works.
siny
Posts: 10
Joined: Fri Apr 20, 2007 11:59 am

Post by siny »

Thanks. that idea with empty node works perfectly.
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

Post by TheGameMaker »

uhm.. why simple if its possible to do it the hard way??

Code: Select all


vector3df dir(1,0,0);
node->getAbsoluteTransformation().rotateVect(dir);
(dunno if everything is spelled correct.. so if it doesn´t work, just havge a look for the correct spelling).
Post Reply