![]() |
naev 0.11.5
|
Deals with 2d collisions. More...
Go to the source code of this file.
Macros | |
| #define | FX(A, B, C, x) |
| #define | FY(A, B, C, y) |
Functions | |
| static int | PointInPolygon (const CollPoly *at, const vec2 *ap, float x, float y) |
| Checks whether or not a point is inside a polygon. | |
| static int | LineOnPolygon (const CollPoly *at, const vec2 *ap, float x1, float y1, float x2, float y2, vec2 *crash) |
| Checks whether or not a line intersects a polygon. | |
| void | LoadPolygon (CollPoly *polygon, xmlNodePtr node) |
| Loads a polygon from an xml node. | |
| void | FreePolygon (CollPoly *polygon) |
| int | CollideSprite (const glTexture *at, const int asx, const int asy, const vec2 *ap, const glTexture *bt, const int bsx, const int bsy, const vec2 *bp, vec2 *crash) |
| Checks whether or not two sprites collide. | |
| int | CollideSpritePolygon (const CollPoly *at, const vec2 *ap, const glTexture *bt, const int bsx, const int bsy, const vec2 *bp, vec2 *crash) |
| Checks whether or not a sprite collides with a polygon. | |
| int | CollidePolygon (const CollPoly *at, const vec2 *ap, const CollPoly *bt, const vec2 *bp, vec2 *crash) |
| Checks whether or not two polygons collide. /!\ The function is not symmetric: the points of polygon 2 are tested against the polygon 1. Consequently, it works better if polygon 2 is small. | |
| void | RotatePolygon (CollPoly *rpolygon, CollPoly *ipolygon, float theta) |
| Rotates a polygon. | |
| int | CollideLineLine (double s1x, double s1y, double e1x, double e1y, double s2x, double s2y, double e2x, double e2y, vec2 *crash) |
| Checks to see if two lines collide. | |
| int | CollideLineSprite (const vec2 *ap, double ad, double al, const glTexture *bt, const int bsx, const int bsy, const vec2 *bp, vec2 crash[2]) |
| Checks to see if a line collides with a sprite. | |
| int | CollideLinePolygon (const vec2 *ap, double ad, double al, const CollPoly *bt, const vec2 *bp, vec2 crash[2]) |
| Checks to see if a line collides with a polygon. | |
| int | CollideCirclePolygon (const vec2 *ap, double ar, const CollPoly *bt, const vec2 *bp, vec2 crash[2]) |
| Checks to see if a circle collides with a polygon. | |
| int | CollideCircleSprite (const vec2 *ap, double ar, const glTexture *bt, const int bsx, const int bsy, const vec2 *bp, vec2 *crash) |
| Checks whether or not a sprite collides with a polygon. | |
| static int | linePointOnSegment (double d1, double x1, double y1, double x2, double y2, double x, double y) |
| int | CollideLineCircle (const vec2 *p1, const vec2 *p2, const vec2 *cc, double cr, vec2 crash[2]) |
| Checks to see if a line collides with a circle. | |
| int | CollideCircleCircle (const vec2 *p1, double r1, const vec2 *p2, double r2, vec2 crash[2]) |
| Computes the collision between two circles. | |
| double | CollideCircleIntersection (const vec2 *p1, double r1, const vec2 *p2, double r2) |
| Calculates the area of intersection between two circles. | |
Deals with 2d collisions.
Definition in file collision.c.
| #define FX | ( | A, | |
| B, | |||
| C, | |||
| x ) |
Definition at line 940 of file collision.c.
| #define FY | ( | A, | |
| B, | |||
| C, | |||
| y ) |
Definition at line 941 of file collision.c.
Computes the collision between two circles.
Definition at line 1054 of file collision.c.
Calculates the area of intersection between two circles.
Definition at line 1071 of file collision.c.
| int CollideCirclePolygon | ( | const vec2 * | ap, |
| double | ar, | ||
| const CollPoly * | bt, | ||
| const vec2 * | bp, | ||
| vec2 | crash[2] ) |
Checks to see if a circle collides with a polygon.
First collisions are detected on all the walls of the polygon's rectangle. Then the collisions are tested on every line of the polygon.
| [in] | ap | Origin of the circle. |
| [in] | ar | Radius of the circle. |
| [in] | bt | Polygon b. |
| [in] | bp | Position in space of polygon b. |
| [out] | crash | Position of the collision. |
Definition at line 790 of file collision.c.
| int CollideCircleSprite | ( | const vec2 * | ap, |
| double | ar, | ||
| const glTexture * | bt, | ||
| const int | bsx, | ||
| const int | bsy, | ||
| const vec2 * | bp, | ||
| vec2 * | crash ) |
Checks whether or not a sprite collides with a polygon.
| [in] | ap | Position in space of circle a. |
| [in] | ar | Radius of circle a. |
| [in] | bt | Texture b. |
| [in] | bsx | Position of x of sprite b. |
| [in] | bsy | Position of y of sprite b. |
| [in] | bp | Position in space of sprite b. |
| [out] | crash | Actual position of the collision (only set on collision). |
Definition at line 868 of file collision.c.
| int CollideLineCircle | ( | const vec2 * | p1, |
| const vec2 * | p2, | ||
| const vec2 * | cc, | ||
| double | cr, | ||
| vec2 | crash[2] ) |
Checks to see if a line collides with a circle.
| [in] | p1 | Point 1 of the line segment. |
| [in] | p2 | Point 2 of the line segment. |
| [in] | cc | Center of the circle. |
| [in] | cr | Radius of the circle. |
| [out] | crash | Position of the collision. |
Definition at line 952 of file collision.c.
| int CollideLineLine | ( | double | s1x, |
| double | s1y, | ||
| double | e1x, | ||
| double | e1y, | ||
| double | s2x, | ||
| double | s2y, | ||
| double | e2x, | ||
| double | e2y, | ||
| vec2 * | crash ) |
Checks to see if two lines collide.
| [in] | s1x | X start point of line 1. |
| [in] | s1y | Y start point of line 1. |
| [in] | e1x | X end point of line 1. |
| [in] | e1y | Y end point of line 1. |
| [in] | s2x | X start point of line 2. |
| [in] | s2y | Y start point of line 2. |
| [in] | e2x | X end point of line 2. |
| [in] | e2y | Y end point of line 2. |
| [out] | crash | Position of the collision. |
Definition at line 455 of file collision.c.
| int CollideLinePolygon | ( | const vec2 * | ap, |
| double | ad, | ||
| double | al, | ||
| const CollPoly * | bt, | ||
| const vec2 * | bp, | ||
| vec2 | crash[2] ) |
Checks to see if a line collides with a polygon.
First collisions are detected on all the walls of the polygon's rectangle. Then the collisions are tested on every line of the polygon.
| [in] | ap | Origin of the line. |
| [in] | ad | Direction of the line. |
| [in] | al | Length of the line. |
| [in] | bt | Polygon b. |
| [in] | bp | Position in space of polygon b. |
| [out] | crash | Position of the collision. |
Definition at line 657 of file collision.c.
| int CollideLineSprite | ( | const vec2 * | ap, |
| double | ad, | ||
| double | al, | ||
| const glTexture * | bt, | ||
| const int | bsx, | ||
| const int | bsy, | ||
| const vec2 * | bp, | ||
| vec2 | crash[2] ) |
Checks to see if a line collides with a sprite.
First collisions are detected on all the walls of the sprite's rectangle. Then the collisions are tested by pixel perfectness until collisions are actually found with the ship itself.
| [in] | ap | Origin of the line. |
| [in] | ad | Direction of the line. |
| [in] | al | Length of the line. |
| [in] | bt | Texture b. |
| [in] | bsx | Position of x of sprite b. |
| [in] | bsy | Position of y of sprite b. |
| [in] | bp | Position in space of sprite b. |
| [out] | crash | Position of the collision. |
Definition at line 508 of file collision.c.
| int CollidePolygon | ( | const CollPoly * | at, |
| const vec2 * | ap, | ||
| const CollPoly * | bt, | ||
| const vec2 * | bp, | ||
| vec2 * | crash ) |
Checks whether or not two polygons collide. /!\ The function is not symmetric: the points of polygon 2 are tested against the polygon 1. Consequently, it works better if polygon 2 is small.
| [in] | at | Polygon a. |
| [in] | ap | Position in space of polygon a. |
| [in] | bt | Polygon b. |
| [in] | bp | Position in space of polygon b. |
| [out] | crash | Actual position of the collision (only set on collision). |
Definition at line 260 of file collision.c.
| int CollideSprite | ( | const glTexture * | at, |
| const int | asx, | ||
| const int | asy, | ||
| const vec2 * | ap, | ||
| const glTexture * | bt, | ||
| const int | bsx, | ||
| const int | bsy, | ||
| const vec2 * | bp, | ||
| vec2 * | crash ) |
Checks whether or not two sprites collide.
This function does pixel perfect checks. If the collision actually occurs, crash is set to store the real position of the collision.
| [in] | at | Texture a. |
| [in] | asx | Position of x of sprite a. |
| [in] | asy | Position of y of sprite a. |
| [in] | ap | Position in space of sprite a. |
| [in] | bt | Texture b. |
| [in] | bsx | Position of x of sprite b. |
| [in] | bsy | Position of y of sprite b. |
| [in] | bp | Position in space of sprite b. |
| [out] | crash | Actual position of the collision (only set on collision). |
Definition at line 103 of file collision.c.
| int CollideSpritePolygon | ( | const CollPoly * | at, |
| const vec2 * | ap, | ||
| const glTexture * | bt, | ||
| const int | bsx, | ||
| const int | bsy, | ||
| const vec2 * | bp, | ||
| vec2 * | crash ) |
Checks whether or not a sprite collides with a polygon.
| [in] | at | Polygon a. |
| [in] | ap | Position in space of polygon a. |
| [in] | bt | Texture b. |
| [in] | bsx | Position of x of sprite b. |
| [in] | bsy | Position of y of sprite b. |
| [in] | bp | Position in space of sprite b. |
| [out] | crash | Actual position of the collision (only set on collision). |
Definition at line 185 of file collision.c.
| void FreePolygon | ( | CollPoly * | polygon | ) |
Definition at line 80 of file collision.c.
|
static |
Checks whether or not a line intersects a polygon.
| [in] | at | Polygon a. |
| [in] | ap | Position in space of polygon a. |
| [in] | x1 | Coordiante of point 1. |
| [in] | y1 | Coordinate of point 1. |
| [in] | x2 | Coordiante of point 2. |
| [in] | y2 | Coordinate of point 2. |
| [out] | crash | coordinates of the intersection. |
Definition at line 415 of file collision.c.
|
static |
Definition at line 932 of file collision.c.
| void LoadPolygon | ( | CollPoly * | polygon, |
| xmlNodePtr | node ) |
Loads a polygon from an xml node.
| [out] | polygon | Polygon. |
| [in] | node | xml node. |
Definition at line 35 of file collision.c.
Checks whether or not a point is inside a polygon.
| [in] | at | Polygon a. |
| [in] | ap | Position in space of polygon a. |
| [in] | x | Coordiante of point. |
| [in] | y | Coordinate of point. |
Definition at line 369 of file collision.c.
Rotates a polygon.
| [out] | rpolygon | Rotated polygon. |
| [in] | ipolygon | Imput polygon. |
| [in] | theta | Rotation angle (radian). |
Definition at line 332 of file collision.c.