moving "forward" according to current rotation

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
Gav
Posts: 23
Joined: Fri Jul 16, 2004 12:28 pm

moving "forward" according to current rotation

Post by Gav »

basically i have a node that rotates when you press left/right and then want it to go forward/back when i press up/down, however I can't figure out how to move it forward/back relative to its current rotation.
:roll:
i have already searched thru the documentation and tried various ways but with no success... so remember this is the BEGINNERS forum and dont tell me I should be able to figure it out because I CAN'T!!! :roll:
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Forward is a vector, to go backward, subtract instead of add.

forward = vector3df(sin( Node->getRotation().Y*PI/180.0f ), 0, cos( Node->getRotation().Y*PI/180.0f ) );
Node->setPosition( Node->getPosition() + forward*10.0f ); //move forward 10 units
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Oz wrote:Ouch, too much math. ;)
Copy/Paste is too much math? :shock: It's already there for you :D
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

LOL

No I mean use matrix math. Matrices are your friend!
Thanks for your code, im sure it works great.
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

This is something I've been working on as 2 of my test projects needs some sort of GetOrientation() function.

I've been trying to read more on how to get a vector form of orientation, but everything out there gives a very simple quaternion method that doesn't involve vectors.

I could swear the answer is some form of Orientation =YawVector + PitchVector + RollVector;
Crud, how do I do this again?
Oz - Enraged

Post by Oz - Enraged »

Well you could try my matrix math, (the links above) if its not good enough then just dont use it. (At least I tried)

Bah! Im so mad at the moment!
Gav (at uni)

Post by Gav (at uni) »

matrices are not my friend they are my sworn enemy. .. Unfortunately they have to exist to some extent :cry:

i will try darkwhoppy's method when i get home and see how it goes...
eek! i've used 200% of my bandwidth at uni im gonna pay for this thru the nose at the end of semester... :?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

here is function for moving in 3d space (works in 2d too):
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3608
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Dang.. I searched the forums for 3 hours yesterday for that post. Read through a lot of code from a lot of people (you, Oz, jox, mm, etc...)

I made a demo just like your spaceship one in Ogre about 2 years ago using straight matrix math, but haven't used it since so the knowledge all leaked out.

jox gave me the same answer and I used yours to clean up the code.

Code: Select all

irr::core::vector3df dir = irr::core::vector3df(0.0f,0.0f,OffSet); //Offset = Speed * Time Factor; for smooth animation
irr::core::matrix4 rotMatrix;
rotMatrix.setRotationDegrees(node->getRotation());
rotMatrix.transformVect(dir);
node->setPosition(node->getPosition() + dir);
Seems like this should be a function in irr::scene::ISceneNode... like setPositionRelativetoSelf() but I bet there is a better word already in the 3D dictionary.
Crud, how do I do this again?
Post Reply