Page 1 of 1

movement + rotation?

Posted: Sat Feb 13, 2010 4:59 pm
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

Posted: Sat Feb 13, 2010 5:16 pm
by rk
Just to avoid confusion, Y axis refers to this rotation :

Image

Posted: Sun Feb 14, 2010 4:18 pm
by kiwibonga
Can you show us your code and explain how you calculate the angle? Are there physics involved?

Posted: Sun Feb 14, 2010 6:50 pm
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:

Posted: Sun Jun 13, 2010 2:56 pm
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:

Posted: Mon Jun 14, 2010 7:40 am
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.

Posted: Mon Jun 14, 2010 1:08 pm
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

Posted: Tue Jun 15, 2010 1:17 am
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

Posted: Mon Jun 28, 2010 8:59 pm
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