movement + 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
rk
Posts: 6
Joined: Mon Feb 08, 2010 9:42 pm

movement + rotation?

Post by rk »

Hello

I made a little project with a car moving around on a hill. The idea is to have the car angle adapt to the angle of the terrain. It was working great until I introduced the Z axis rotation. The rotation works and everything, but the car doesn't go forward anymore like it should.
I've been looking at the car->getRotation().Y and it seems to be going all crazy. When my car rotates the Y takes these values :

Image

I have no idea why :O, is there a way I can calculate the Y rotation like it use to be before the Z rotation was added? :
Image
rk
Posts: 6
Joined: Mon Feb 08, 2010 9:42 pm

Post by rk »

Just to avoid confusion, Y axis refers to this rotation :

Image
kiwibonga
Posts: 3
Joined: Sun Feb 14, 2010 3:25 am

Post by kiwibonga »

Can you show us your code and explain how you calculate the angle? Are there physics involved?
Viz_Fuerte
Posts: 91
Joined: Sun Oct 19, 2008 5:29 pm
Location: Valencia (Spain)
Contact:

Post by Viz_Fuerte »

I think I understood what you want make.

You want the vehicle to follow a specified address, forgetting the overall position.

For move:

Code: Select all

vector3df move(x,y,z);
matrix4 matrix;

matrix = car->getRelativeTransformation();
matrix.transformVect(move);
car->setPosition(move);
For turn:

Code: Select all

car->setRotation(vector3df(x,y,z) + car->getRotation());
With this code could achieve an effect of driving.

PD: For more realism, use any physics engine. :wink:
ericklima.comp
Posts: 9
Joined: Tue Jan 05, 2010 3:06 pm
Location: Brazil

Post by ericklima.comp »

Hello guys!
I'm having a very similar problem.
I'm trying to make my node movements this way
(Inspired by Resident Evil 4 Camera Style):

1 - Left and Right keys rotate my character node;
2 - Up and Down move my character node in the direction it's looking at.

My problem:

How am I suposed to get the direction
vector my character node is looking at?

I've tried some things, but I had no sucess. :cry:
Please, anyone help me... :wink:
Erick
mataanjin
Posts: 19
Joined: Tue May 25, 2010 3:07 am

Post by mataanjin »

ericklima.comp wrote:Hello guys!
I'm having a very similar problem.
I'm trying to make my node movements this way
(Inspired by Resident Evil 4 Camera Style):

1 - Left and Right keys rotate my character node;
2 - Up and Down move my character node in the direction it's looking at.

My problem:

How am I suposed to get the direction
vector my character node is looking at?

I've tried some things, but I had no sucess. :cry:
Please, anyone help me... :wink:
my trick is to have 2 bone that is align so it always face where the node facing.
when i want to get the direction i just get the absolute position of each bone and subtract it, then normalized the vector.
ericklima.comp
Posts: 9
Joined: Tue Jan 05, 2010 3:06 pm
Location: Brazil

Post by ericklima.comp »

Hello again! :D
I'll try something like that!
But i think I'm gonna use a dummy scene node.
If it works, I'll let you know!!!
One more question:
These scene nodes must be parent and child of each other?

Anyway,
Thanks a lot for answering, mataanjin!!! :D
Erick
mataanjin
Posts: 19
Joined: Tue May 25, 2010 3:07 am

Post by mataanjin »

ericklima.comp wrote:Hello again! :D
I'll try something like that!
But i think I'm gonna use a dummy scene node.
If it works, I'll let you know!!!
One more question:
These scene nodes must be parent and child of each other?

Anyway,
Thanks a lot for answering, mataanjin!!! :D
yes, it should, so the dir will always point to node direction
ericklima.comp
Posts: 9
Joined: Tue Jan 05, 2010 3:06 pm
Location: Brazil

Post by ericklima.comp »

Hello guys!!! Your support helped me a lot!!!

After my last post, I suceeded to code the camera the way wanted. \o/
I created the camera as a child of my character node.
Then I added a new Scene Node to get the direction.
So I used the FPSCamera as an example to make all the movement stuff.
For now, it's in my classes layout, but I'm thinking about
code an animator for it when I'm done with this project,
to help other people.


Special thanks to mataanjin!!! :D
Erick
Post Reply