User:Monster Iestyn/Source Code Documentation/m_bbox.h
Appearance
Online link | GitHub entry |
---|---|
File type | C header file |
#include guard | __M_BBOX__
|
This header file contains prototypes for utility functions to be used with "bounding boxes" (fixed_t
arrays with 4 elements).
Includes
Bounding box coordinates
These values correspond with the four elements of a bounding box array; each of these four elements stores an X or Y coordinate of one of the box's edges.
Data type | enum
|
---|
Value | Name | Description |
---|---|---|
0 | BOXTOP
|
The Y coordinate of the bounding box's top edge |
1 | BOXBOTTOM
|
The Y coordinate of the bounding box's bottom edge |
2 | BOXLEFT
|
The X coordinate of the bounding box's left edge |
3 | BOXRIGHT
|
The X coordinate of the bounding box's right edge |
Example usage:
fixed_t bbox[4];
bbox[BOXTOP] = bbox[BOXRIGHT] = FRACUNIT;
bbox[BOXBOTTOM] = bbox[BOXLEFT] = -FRACUNIT;
/* Result:
2 FU x 2 FU bounding box {FRACUNIT, -FRACUNIT, -FRACUNIT, FRACUNIT}
BOXTOP
-----------------
| | |
| | |
| | |
| | |
BOXLEFT --------0-------- BOXRIGHT
| | |
| | |
| | |
| | |
-----------------
BOXBOTTOM
*/
Function prototypes
Function name | Return type | Params | Defined in | Description |
---|---|---|---|---|
M_ClearBox
|
void | fixed_t *box
|
m_bbox.c
|
"Clears" the bounding box (top and right are set to INT32_MIN , bottom and left are set to INT32_MAX ).
|
M_AddToBox
|
void | fixed_t *box ,fixed_t x ,fixed_t y
|
m_bbox.c
|
Adds to the bounding box – if (x ,y ) is a point outside the bounding box, extend the nearest vertical and/or horizontal edges to this point. If the point is completely inside the box, no changes will be made.
|
M_PointInBox
|
boolean | fixed_t *box ,fixed_t x ,fixed_t y
|
m_bbox.c
|
Returns true if point (x ,y ) is inside the bounding box; returns false otherwise.
|
M_CircleTouchBox
|
boolean | fixed_t *box ,fixed_t circlex ,fixed_t circley ,fixed_t circleradius
|
m_bbox.c
|
Returns true if the bounding box is touching or within a circle with given radius (circleradius ) and a center point at (circlex ,circley ); returns false otherwise.
Note: this function does not account for the bounding box being diagonal to the circle, so the "circle" in practice will act more like a box itself. |