Sign in to follow this  
Zmurf

Dynamic Camera

Recommended Posts

I need to make a camera be able to automatically zoom/out and pan so that 2 players always remain in view no matter where they are in an arena style map. This type of camera motion is featured in most fighting style games. Anyone know how to do this? Or an algorithm to work out what points on the plane are in view so I could maybe do it myself?

Share this post


Link to post
Share on other sites
Hi,

You could test your players against your camera's frustum, so if someone is out of it or partially intersects it, zoom out your camera until your players complete fit on your camera frustum.

About the pan, mmm, I guess you couls point your camera at some point in the middle of your 2 players (fighting game right?), so as players moves,
pan the camera so it keeps aligned with your target point.

Hope that helps, regards
Oscar

[Edited by - ogracian on October 6, 2005 5:44:45 PM]

Share this post


Link to post
Share on other sites
The gluLookAt function could be useful for this. It has three vectors, position, up and at. The up should probably be 0,1,0. That at will be the midpoint between the two players positions. And the position will depend on the distance between the players. I think you could make a quick formula instead of using the view frustum, and it would be faster. You could say, the x is the same as the midpoint, the y as well, and the z uses the formula. Depending on your view, I think z might need to be a value like this(2 * PlayerDistance). Maybe less maybe more. Then if you keep the x in between them, then as players get farther separated, the z value goes farther back. This works quicker and easier than the view frustum.

Share this post


Link to post
Share on other sites
What is the midpoint formula for a 3D environment, I know the one for 2D. I think I could always have the camera look exactly in the middle of the 2, then zoom in and out depending on how far away they are form eachother. I'll have to read more in to camera frustrums and what-not.

Share this post


Link to post
Share on other sites
You can calculate the midpoint by taking average of player positions' x,y and z-coordinates and store the value in a new vector.


Vec3 vPlayer1;
Vec3 vPlayer2;

Vec3 vMidpoint;
vMidPoint.x = (vPlayer1.x + vPlayer2.x) / 2.0f;
vMidPoint.y = (vPlayer1.y + vPlayer2.y) / 2.0f;
vMidPoint.z = (vPlayer1.z + vPlayer2.z) / 2.0f;

Off course you have to take the zooming into account, this calculates only the players' midpoint.

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