• Advertisement
Sign in to follow this  

3rd Person camera

This topic is 3953 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

Does anyone have a good tutorial on 3rd person cameras for OpenGL? I guess DX would be fine to (just have to convert it). I have looked around the web and not really finding much. I would like to have the players car in front and down a bit, and have the camera follow the car and allow the car to turn a bit before the camera rotates... What I have now doesn't follow like that, and if the car turns the camera turns right away. I would also like the player to rotate the view to the left or right but allow the player to keep moving forward if they are pressing fwd key. This would allow a fake move your head to the left or right so the player can check out the view around them. Any help would be great. I can post my code for my camera if need be, if someone would like to modify it to show me how to get these results. Thanks

Share this post


Link to post
Share on other sites
Advertisement
This is basically a duplicate reply from an earlier thread that I posted in. The link to the demo code is still valid, and can be download here (.zip, 26Kb). Move the object around the environment using the cursor keys, 'Escape' to quit.

I hope that's what you're looking for, if you have any questions about the code (or other camera control methods), feel free to ask [smile].

Share this post


Link to post
Share on other sites
//initialize the camera right where you want it. then

vector3 vDirection = vCarPos - vCameraPos;//vCarPos is the position of your car

vDirection.Normalize(); // however you do it

vCamerPos = vCarPos + vDirection * 0.5f; //update the 0.5f with trial and error
vCameraPos.y = vCameraPos.y + 3.0f;


// to get the vLookAt vector
vector3 vLookAt;
vLookAt = vCarPos;
vLookAt.y = vLookAt.y + 1.5f; //update with trial and error


Try this and let me know if it works...

Share this post


Link to post
Share on other sites
u have a 3x3 matrix with which u orientate the person right, u may need the inverse of that

all u need to do is then

MATRIX33_VEC_MUL( offset, person_view_mat, VEC3(0,camera_height,camera_dist) );
offset += person_pos;

thats the position of the camera,
person_view_mat is the camera's rotation

u might wanna include some lag in the camera to smooth out the result ( i recently wrote one method in my blog)
another method is a simple lerp eg
pos * A + prev_pos * (1-A)
also with orientation

Share this post


Link to post
Share on other sites
Quote:
Original post by takingsometime
This is basically a duplicate reply from an earlier thread that I posted in. The link to the demo code is still valid, and can be download here (.zip, 26Kb). Move the object around the environment using the cursor keys, 'Escape' to quit.

I hope that's what you're looking for, if you have any questions about the code (or other camera control methods), feel free to ask [smile].


Thanks a million takingsometime. That worked out great after I got it implemented into the game. Exactly what I was looking for. Now the questions I have are the variables in the camera class. The azimuth, altitude what do they change...

I assume altitude is the height of the camera? the azimuth I am not 100% sure on. And distance I am guessing is how far behind the camera you are?

Thanks
Rating++

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Now the questions I have are the variables in the camera class. The azimuth, altitude what do they change...

I assume altitude is the height of the camera? the azimuth I am not 100% sure on. And distance I am guessing is how far behind the camera you are?

Thanks
Rating++


No problem, the best way to understand 3rd person cameras is to see the code in action.

The code is calculating the camera position using spherical coordinates. A sphere surrounds the target, with the target being the centre of the sphere. Basically, the altitude controls the height, but the camera position will always lie on a point of the sphere. The azimuth is the same, except it is the left/right angle to view the object. If you change the azimuth in the demo code to 270.0f, you will view the object from the side (still a point on the sphere). And yes, the distance defines how far from the target position the camera should be (the radius of the sphere).

Share this post


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

  • Advertisement