home *** CD-ROM | disk | FTP | other *** search
-
- #import <gamekit/gamekit.h>
-
- // These are the shape tags used to tell the collision machinery what
- // methods to call in order to verify a collision between two objects.
- // You can add your own types, but you MUST use prime numbers for the
- // new tags! (Note that the hash table must be loaded with a proper
- // collision method for each combo...for example the collision method
- // for a triangle and rectangle has a hash tag of GK_RECTANGLE_SHAPE
- // multiplied by GK_TRIANGLE_SHAPE == 10, so the hash table's slot #10
- // has the info on how to intersect a rectangle and triangle.)
- #define GK_RECTANGLE_SHAPE 2
- #define GK_CIRCLE_SHAPE 3
- #define GK_TRIANGLE_SHAPE 5
- #define GK_COMPOSITE_SHAPE 7
-
- BOOL GKPointAboveLine(NXPoint *point, NXPoint *start, NXPoint *end);
- BOOL GKPointsOnSameSideOfLine(NXPoint *point1, NXPoint *point2, NXPoint *start, NXPoint *end);
- extern double GKDistanceBetweenPoints(NXPoint *point1, NXPoint *point2);
- extern double GKSegmentAngle(NXPoint *point1, NXPoint *point2);
- extern BOOL GKOuterLineSegmentIntersectsRect(NXPoint *point1, NXPoint *point2, NXRect *rect);
- extern BOOL GKPointInTriangle(NXPoint *point, GKTriangle *tri);
-
- @interface GKCollider:Object
- {
- id collisionHash; // a HashTable used to hold collision methods
- }
-
- + new; // returns the global GKCollider -- NEVER use alloc/init!!!
- - buildHashTable; // does set up, called by new as needed;
- // override to add new shapes and then add detection methods as below...
-
- // This is the only method an external object needs to call
- - (BOOL)object:actor1 collidesWith:actor2;
-
- // built-in collision detection methods
- // Note that the arg with the lower tag MUST come first!!!
- - (int)rect:(NXRect *)rect1 intersectsRect:(NXRect *)rect2;
- - (int)rect:(NXRect *)rect intersectsCircle:(GKCircle *)circ;
- - (int)rect:(NXRect *)rect intersectsTriangle:(GKTriangle *)tri;
- - (int)rect:(NXRect *)rect intersectsComposite:comp;
- - (int)circle:(GKCircle *)circ1 intersectsCircle:(GKCircle *)circ2;
- - (int)circle:(GKCircle *)circ intersectsTriangle:(GKTriangle *)tri;
- - (int)circle:(GKCircle *)circ intersectsComposite:comp;
- - (int)triangle:(GKTriangle *)tri1 intersectsTriangle:(GKTriangle *)tri2;
- - (int)triangle:(GKTriangle *)tri intersectsComposite:comp;
- - (int)composite:(GKTriangle *)comp1 intersectsComposite:comp2;
-
- @end
-