Jump to content
  • Advertisement
Sign in to follow this  

Rough Orientation Situation

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I may have just busted some brain cells trying, but I can't figure this out. Here is the situation: I have a movement direction vector [Move]: Zero(Move) if(KEYDOWN(UP)) Move.z += 1.0f; if(KEYDOWN(DOWN)) Move.z -= 1.0f; if(KEYDOWN(LEFT)) Move.x -= 1.0f; if(KEYDOWN(RIGHT)) Move.x += 1.0f; Normalize(Move); When the character animates, he uses the [Move] vector to blend his walking animations. So if [Move].z == 1.0, he will animate walking straight forward. If [Move].x is 0.5 and [Move].z is 0.5, he will walk forward-right. As he animates, his animation will push him in the directions relative to his facing direction. In other words, his movement is automatically relative to his direction. Does anyone have any clue how to make his movements relative to the camera now? In other words, I want key UP to move him away from the camera. I've tried this.. Move = (Move.x * CameraRight) + (Move.y * CameraUp) + (Move.z * CameraForward); Where CameraRight, CameraUp, and CameraForward are direction vectors for the camera rotations. Of course this won't work because the Move vector is already relative to his own direction. Move.z==1.0 does not represent world-forward, it represents his own facing forward. I have direction vectors for the 3 axes for all objects, and matrices for their rotations. So everything is at my disposal. To be more clear, I'm lost. I think I need to use the camera direction relative to the character facing direction to convert [Move]. But I'm not sure how to do it. Does anyone know how I can do this? Let me know if I explained something terribly. Thanks [smile]

Share this post

Link to post
Share on other sites
Ahh? No one wants to do all of my work for me? [smile]

I've come up with something that works. If my previous explanation of the situation sucked, maybe this will make it more clear. If I do this to [Move], it works..

MATRIX inv = InvertMatrix( GetCharacterRotationMatrix() );
TransformVector(&Move, &Move, &inv); // transform [Move] by [inv]
Move = (Move.x * Camera->GetRight()) + (Move.y * Camera->GetUp()) + (Move.z * Camera->GetForward());


I applied the inverse object rotation transform, then used the camera's directions as the base for the vector. Is this overkill? Is there a better way to do it?

Thanks for any help [smile]

Share this post

Link to post
Share on other sites
Your goal is to transform a vector in viewspace to your character's local space. Do it like this:

C = Camera orientation/position matrix
M = Character's orientation/position matrix

To transform a vector from your character's local space to world space:

v' = Mv

So, to tranform a vector from world space to your character's local space:

v' = M-1v

To transform a vector from view space to world space:

v' = Cv

To transform a vector from view space to world space and then from world space to your character's local space:

v' = M-1(Cv) = M-1Cv

Assuming Move is the movement vector in view space, you should do this:

1. Transform Move by C. Since Move is always a unit vector along one of the camera axes, you can instead simply assign the appropriate camera axis to Move.
2. Transform Move by M-1.

Share this post

Link to post
Share on other sites
Jiia: that's not overkill at all; that's how most games would do it (assuming they have the camera representation you do).

Rename "x" as "forward" and "z" as "right" and "y" as "up" in your Move struct if you want to be really clear.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!