Sign in to follow this  

Finding the middle of an arbitrary shape

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

Howdy! Just recently I began the massive undertaking of changing thousands of lines of code for my game so that the number of players is now dynamic instead of fixed on 2. Now I've reached the final part: Updating the camera system so instead of tracking the middle point (2D) of the two players (easy) it has to track the middle point of a dynamic number of players (not so easy). There can be any number of players, though usually it'll be between 2 and say, 8. There is no guarentee. The shape that they can create can be non-convex also! I need to find their middle point and I have all their positions stored as x, y floats. Any ideas?

Share this post


Link to post
Share on other sites
If you need to see them all at once you need to find the minimum and maximum x and y values and adjust the camera to that (assuming your setup allows zooming). If you just average their positions some players may go out of camera range.

Share this post


Link to post
Share on other sites
http://kspark.kaist.ac.kr/Aesthetic%20Engineering.files/Area%20Centroid.htm

Something like that may help you. Treat all your players as vertexes on a polygon of some sort and then finds its geometric center as described in the link.

Mathworld has a way of doing it for "Point masses" so that maybe better, but that site always confuses the hell out of me.
http://mathworld.wolfram.com/GeometricCentroid.html

and yes, if you allow zooming, you may need to zoom out after panning the camera center on the centoid to make sure that players on the extents are visible. If you do not zoom, you will need to check their extents and shift over a bit from the centroid to get them on the screen.

Share this post


Link to post
Share on other sites

This topic is 4759 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.

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