Jump to content
  • Advertisement
Sign in to follow this  
ToohrVyk

[API] Collision API proposition

This topic is 4617 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 currently considering developing a collision detection system. I seek critics about its structure and layout, as well as usability in situations from your experience. My constraints for the API (due to the structure of my game) are: - The positions of objects are described to the collision system in terms of initial position and velocity, and duration1. - From there, the collision system determines (and makes available) a no-change duration: it is the longest duration (starting with the current time) during which no collision happens. - The collision system can be asked to compute all collisions that occur between the current time and an arbitrary time in the future. Therefore, my suggestion for an API is: Classes manager: the collision manager represents the core of the collision system. It integrates all the above functionality. group: a collision group represents a set of objects (such as "player bullets", "enemies", "player"). Instead of setting up manually which object can collide with which, and what the effects should be, collisions are configured on a group-group basis. hull: represents the volume occupied by an object. Object hull : hull class This class is implemented by several derived classes (sphere, AABB, OBB, convex polyhedron). The position( ) of a hull is determined by its initial_position and its velocity, as well as its start_time and end_time. All these properties are read-only (and set up at construction time). They may be changed with a change_movement( ) function : changes the velocity and end time(using the current value as the new start_time value, and the current position as the new initial_position). Collision groups : group class Each group is managed by a given manager (the owner), which is a read-only property of the group that is set upon creation of said group. Each group performs hull-controller associations, where hull is an object of type hull and controller is an arbitrary object (the type of which is a parameter of the group class) that responds to collisions involving its associated hull. Collision manager : manager class The manager monitors collisions between associated groups. Such an association can be created using a detect function, which takes as arguments two groups (the ownerof which is the current manager) and a callback binary function reaction( ). When a collision is detected between an object a of group A and b of group B, then the callback function that was passed to manage the collision between A and B is called with A[a] and B as its arguments - where A[a] is a notation for the controller associated to a in group A. The manager also has the obvious nochangeduration( ) property, and the advance( nexttime ) function which computes all collisions until the specified time. Practical example : bouncing balls inside screen. I assume here that "bounce" is a physics function : a collision is detected between two hulls, it alters their movement based on their masses, velocities and relative positions.
// init
manager = new manager 
balls = new group
screen = new group

repeat 10 times
  sphere = new sphereHull (random position, radius, velocity)
  // also set up the sphere for rendering
  add the sphere-(sphere,mass=random) association to balls

rect = new screenHull
add the rect-(rect,mass=infinity) association to screen

make manager detect (balls,balls,bounce)
make manager detect (balls,screen,bounce)

// run

as often as possible:
  render

every 15 milliseconds:
  make manager advance (15 milliseconds)
1: All durations and moments are described in arbitrary in-game time units. In-game time flow is independent from real-world time flow.

Share this post


Link to post
Share on other sites
Advertisement
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!