Public Group

2D Collision Detection Implementation Design Questions

This topic is 2619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm working on code my own collision detection code from scratch (mainly as a learning exercise, might use it in a game if I like the end result).

I'm planning on using points, lines, circles, AABB's (for fast boundary box testing) and convex polygons. With the exception of the AABB rects (and circles ) everything will support rotation. Complex objects will be represented as a list of different parts.

I'm fairly happy with the checking for collision between 2 of these shapes (using seperating axis theorm for the polygons, and simple stuff like distance for circle-circle/point) however I'm not sure on the best way to get this data. At present each shape uses a simple struct, e.g.:
[source lang="cpp"]
struct Circle : public Shape
{
Vector2F centre;
float r;
};
struct Polygon : public Shape
{
unsigned count;
Vector2F *p;
};
...
struct Hull
{
unsigned count;
Shape *parts;
RectF bbox;//essentailyl a square, since needs to be large enough for all rotations
};
...
bool test(Circle a,Circle b)
return distance(a,b) < a.r + b.r
bool test(Circle,Point)
bool test(Hull,Hull)
[/source]

This is fine if the objects never move, but since that doesnt happen, the issue is taking a Hull, and applying a rotation and translation to it to get all the shapes into world coordinates (or at least right relativeto the other object). The two options Ive come up with are:

1) The test etc methods take a position and rotation for each of the two objects, and transform the shapes vertices on the fly. The downside to this is that in a given frame, many vertices get transformed many times. Also rotating vertices each require a fair bit of trig or matrix multiplication, which seems expensive.
2) When an object instance is created, it gets its own copy of its Hull. Each time it moves it then updates the vertices using the origenal hull as a template. Doesnt seem to solve the expensive transform issue though.

Is there a better way to store the collision data, or to use the data during detection and response?

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• Forum Statistics

• Total Topics
633674
• Total Posts
3013277
×