Sign in to follow this  
mxb

Camera + Player Direction Problem

Recommended Posts

mxb    100
Hi gamedev friends, I'm new to 3D game development, so far loving it. Now, got a problem keeping Player's face direction in the same direction as I move... Starting point is fine, but when the camera is turned using Mouse player is facing in different ways while moving. I'm using CCamera, the loaded player's x,z are set to "Camera.mView.x" and "Camera.mView.z" to keep the player in the middle of camera. Currently the rotation of player's Y takes place manually when moving VK_ arrow buttons (0, 90, 180, 270). I want to be able to update player's facing direction automatically to face where camera is currently looking when Arrow keys are used. I've searched to fix this issue past 2-3 days without giving up, but no luck because non of those ideas/logics work with mine.. so I decided to post it here. I'd really appreciate if you cud give me a hand on this one. Thanks in advance!

Share this post


Link to post
Share on other sites
szecs    2990
I didn't understand you clearly, but if you want to rotate the camera with the head, you have to know that in openGL the objects are transformed not the camera:

So you have to apply the inverse matrix of the camera matrix.

Simply put: to rotate the camera right, you have to turn the 'world' left instead.

Or try using gluLookAt

I hope that helps.

Share this post


Link to post
Share on other sites
mxb    100
thanks for the reply szecs.

Ok, I'm able to rotate the camera right or left (360*) by counting the angle from the mouse x,z.

//from the CCamera class used in Mouse_Move function..
Rotate_Position(-angle_y);

Yes, I'm using gluLookAt function.

//camera control
gluLookAt(CCamera.mPos.x, CCamera.mPos.y, CCamera.mPos.z,
CCamera.mView.x, CCamera.mView.y, CCamera.mView.z,
CCamera.mUp.x, CCamera.mUp.y, CCamera.mUp.z);


However, I want to know how to turn my loaded model's face automatically where the camera is looking at when keyboard arrow buttons are pressed.

I wonder how to calculate the camera's view to apply that to player's view, for example: when the camera is turned to North, and when the Arrow key (VK_UP) is pressed Player shouldn't be looking at South or West. He should turn from Old_Pos to New_Pos and look at the direction of where Camera is facing.

You said I have to apply the inverse matrix of the camera matrix. How to do that? :\

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this