Difference between revisions of "Collision detection"

From JPCT
Jump to: navigation, search
(Ellipsoid-Polyong)
Line 24: Line 24:
 
Second, it's a swept algorithm, i.e. all collisions along the translation will be detected and the translation will be adjusted while this happens. Compared to the spherical approach, the corrected translation isn't really capable of resolving an existing intersection, but it's very good in avoiding it. With this collision detection method, it's pretty easy to let your character climb stairs, rocks etc...
 
Second, it's a swept algorithm, i.e. all collisions along the translation will be detected and the translation will be adjusted while this happens. Compared to the spherical approach, the corrected translation isn't really capable of resolving an existing intersection, but it's very good in avoiding it. With this collision detection method, it's pretty easy to let your character climb stairs, rocks etc...
 
One drawback: This is the slowest approach of all three.
 
One drawback: This is the slowest approach of all three.
 +
  
 
==== Other methods ====
 
==== Other methods ====
  
 
There are no other methods build into jPCT, but you can always use a [[ Physics ]] engine of your choice instead of the build in methods.
 
There are no other methods build into jPCT, but you can always use a [[ Physics ]] engine of your choice instead of the build in methods.

Revision as of 21:42, 6 June 2009

Collision detection

jPCT has basically three different methods for collision detection. Depending on the application and its requirements, one may be more suitable than the other. This section provides a brief overview. To use any kind of collision detection, the collision mode has to be set correctly. An Object3D can either receive collisions from other objects/entities, cause collisions or both (or nothing). Collision detection on complex models largely benefits from using octrees.


Ray-Polygon

Methods using this approach usually are named checkXXXCollision(...). The idea of this collision test is simple: A ray will be casted into the scene and the closest polygon in its way will block it. There another method that works very similar to this in World: calcMinDistance. Its basically the same stuff, but it returns the actual distance to the hit polygon which the other checkXXXCollision-methods won't. This method is fine for detecting bullet hits, for placing a car's wheel on the ground (the car-example is using it for example) and similar.


Sphere-Polygon

Methods using this approach usually are named checkXXXCollisionSpherical(...). Here, a sphere is queried if some other object intersects with it. If this is the case, the translation vector will be adjusted, so that the collision won't happen (if you actually apply the corrected vector, of course you don't have to). This isn't a swept approach, i.e. for a given translation vector, two tests happen: One at the start of the translation and one at the end. If the translation is too large for and/or the sphere's radius too small to make these tests cover the whole translation, any collision in between won't be recognized. This method is great for resolving collisions, i.e. if some object already is in a collision, this method can help to pull it out of it. Personally, i'm using this method to compensate for accuracy problems of the other methods, i.e. if they cause an intersection where they should actually avoid it, i'm using method to resolve it. I don't recomment to use this method for a FPS game or similar.


Ellipsoid-Polygon

This is the most powerful collision detection approach in jPCT. Methods using it are usually named checkXXXCollisionEllipsoid(...). It's similar to the spherical approach, but it has some advantages. At first, it's using an ellipsoid, not a sphere. That means, that it's easier to approximate human-like objects for example with it than it would be with sphere. However, you can always use a sphere as your ellipsoid. Second, it's a swept algorithm, i.e. all collisions along the translation will be detected and the translation will be adjusted while this happens. Compared to the spherical approach, the corrected translation isn't really capable of resolving an existing intersection, but it's very good in avoiding it. With this collision detection method, it's pretty easy to let your character climb stairs, rocks etc... One drawback: This is the slowest approach of all three.


Other methods

There are no other methods build into jPCT, but you can always use a Physics engine of your choice instead of the build in methods.