|
|
Rectangles, squares, and quads.
typedef struct {
vec2i v[4]; // in a loop
} Quad2i;
typedef struct {
vec2 v[4]; // in a loop
} Quad2;
typedef struct { // does not have to be coplanar
vec3 v[4]; // in a loop
} Quad3;
typedef struct {
vec2 c1, c2; // opposite corners
} Rect2;
typedef struct {
Plane planes[6]; // near, far, sides[4]
vec3 points[8]; // near then far
} Frustum;
Not all distance and intersection functions have systematic names yet. In general, functions are named in the pattern
[operation][lesser]N[greater]N(l, g, [args], out*) where operation is something like dist or intersect, lesser is the argument with fewer
dimensions, greater is the argument with more dimensions, and N is the number of dimensions if otherwise unclear (lines and triangles can exist in
2 or 3 dimensions, for example, but spheres and circles imply their dimensionality). Functions with "T" in the name return a normalized value
along with whatever other results.
Primitives
- Line: An infinite line, unless otherwise specified, with no implied direction.
- Ray: A line with a start location that extends inifinitely in some specified direction.
- Rect: An axis-aligned rectangle defined by two opposing corners.
- Quad: An arbitrary quadrilateral in 2 or 3 dimensions defined by a loop of consecutive corners. May or may not need to be
planar or rectangular (right angles) depending on the function.
- Circle: A circle defined by a center and a radius in 2 dimensions.
- Plane: An infinite plane in 3 dimensions defined by a normal vector and a distance from the origin.
- PlaneP: An infinite plane in 3 dimensions defined by a normal vector and a point on the plane.
- Sphere: A sphere in 3 dimensions defined by a center and a radius.
- Capsule: A pill-shaped 3D object defined by the center points of the two connected end spheres and a radius.
Operation Stubs
- dist: Shortest distance between the two objects.
- intersect: Determines if the two objects intersect.
- findIntersect: Finds the point (or line) of intersection between two objects. Unless otherwise specified, it's the closest
point of intersection if there are multiple.
- proj: Projects the first object onto the second, whatever that means for the objects involved.
Functions
int intersectPoint2Rect2(vec2 a, Quad2 q)
Must be a rectangle, not an arbitrary quadrilateral. Returns C3DLAS_INTERSECT or C3DLAS_DISJOINT.
int intersectRect2Rect2(Quad2 a, Quad2 b)
Returns C3DLAS_INTERSECT, C3DLAS_DISJOINT.
float distLine2Rect2(Line2 a, Quad2 q)
Quad must be a rectangle, and the vertices must be ordered in a loop
float distPoint2Rect2(vec2 a, Quad2 q)
Quad must be a rectangle, and the vertices must be ordered in a loop
int intersectBoxLine3(AABB3 b, Line3 l, vec3* ipoint, float* idist)
int intersectBoxLine3p(const AABB3* b, const Line3* l, vec3* ipoint, float* idist)
// 3D versions
int boxDisjoint3p(const AABB3* a, const AABB3* b);
int boxOverlaps3p(const AABB3* a, const AABB3* b);
int boxContainsBox3p(const AABB3* outside, const AABB3* inside);
int boxContainsPoint3p(const AABB3* b, const Vector3* p);
bool boxContainsPoint3(AABB3 b, Vector3 p);
AABB3 boxUnion(AABB3 a, AABB3 b);
Vector3 boxCenter3(const AABB3 b); // calculates the center of the box
void boxCenter3p(const AABB3* b, Vector3* out); // calculates the center of the box
Vector2 boxSize2(const AABB2 b); // calculates the size of the box
Vector3 boxSize3(const AABB3 b); // calculates the size of the box
void boxSize2p(const AABB2* b, Vector2* out); // calculates the size of the box
void boxSize3p(const AABB3* b, Vector3* out); // calculates the size of the box
void boxExpandTo3p(AABB3* b, Vector3* p);
void boxExpandTo3(AABB3* b, Vector3 p);
int boxClipRay(AABB3* b, Ray3 r, Line3* out); // returns _INTERSECT or _DISJOINT
void makeRay3p(Vector3* origin, Vector3* direction, Ray3* out);
int boxRayIntersectFast3p(const AABB3* b, const Ray3* r);
int boxRayIntersect3p(const AABB3* b, const Ray3* r, Vector3* ipoint, float* idist);
int intersectBoxLine3p(const AABB3* b, const Line3* l, Vector3* ipoint, float* idist);
int intersectBoxLine3(AABB3 b, Line3 l, Vector3* ipoint, float* idist);
// 2D versions
int boxDisjoint2p(const AABB2* a, const AABB2* b);
int boxOverlaps2p(const AABB2* a, const AABB2* b);
int boxContainsBox2p(const AABB2* outside, const AABB2* inside);
int boxContainsPoint2p(const AABB2* b, const Vector2* p);
void boxCenter2p(const AABB2* b, Vector2* out); // calcuates the center of the box
void boxSize2p(const AABB2* b, Vector2* out); // calculates the size of the box
void boxQuadrant2p(const AABB2* in, char ix, char iy, AABB2* out);
// 2D integer versions
int boxDisjoint2ip(const AABB2i* a, const AABB2i* b);
int boxOverlaps2ip(const AABB2i* a, const AABB2i* b);
int boxContainsPoint2ip(const AABB2i* b, const Vector2i* p);
void boxCenter2ip(const AABB2i* b, Vector2* out); // calcuates the center of the box
void boxSize2ip(const AABB2i* b, Vector2* out); // calculates the size of the box
void boxQuadrant2ip(const AABB2i* in, char ix, char iy, AABB2i* out);
// find the center of a quad
void quadCenter2p(const Quad2* in, Vector2* out);
void quadRoundOutward2p(const Quad2* in, Quad2i* out);
void quadRoundInward2p(const Quad2* in, Quad2i* out);
// _INTERSECT, or _DISJOINT
int intersectQuadPoint2(vec2 p, vec2 q[4]);
struct intersectQuadPoint2_precalc {
vec2 ab, ac, db, dc;
vec2 a, d;
float invden_a, invden_d;
};
void intersectQuadPoint2_precalc(vec2 q[4], struct intersectQuadPoint2_precalc* pc);
int intersectQuadPoint2_withprecalc(vec2 p, struct intersectQuadPoint2_precalc* pc);
void frustumCenter(Frustum* f, Vector3* out);
void frustumBoundingSphere(Frustum* f, Sphere* out);
void quadCenterp3p(Vector3* a, Vector3* b, Vector3* c, Vector3* d, Vector3* out);
void frustumFromMatrix(Matrix* m, Frustum* out);
void frustumFromMatrixVK(Matrix* m, Frustum* out);
void frustumFromMatrixVK_ZUP(Matrix* m, Frustum* out);
void frustumFromMatrixVK_RDepth(Matrix* m, Frustum* out);
void frustumFromMatrixVK_ZUP_RDepth(Matrix* m, Frustum* out);
void frustumInnerBoundingSphere(Frustum* f, Sphere* out);
void frustumOuterBoundingSphere(Frustum* f, Sphere* out);
|