|
|
typedef struct {
vec3 n; // normal
float d; // distance along normal from the origin
} Plane;
typedef struct {
vec3 n; // normal
vec3 p; // an arbitrary point on the plane
} PlaneP;
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 intersectPlaneRay3p(Plane* pl, Ray3* ray, vec3* ipoint, float* idist)
Negative values of idist are "behind" ray->o. Returns C3DLAS_INTERSECT, C3DLAS_PARALLEL or C3DLAS_DISJOINT.
int findIntersectLinePlane(Line3 l, Plane* pl, Vector3* out)
Returns C3DLAS_INTERSECT, C3DLAS_COPLANAR or C3DLAS_DISJOINT.
int findIntersectFastLinePlane(Line3 l, Plane* pl, Vector3* out)
Assumes that the line and plan intersect; does not check for coplanarity. Returns C3DLAS_INTERSECT, C3DLAS_COPLANAR or C3DLAS_DISJOINT.
void vProjectOntoPlane3p(Vector3* v, Plane* p, Vector3* out);
void vProjectOntoPlaneNormalized3p(Vector3* v, Plane* p, Vector3* out);
void planeFromPointNormal(Vector3* p, Vector3* norm, Plane* out);
void planeFromTriangle3p(Vector3* v1, Vector3* v2, Vector3* v3, Plane* out); // calculates a plane form a triangle
void planeCopy3p(Plane* in, Plane* out); // copy a plane
void planeInverse3p(Plane* in, Plane* out); // flips the plane's direction
int planeClassifyPoint3p(Plane* p, Vector3* pt); // classifies a point by which side of the plane it's on, default espilon
int planeClassifyPointEps3p(Plane* p, Vector3* pt, float epsilon); // classifies a point by which side of the plane it's on, custom espilon
// closest distance from an arbitrary point to the plane
float planePointDist3p(Plane* pl, Vector3* p);
// signed closest distance from an arbitrary point to the plane
float planePointDistSigned3p(Plane* pl, Vector3* p);
// C3DLAS_INTERSECT, _PARALLEL or _DISJOINT
// negative values of idist are "behind" ray->o
int intersectPlaneRay3p(Plane* pl, Ray3* ray, Vector3* ipoint, float* idist);
// C3DLAS_COPLANAR, _PARALLEL, _INTERSECT, or _DISJOINT
// aboveCnt and belowCnt are always set.
int linePlaneClip3p(
Vector3* la,
Vector3* lb,
Plane* pl,
Vector3* aboveOut,
Vector3* belowOut,
int* aboveCnt,
int* belowCnt
);
|