Jump to content
  • Advertisement
Sign in to follow this  
Finalspace

Move side of a polygon

This topic is 1115 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 am building a level editor for my game and doing the implementation for resizing (moving of two vectors by a given delta) of polygons right now. Grabing the side of a polygon and moving the vertices along the given delta works already, so the only problem i have right now is to doing the repositioning so that the body center match the new local center.

 

How do i calculate the new body center and delta for offseting my local vertices?

 

See picture for better understanding:

 

resize%20delta.png

 

 

Share this post


Link to post
Share on other sites
Advertisement

The easiest way I can think of is the following:

 

First, compute the new vertex positions in global space (affected vertices + delta). After that just sum them up and divide by vertex count to obtain the center of mass (this is a nifty trick to compute the center of something). You can compute local vertex positions by <global vertex position> - <center of mass> (all this does is shift the center of mass to the origin, which is the local coordinate system in question).

The nice thing is that this works for an arbitrary number of vertices!

 

For rectangular regions you can calculate Lactose!'s solution analytically, but I don't think it's worth the hassle, unless you have want to see the math.

Share this post


Link to post
Share on other sites

Yeah it was delta / 2, first move the local vertices for the desired side by the full delta - than move back every local vertex by delta / 2 and then move the body position by delta / 2 too.

But the solution from duckflock i like much more, because it will preserve the center of mass - i will give it a try ;-)

 

Now it is getting more complex because i want to support scaling for non-rectangulary sides too, in this case you must scale the the other two sides connected too (based on the angle between).

 

And much more to come:

 

- Extruding

- Single vertex moving

Edited by Finalspace

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!