Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

Dynamic Camera

This topic is 4667 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 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
Advertisement
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
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!