Rough Orientation Situation

Started by
2 comments, last by hplus0603 19 years, 6 months ago
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]
Advertisement
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());Normalize(Move);


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]
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement