1 Replies - 915 Views - Last Post: 16 October 2013 - 09:45 AM Rate Topic: -----

#1 novakasss   User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 458
  • Joined: 11-July 12

Collision points.

Posted 16 October 2013 - 07:46 AM

I have read this article and I have one question. If I have oval shape, is there a better way to detect collision than using collsion points? Because oval shape can collide with all points that surrounds the actual shape. Or it would be OK to set only 8 points(up,down,left,right,left-up, left-down,right-up,right-down all 45 degrees)?

This post has been edited by novakasss: 16 October 2013 - 07:46 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Collision points.

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1509
  • View blog
  • Posts: 8,273
  • Joined: 07-September 06

Re: Collision points.

Posted 16 October 2013 - 09:45 AM

Well, and oval, as drawn on a computer, is really just a series of short lines with angles between each of them. That being said, and because ovals are convex shapes, you can take the center of mass (center of the shape) and keep that with the shape. Then you can check the bounding box for a collision with a point (basically draw a box around the oval and see if the point in question is inside that box or not; if not you aren't colliding with the object), and if you are colliding you run through all of the small lines (each vertex pair) and, using vector math and the cross product, you check to see if the center of mass and the point in question are on the same side of all of the lines. If they are then you have a collision. If any of the lines comes back false you don't have a collision.

Now, when working with sprites and pixel-art you can use points as they show for an oval, it just requires more points to get the curve approximately correct. As you can see in the article, they aren't going for pixel-perfect collisions, just close. It is also worth noting that they allow for concave and convex shapes to correctly approximate collisions through that method, whereas the above method only works for convex shapes.

Hopefully that makes some sense.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1