123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104 |
- #ifndef __c3dlas_h__
- #define __c3dlas_h__
- #include <stdlib.h> // rand() et al.
- #include <stdint.h>
- #include <math.h> // fmin/fmax
- #undef I // because of some bullshit in <complex.h>
- #define _0000b 0x00
- #define _0001b 0x01
- #define _0010b 0x02
- #define _0011b 0x03
- #define _0100b 0x04
- #define _0101b 0x05
- #define _0110b 0x06
- #define _0111b 0x07
- #define _1000b 0x08
- #define _1001b 0x09
- #define _1010b 0x0a
- #define _1011b 0x0b
- #define _1100b 0x0c
- #define _1101b 0x0d
- #define _1110b 0x0e
- #define _1111b 0x0f
- #define F_PI ((float)3.1415926535897932384626433832795028841971693993751)
- #define D_PI ((double)3.1415926535897932384626433832795028841971693993751)
- #define F_2PI ((float)6.2831853071795864769252867665590057683943387987502)
- #define D_2PI ((double)6.2831853071795864769252867665590057683943387987502)
- #define F_1_PI ((float)0.3183098861837906715377675267450287240689192914809)
- #define D_1_PI ((double)0.3183098861837906715377675267450287240689192914809)
- #define F_PI_2 ((float)1.5707963267948966192313216916397514420985846996875)
- #define D_PI_2 ((double)1.5707963267948966192313216916397514420985846996875)
- #define F_3PI_2 ((float)4.7123889803846898576939650749192543262957540990626)
- #define D_3PI_2 ((double)4.7123889803846898576939650749192543262957540990626)
- #define F_GOLDEN ((float)1.61803398874989484820458683436563811772030917980576f)
- #define D_GOLDEN ((double)1.61803398874989484820458683436563811772030917980576)
- #define RAD2DEG (57.29577951308232087679815481410517033240547246656432154916024386)
- #define DEG2RAD (0.0174532925199432957692369076848861271344287188854172545609719144)
- #ifndef FLT_CMP_EPSILON
- #define FLT_CMP_EPSILON 0.000001
- #endif
- #ifndef DBL_CMP_EPSILON
- #define DBL_CMP_EPSILON 0.00000000000001
- #endif
- #define FLT_CMP_EPSILON_SQ (FLT_CMP_EPSILON * FLT_CMP_EPSILON)
- #define DBL_CMP_EPSILON_SQ (DBL_CMP_EPSILON_SQ * DBL_CMP_EPSILON_SQ)
- #define C3DLAS_COPLANAR (0)
- #define C3DLAS_FRONT (1)
- #define C3DLAS_BACK (2)
- #define C3DLAS_INTERSECT (3)
- #define C3DLAS_DISJOINT (4)
- #define C3DLAS_PARALLEL (5)
- #ifndef C3DLAS_fprintf
- #define C3DLAS_fprintf fprintf
- #endif
- #ifndef C3DLAS_errprintf
- #define C3DLAS_errprintf(...) fprintf(stderr, __VA_ARGS__)
- #endif
- static const char* c3dlas_EnumString(int e) {
- switch(e) {
- case 0: return "C3DLAS_COPLANAR";
- case 1: return "C3DLAS_FRONT";
- case 2: return "C3DLAS_BACK";
- case 3: return "C3DLAS_INTERSECT";
- case 4: return "C3DLAS_DISJOINT";
- case 5: return "C3DLAS_PARALLEL";
- default: return "Unknown Code";
- }
- }
- #ifndef MAX
- #define MAX(a,b) ({ \
- __typeof__ (a) _a = (a); \
- __typeof__ (b) _b = (b); \
- _a > _b ? _a : _b; \
- })
- #endif
- #ifndef MIN
- #define MIN(a,b) ({ \
- __typeof__ (a) _a = (a); \
- __typeof__ (b) _b = (b); \
- _a < _b ? _a : _b; \
- })
- #endif
- #define C3DLAS_VECTOR_TYPE_LIST(X, ...) \
- X(, float, float, __VA_ARGS__) \
- X(d, double, double, __VA_ARGS__) \
- X(i, int, double, __VA_ARGS__) \
- X(l, long, double, __VA_ARGS__) \
- #define C3DLAS_VECTOR_LIST(X, ...) \
- X(2, 2, float, float, 2, FLT __VA_OPT__(,) __VA_ARGS__) \
- X(3, 3, float, float, 3, FLT __VA_OPT__(,) __VA_ARGS__) \
- X(4, 4, float, float, 4, FLT __VA_OPT__(,) __VA_ARGS__) \
- X(2, 2d, double, double, 2d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(3, 3d, double, double, 3d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(4, 4d, double, double, 4d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(2, 2i, int, double, 2d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(3, 3i, int, double, 3d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(4, 4i, int, double, 4d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(2, 2l, long, double, 2d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(3, 3l, long, double, 3d, DBL __VA_OPT__(,) __VA_ARGS__) \
- X(4, 4l, long, double, 4d, DBL __VA_OPT__(,) __VA_ARGS__) \
- #define C3DLAS_GEN_HELPER(sz, suf, ty, ft, sufft, pref, name, ...) Vector##suf: name##suf,
- #define X(suf, t, ...) \
- typedef struct Vector2 ## suf { \
- \
- union { t x, rho; }; \
- union { t y, theta; }; \
- } Vector2 ## suf;
-
- C3DLAS_VECTOR_TYPE_LIST(X)
- #undef X
- #define X(suf, t, ...) \
- typedef struct Vector3 ## suf { \
- \
- union { t x, rho, r; }; \
- union { t y, theta, g; }; \
- union { t z, phi, b; }; \
- } Vector3 ## suf;
-
- C3DLAS_VECTOR_TYPE_LIST(X)
- #undef X
- #define X(suf, t, ...) \
- typedef struct Vector4 ## suf { \
- \
- union { t x, rho, r, i; }; \
- union { t y, theta, g, j; }; \
- union { t z, phi, b, k; }; \
- union { t w, a, real; }; \
- } Vector4 ## suf;
-
- C3DLAS_VECTOR_TYPE_LIST(X)
- #undef X
- typedef struct Vector4 Quaternion;
- typedef struct Vector4d Quaterniond;
- typedef struct {
- Vector3 o;
- Vector3 d;
- } Ray3;
- typedef struct {
- Vector2 o;
- Vector2 d;
- } Ray2;
- typedef struct {
- Vector2 start, end;
- } Line2;
- typedef struct {
- union { Vector3 start, a; };
- union { Vector3 end, b; };
- } Line3;
- typedef struct Polygon {
- Vector2* points;
- long pointAlloc;
- long pointCount;
-
- Vector2 centroid;
- float maxRadiusSq;
- } Polygon;
- typedef struct BezierSplineSegment3 {
- Vector3 e, c;
- struct BezierSplineSegment3* next;
- } BezierSplineSegment3;
- typedef struct {
- int length;
- unsigned char isLoop;
- BezierSplineSegment3* segments;
- } BezierSpline3;
- typedef struct BezierSplineSegment2 {
- Vector2 e, c;
- struct BezierSplineSegment2* next;
- } BezierSplineSegment2;
- typedef struct {
- int length;
- unsigned char isLoop;
- BezierSplineSegment2* segments;
- } BezierSpline2;
- typedef struct {
- Vector3 n;
- float d;
- } Plane;
- typedef struct {
- Vector3 n;
- Vector3 p;
- } PlaneP;
- typedef struct {
- Vector3 center;
- float r;
- } Sphere;
- typedef struct {
- Vector3 a, b;
- float r;
- } Capsule;
- typedef struct {
- Plane planes[6];
- Vector3 points[8];
- } Frustum;
- typedef struct {
- Vector2i v[4];
- } Quad2i;
- typedef struct {
- Vector2 v[4];
- } Quad2;
- typedef struct {
- Vector3 v[4];
- } Quad3;
- typedef struct {
- Vector2 c1, c2;
- } Rect2;
- typedef struct {
- float m[16];
- } Matrix;
- typedef struct MatrixStack {
- short size;
- short top;
- Matrix* stack;
- } MatrixStack;
- typedef struct {
- float m[10];
- } MatrixSym;
- typedef struct {
- float m[9];
- } Matrix3;
- typedef struct {
- float m[4];
- } Matrix2;
- #define X(sz, suf, t, ...) \
- typedef struct AABB ## suf { \
- Vector ## suf min, max; \
- } AABB ## suf;
-
- C3DLAS_VECTOR_LIST(X)
- #undef X
- typedef struct {
- uint64_t state, stream;
- } PCG;
- extern const Matrix IDENT_MATRIX;
- extern const Matrix3 IDENT_MATRIX3;
- uint32_t bitReverse32(uint32_t x);
- uint32_t reverseBits(uint32_t n, int len);
- float pcg_f(uint64_t* state, uint64_t stream);
- uint32_t pcg_u32(uint64_t* state, uint64_t stream);
- float frandPCG(float low, float high, PCG* pcg);
- #ifndef C3DLAS_NO_LIBC_RAND
- static inline float frand(float low, float high) {
- return low + ((high - low) * ((float)rand() / (float)RAND_MAX));
- }
- static inline float frandNorm(void) {
- return ((float)rand() / (float)RAND_MAX);
- }
- static inline float frandNorm2(void) {
- return ((float)rand() / (float)RAND_MAX) * 2.0 - 1.0;
- }
- static inline double drand(double low, double high) {
- return low + ((high - low) * ((double)rand() / (double)RAND_MAX));
- }
- static inline double drandNorm(void) {
- return ((double)rand() / (double)RAND_MAX);
- }
- #endif
- static inline float fclamp(float val, float min, float max) {
- return fminf(max, fmaxf(min, val));
- }
- static inline double dclamp(double val, double min, double max) {
- return fmin(max, fmax(min, val));
- }
- static inline float fclampNorm(float val) {
- return fclamp(val, 0.0f, 1.0f);
- }
- static inline double dclampNorm(double val) {
- return dclamp(val, 0.0, 1.0);
- }
- static inline int iclamp(int val, int min, int max) {
- return MIN(max, MAX(min, val));
- }
- static inline long lclamp(long val, long min, long max) {
- return MIN(max, MAX(min, val));
- }
- static inline float flerp(float a, float b, float t) {
- return a + ((b - a) * t);
- }
- static inline double dlerp(double a, double b, double t) {
- return a + ((b - a) * t);
- }
- static inline float flerp2D(float xx, float xy, float yx, float yy, float xt, float yt) {
- float a = xx + ((xy - xx) * yt);
- float b = yx + ((yy - yx) * yt);
- return a + ((b - a) * xt);
- }
- static inline double dlerp2D(double xx, double xy, double yx, double yy, double xt, double yt) {
- double a = xx + ((xy - xx) * yt);
- double b = yx + ((yy - yx) * yt);
- return a + ((b - a) * xt);
- }
- static inline float fsmootherstep(float a, float b, float t) {
- if(t < 0.f) return a;
- if(t > 1.f) return b;
- return (b - a) * ((t * (t * 6.0f - 15.0f) + 10.0f) * t * t * t) + a;
- }
- static inline double dsmootherstep(double a, double b, double t) {
- if(t < 0.0) return a;
- if(t > 1.0) return b;
- return (b - a) * ((t * (t * 6.0 - 15.0) + 10.0) * t * t * t) + a;
- }
- void vPerp2p(Vector2* n, Vector2* out);
- Vector2 vPerp2(Vector2 n);
- void vPerp3p(Vector3* n, Vector3* out);
- Vector3 vPerp3(Vector3 n);
- #define X(sz, suf, ty, ft, sufft, ...) \
- int vEq##suf(const Vector##suf a, const Vector##suf b); \
- int vEq##suf##p(const Vector##suf* a, const Vector##suf* b); \
- \
- int vEqEp##suf(const Vector##suf a, const Vector##suf b, ft epsilon); \
- int vEqEp##suf##p(const Vector##suf* a, const Vector##suf* b, ft epsilon); \
- \
- int vEqExact##suf(const Vector##suf a, const Vector##suf b); \
- int vEqExact##suf##p(const Vector##suf* a, const Vector##suf* b); \
- \
- Vector##suf vAdd##suf(const Vector##suf a, const Vector##suf b); \
- void vAdd##suf##p(const Vector##suf* a, const Vector##suf* b, Vector##suf* out); \
- \
- Vector##suf vSub##suf(const Vector##suf from, const Vector##suf what); \
- void vSub##suf##p(const Vector##suf* from, const Vector##suf* what, Vector##suf* out); \
- \
- Vector##suf vMul##suf(const Vector##suf a, const Vector##suf b); \
- void vMul##suf##p(const Vector##suf* a, const Vector##suf* b, Vector##suf* out); \
- \
- Vector##suf vDiv##suf(const Vector##suf top, const Vector##suf bot); \
- void vDiv##suf##p(const Vector##suf* top, const Vector##suf* bot, Vector##suf* out); \
- \
- Vector##sufft vScale##suf(const Vector##suf v, ft scalar); \
- void vScale##suf##p(const Vector##suf* v, ft scalar, Vector##sufft* out); \
- \
- Vector##suf vMin##suf(const Vector##suf a, const Vector##suf b); \
- void vMin##suf##p(const Vector##suf* a, const Vector##suf* b, Vector##suf* out); \
- \
- Vector##suf vMax##suf(const Vector##suf a, const Vector##suf b); \
- void vMax##suf##p(const Vector##suf* a, const Vector##suf* b, Vector##suf* out); \
- \
- Vector##suf vClamp##suf(const Vector##suf in, const Vector##suf min, const Vector##suf max); \
- void vClamp##suf##p(const Vector##suf* in, const Vector##suf* min, const Vector##suf* max, Vector##suf* out); \
- \
- int vMinComp##suf(const Vector##suf a); \
- int vMinComp##suf##p(const Vector##suf* a); \
- \
- int vMaxComp##suf(const Vector##suf a); \
- int vMaxComp##suf##p(const Vector##suf* a); \
- \
- ft vDot##suf(const Vector##suf a, const Vector##suf b); \
- ft vDot##suf##p(const Vector##suf* a, const Vector##suf* b); \
- \
- Vector##sufft vAvg##suf(const Vector##suf a, const Vector##suf b); \
- void vAvg##suf##p(const Vector##suf* a, const Vector##suf* b, Vector##sufft* out); \
- \
- ft vDist##suf(const Vector##suf a, const Vector##suf b); \
- ft vDist##suf##p(const Vector##suf* a, const Vector##suf* b); \
- \
- ft vDistSq##suf(const Vector##suf a, const Vector##suf b); \
- ft vDistSq##suf##p(const Vector##suf* a, const Vector##suf* b); \
- \
- Vector##sufft vNorm##suf(const Vector##suf v); \
- void vNorm##suf##p(const Vector##suf* v, Vector##sufft* out); \
- \
- Vector##sufft vUnit##suf(const Vector##suf v); \
- void vUnit##suf##p(const Vector##suf* v, Vector##sufft* out); \
- \
- ft vLen##suf(const Vector##suf v); \
- ft vLen##suf##p(const Vector##suf* v); \
- ft vMag##suf(const Vector##suf v); \
- ft vMag##suf##p(const Vector##suf* v); \
- \
- ft vLenSq##suf(const Vector##suf v); \
- ft vLenSq##suf##p(const Vector##suf* v); \
- \
- ft vInvLen##suf(const Vector##suf v); \
- ft vInvLen##suf##p(const Vector##suf* v); \
- \
- Vector##suf vAbs##suf(const Vector##suf v); \
- void vAbs##suf##p(const Vector##suf* v, Vector##suf* out); \
- \
- Vector##sufft vRecip##suf(const Vector##suf v); \
- void vRecip##suf##p(const Vector##suf* v, Vector##sufft* out); \
- Vector##sufft vInv##suf(const Vector##suf v); \
- void vInv##suf##p(const Vector##suf* v, Vector##sufft* out); \
- \
- Vector##suf vNeg##suf(const Vector##suf v); \
- void vNeg##suf##p(const Vector##suf* v, Vector##suf* out); \
- \
- Vector##suf vSign##suf(const Vector##suf v); \
- void vSign##suf##p(const Vector##suf* v, Vector##suf* out); \
- \
- Vector##suf vStep##suf(const Vector##suf edge, const Vector##suf v); \
- void vStep##suf##p(const Vector##suf* edge, const Vector##suf* v, Vector##suf* out); \
- \
- Vector##sufft vLerp##suf(const Vector##suf a, const Vector##suf b, ft t); \
- void vLerp##suf##p(const Vector##suf* a, const Vector##suf* b, ft t, Vector##sufft* out); \
- \
-
-
- C3DLAS_VECTOR_LIST(X)
- #undef X
- #ifndef C3DLAS_NO_SHORT_TYPENAMES
- #include "short_macros.h"
- #endif
- #ifndef C3DLAS_NO_GENERIC_FNS
- #include "generic_vectors.h"
- #endif
- void vSwap2ip(Vector2i* a, Vector2i* b);
- void vSwap2p(Vector2* a, Vector2* b);
- void vSwap3p(Vector3* a, Vector3* b);
- void vSwap4p(Vector4* a, Vector4* b);
- Vector3 vCross3(Vector3 a, Vector3 b);
- void vCross3p(Vector3* a, Vector3* b, Vector3* out);
- float vCross2(Vector2 a, Vector2 b);
- float vCross2p(Vector2* a, Vector2* b);
- float vScalarTriple3(Vector3 a, Vector3 b, Vector3 c);
- float vScalarTriple3p(Vector3* a, Vector3* b, Vector3* c);
- double vMag2i(const Vector2i v);
- float vMag2(const Vector2 v);
- float vMag3(const Vector3 v);
- float vMag4(const Vector4 v);
- double vMag2ip(const Vector2i* v);
- float vMag2p(const Vector2* v);
- float vMag3p(const Vector3* v);
- float vMag4p(const Vector4* v);
- Vector4i vFloor4(const Vector4 v);
- Vector3i vFloor3(const Vector3 v);
- Vector2i vFloor2(const Vector2 v);
- Vector4i vCeil4(const Vector4 v);
- Vector3i vCeil3(const Vector3 v);
- Vector2i vCeil2(const Vector2 v);
- Vector4l vFloor4d(const Vector4d v);
- Vector3l vFloor3d(const Vector3d v);
- Vector2l vFloor2d(const Vector2d v);
- Vector4l vCeil4d(const Vector4d v);
- Vector3l vCeil3d(const Vector3d v);
- Vector2l vCeil2d(const Vector2d v);
- Vector2 vModPositive2(Vector2 v, Vector2 m);
- Vector3 vModPositive3(Vector3 v, Vector3 m);
- Vector4 vModPositive4(Vector4 v, Vector4 m);
- Vector2 vClamp2f(Vector2 in, float min, float max);
- Vector3 vClamp3f(Vector3 in, float min, float max);
- Vector3 vC2S3(Vector3 cart);
- Vector3 vS2C3(Vector3 s);
- float vDistPointLine2(Vector2 p, Line2 ls);
- float vDistPointLine3(Vector3 p, Line3 ls);
- float distPoint2Triangle2(Vector2 a, Vector2 tri[3]);
- float vDistTPointLine2(Vector2 p, Line2 ls, float* T);
- float vDistTPointLine3(Vector3 p, Line3 ls, float* T);
- int intersectLine2Line2(Line2 a, Line2 b);
- int intersectRect2Rect2(Quad2 a, Quad2 b);
- float projPointLine2(Vector2 p, Line2 ls);
- float distLineLine3(Line3* a, Line3* b);
- Line2 shortestLineFromLineToLine2(Line2* a, Line2* b);
- Line3 shortestLineFromLineToLine(Line3* a, Line3* b);
- float distLine2Rect2(Line2 a, Quad2 q);
- float distPoint2Rect2(Vector2 a, Quad2 q);
- float distLine2Triangle2(Line2 a, Vector2 tri[3]);
- float distTPointRay3(Vector3 p, Ray3 r, float* T);
- float dist2TPointRay3(Vector3 p, Ray3 r, float* T);
- int vInsidePolygon(Vector2 p, Polygon* poly);
- float vDistPolygon(Vector2 p, Polygon* poly);
- void polyCalcCentroid(Polygon* poly);
- void polyCalcRadiusSq(Polygon* poly) ;
- void vProject3p(Vector3* what, Vector3* onto, Vector3* out);
- void vProjectNorm3p(Vector3* what, Vector3* onto, Vector3* out);
- void vPointAvg3p(Vector3* a, Vector3* b, Vector3* out);
- void vRandomPCG3p(Vector3* end1, Vector3* end2, PCG* pcg, Vector3* out);
- Vector3 vRandomPCG3(Vector3 end1, Vector3 end2, PCG* pcg);
- void vRandomNormPCG3p(PCG* pcg, Vector3* out);
- Vector3 vRandomNormPCG3(PCG* pcg);
- void vRandomPCG2p(Vector2* end1, Vector2* end2, PCG* pcg, Vector2* out);
- Vector2 vRandomPCG2(Vector2 end1, Vector2 end2, PCG* pcg);
- void vRandomNormPCG2p(PCG* pcg, Vector2* out);
- Vector2 vRandomNormPCG2(PCG* pcg);
- void vRandom3p(Vector3* end1, Vector3* end2, Vector3* out);
- Vector3 vRandom3(Vector3 end1, Vector3 end2);
- void vRandomNorm3p(Vector3* out);
- int shortestLineFromRayToRay3p(Ray3* r1, Ray3* r2, Vector3* pOut);
- void vReflectAcross3p(Vector3* v, Vector3* pivot, Vector3* out);
- Vector3 vReflectAcross3(Vector3 v, Vector3 pivot);
- void vTriFaceNormal3p(Vector3* a, Vector3* b, Vector3* c, Vector3* out);
- Vector3 vTriFaceNormal3(Vector3 a, Vector3 b, Vector3 c);
- void vpTriFaceNormal3p(Vector3* tri, Vector3* out);
- Vector3 vTriFaceNormalArea3(Vector3 a, Vector3 b, Vector3 c, float* area);
- 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);
- void planeCopy3p(Plane* in, Plane* out);
- void planeInverse3p(Plane* in, Plane* out);
- int planeClassifyPoint3p(Plane* p, Vector3* pt);
- int planeClassifyPointEps3p(Plane* p, Vector3* pt, float epsilon);
- float planePointDist3p(Plane* pl, Vector3* p);
- float planePointDistSigned3p(Plane* pl, Vector3* p);
- int planeLineFindIntersect3p(Plane* pl, Vector3* la, Vector3* lb, Vector3* out);
- int planeLineFindIntersectFast3p(Plane* pl, Vector3* la, Vector3* lb, Vector3* out);
- int intersectPlaneRay3p(Plane* pl, Ray3* ray, Vector3* ipoint, float* idist);
- int rayTriangleIntersect(
- Vector3* a, Vector3* b, Vector3* c, // triangle
- Vector3* ray_origin, Vector3* ray_dir, // ray
- float* u, float* v, float* t // barycentric out coords, t of intersection point along ray
- );
- Vector3 triangleClosestPoint(
- Vector3* a, Vector3* b, Vector3* c, // triangle
- Vector3* p, // test point
- float* out_u, float* out_v // barycentric out coords of closest point
- );
- Vector3 triangleClosestPoint_Reference(
- Vector3* a, Vector3* b, Vector3* c, // triangle
- Vector3* p, // test point
- float* out_u, float* out_v // barycentric out coords of closest point
- );
- int triPlaneTestIntersect3p(Vector3* pTri, Plane* pl);
- int triPlaneClip3p(
- Vector3* pTri,
- Plane* pl,
- Vector3* aboveOut,
- Vector3* belowOut,
- int* aboveCnt,
- int* belowCnt
- );
- int linePlaneClip3p(
- Vector3* la,
- Vector3* lb,
- Plane* pl,
- Vector3* aboveOut,
- Vector3* belowOut,
- int* aboveCnt,
- int* belowCnt
- );
- 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);
- void vReflectAcross2p(Vector2* v, Vector2* pivot, Vector2* out);
- void vRoundAway2p(const Vector2* in, const Vector2* center, Vector2i* out);
- void vRoundToward2p(const Vector2* in, const Vector2* center, Vector2i* out);
- float triArea2p(Vector2* a, Vector2* b, Vector2* c);
- int triPointInside2p(Vector2* p, Vector2* a, Vector2* b, Vector2* c);
- void mIdent3(Matrix3* m);
- void mFastMul3(Matrix3* restrict a, Matrix3* restrict b, Matrix3* restrict out);
- void mMul3(Matrix3* a, Matrix3* out);
- float mDeterminate3(Matrix3* m);
- void mInverse3(Matrix3* m, Matrix3* out);
- void mScalarMul3(Matrix3* m, float scalar, Matrix3* out);
- Vector3 vMatrix3Mul(Vector3 v, Matrix3* restrict m);
- void mTranspose3(Matrix3* m, Matrix3* out);
- float mTrace3(Matrix3* m);
- float pvDist3p(Plane* p, Vector3* v);
- void vMatrixMul3p(Vector3* in, Matrix* m, Vector3* out);
- void vMatrixMulf3p(float x, float y, float z, Matrix* m, Vector3* out);
- Vector3 vMatrixMul3(Vector3 in, Matrix* m);
- Vector4 vMatrixMul4(Vector4 in, Matrix* m);
- Vector3 vMatrixMulProjectedMagic3(Vector3 in, Matrix* m);
- void mIdent(Matrix* m);
- void mCopy(Matrix* in, Matrix* out);
- void mFastMul(Matrix* a, Matrix* b, Matrix* out);
- void mMul(Matrix* a, Matrix* out);
- void mTransv(Vector3* v, Matrix* out);
- void mTrans3f(float x, float y, float z, Matrix* out);
- void mScalev(Vector3* v, Matrix* out);
- void mScale3f(float x, float y, float z, Matrix* out);
- void mRotv(Vector3* v, float theta, Matrix* out);
- void mRot3f(float x, float y, float z, float theta, Matrix* out);
- void mRotX(float theta, Matrix* out);
- void mRotY(float theta, Matrix* out);
- void mRotZ(float theta, Matrix* out);
- void mTranspose(Matrix* in, Matrix* out);
- void mTransposeFast(Matrix* in, Matrix* out);
- float mDeterminate(Matrix* m);
- int mInverse(Matrix* in, Matrix* out);
- float mTrace(Matrix* m);
- void mRotationOnly(Matrix* in, Matrix* out);
- void mAdd(Matrix* a, Matrix* b, Matrix* out);
- void mScalarMul(Matrix* a, float f, Matrix* out);
- void mDecompose(Matrix* mat, Vector3* trans, Quaternion* rot, Vector3* scale);
- void mRecompose(Vector3* trans, Quaternion* rot, Vector3* scale, Matrix* out);
- void mFrustum(float left, float right, float top, float bottom, float near, float far, Matrix* out);
- void mPerspective(float fov, float aspect, float near, float far, Matrix* out);
- void mPerspectiveVK(float fov, float aspect, float near, float far, Matrix* out);
- void mPerspectiveVK_ZUp(float fov, float aspect, float near, float far, Matrix* out);
- void mPerspExtractNF(Matrix* m, double* near, double* far);
- void mPerspSetNF(Matrix* m, float near, float far);
- void mPerspSetNFVK(Matrix* m, float near, float far);
- void mPerspSetNF_ZUp(Matrix* m, float near, float far);
- void mPerspSetNF_ZUp_RDepth(Matrix* m, float near, float far);
- void mPerspSetNFVK_ZUp(Matrix* m, float near, float far);
- void mPerspSetNFVK_ZUp_RDepth(Matrix* m, float near, float far);
- void mOrtho(float left, float right, float top, float bottom, float near, float far, Matrix* out);
- void mOrthoVK(float left, float right, float top, float bottom, float near, float far, Matrix* out);
- void mOrthoFromRadius(float r, Matrix* out);
- void mOrthoFromRadiusVK(float r, Matrix* out);
- void mOrthoFromSphere(Sphere s, Vector3 eyePos, Vector3 up, Matrix* out);
- void mOrthoFromSphereVK(Sphere s, Vector3 eyePos, Vector3 up, Matrix* out);
- void mOrthoExtractPlanes(Matrix* m, float* left, float* right, float* top, float* bottom, float* near, float* far);
- void mOrthoExtractPlanesVK(Matrix* m, float* left, float* right, float* top, float* bottom, float* near, float* far);
- void mOrthoSetNF(Matrix* m, float near, float far);
- void mOrthoSetNFVK(Matrix* m, float near, float far);
- void mLookAt(Vector3 eye, Vector3 center, Vector3 up, Matrix* out);
- void mLookDir(Vector3 eye, Vector3 dir, Vector3 up, Matrix* out);
- void mPrint(Matrix* m, void* arg);
- void msAlloc(int size, MatrixStack* ms);
- void msFree(MatrixStack* ms);
- int msPush(MatrixStack* ms);
- void msPop(MatrixStack* ms);
- Matrix* msGetTop(MatrixStack* ms);
- void msPrintAll(MatrixStack* ms, void* f);
- void msIdent(MatrixStack* ms);
- void msCopy(Matrix* in, MatrixStack* ms);
- void msMul(Matrix* a, MatrixStack* ms);
- void msTransv(Vector3* v, MatrixStack* ms);
- void msTrans3f(float x, float y, float z, MatrixStack* ms);
- void msScalev(Vector3* v, MatrixStack* ms);
- void msScale3f(float x, float y, float z, MatrixStack* ms);
- void msRotv(Vector3* v, float theta, MatrixStack* ms);
- void msRot3f(float x, float y, float z, float theta, MatrixStack* ms);
- void msFrustum(float left, float right, float top, float bottom, float near, float far, MatrixStack* ms);
- void msPerspective(double fov, float aspect, float near, float far, MatrixStack* ms);
- void msOrtho(float left, float right, float top, float bottom, float near, float far, MatrixStack* ms);
- void msLookAt(Vector3* eye, Vector3* center, Vector3* up, MatrixStack* ms);
- void evalBezier3p(Vector3* e1, Vector3* e2, Vector3* c1, Vector3* c2, float t, Vector3* out);
- void evalBezierTangent3p(Vector3* e1, Vector3* e2, Vector3* c1, Vector3* c2, float t, Vector3* out);
- void evalBezierNorm3p(Vector3* e1, Vector3* e2, Vector3* c1, Vector3* c2, float t, Vector3* out);
- float evalBezier1D(float e1, float e2, float c1, float c2, float t);
- float evalBezier1D_dt(float e1, float e2, float c1, float c2, float t);
- float evalBezier1D_ddt(float e1, float e2, float c1, float c2, float t);
- float evalQBezier1D(float e1, float e2, float c1, float t);
- void evalQBezier2D3p(Vector2* e1, Vector2* e2, Vector2* c1, float t, Vector2* out);
- void evalQBezier3p(Vector3* e1, Vector3* e2, Vector3* c1, float t, Vector3* out);
- int boxDisjoint3p(const AABB3* a, const AABB3* b);
- int boxOverlaps3p(const AABB3* a, const AABB3* b);
- 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);
- void boxCenter3p(const AABB3* b, Vector3* out);
- Vector2 boxSize2(const AABB2 b);
- Vector3 boxSize3(const AABB3 b);
- void boxSize2p(const AABB2* b, Vector2* out);
- void boxSize3p(const AABB3* b, Vector3* out);
- void boxExpandTo3p(AABB3* b, Vector3* p);
- void boxExpandTo3(AABB3* b, Vector3 p);
- int boxClipRay(AABB3* b, Ray3 r, Line3* out);
- 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);
- int boxDisjoint2p(const AABB2* a, const AABB2* b);
- int boxOverlaps2p(const AABB2* a, const AABB2* b);
- int boxContainsPoint2p(const AABB2* b, const Vector2* p);
- void boxCenter2p(const AABB2* b, Vector2* out);
- void boxSize2p(const AABB2* b, Vector2* out);
- void boxQuadrant2p(const AABB2* in, char ix, char iy, AABB2* out);
- 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);
- void boxSize2ip(const AABB2i* b, Vector2* out);
- void boxQuadrant2ip(const AABB2i* in, char ix, char iy, AABB2i* out);
- void quadCenter2p(const Quad2* in, Vector2* out);
- void quadRoundOutward2p(const Quad2* in, Quad2i* out);
- void quadRoundInward2p(const Quad2* in, Quad2i* out);
- float evalCatmullRom1D(float t, float a, float b, float c, float d);
- Vector2 evalCatmullRom2D(float t, Vector2 a, Vector2 b, Vector2 c, Vector2 d);
- Vector3 evalCatmullRom3D(float t, Vector3 a, Vector3 b, Vector3 c, Vector3 d);
- float evalCatmullRom1D_dt(float t, float a, float b, float c, float d);
- Vector2 evalCatmullRom2D_dt(float t, Vector2 a, Vector2 b, Vector2 c, Vector2 d);
- Vector3 evalCatmullRom3D_dt(float t, Vector3 a, Vector3 b, Vector3 c, Vector3 d);
- float evalCatmullRom1D_both(float t, float a, float b, float c, float d, float* dt);
- Vector2 evalCatmullRom2D_both(float t, Vector2 a, Vector2 b, Vector2 c, Vector2 d, Vector2* dt);
- Vector3 evalCatmullRom3D_both(float t, Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3* dt);
- float evalCubicHermite1D(float t, float p0, float p1, float m0, float m1);
- Vector2 evalCubicHermite2D(float t, Vector2 p0, Vector2 p1, Vector2 m0, Vector2 m1);
- Vector3 evalCubicHermite3D(float t, Vector3 p0, Vector3 p1, Vector3 m0, Vector3 m1);
- Quaternion qFromRTheta(Vector3 r, float theta);
- void qToRTheta(Quaternion q, Vector3* r, float* theta);
- Quaternion qAdd(Quaternion l, Quaternion r);
- Quaternion qSub(Quaternion l, Quaternion r);
- Quaternion qScale(Quaternion q, float s);
- Quaternion qMul(Quaternion l, Quaternion r);
- Quaternion qDiv(Quaternion n, Quaternion d);
- Quaternion qRot(Quaternion l, Quaternion r);
- Vector3 qRot3(Vector3 a, Quaternion r);
- Vector2 qRot2(Vector2 a, Quaternion r);
- Quaternion qConj(Quaternion q);
- Quaternion qInv(Quaternion q);
- Quaternion qNorm(Quaternion q);
- Quaternion qSlerp(Quaternion a, Quaternion b, float t);
- Quaternion qNlerp(Quaternion a, Quaternion b, float t);
- float qAngleBetween(Quaternion a, Quaternion b);
- float qMod(Quaternion q);
- float qMag(Quaternion q);
- float qLen(Quaternion q);
- Quaternion qFromBasis(Vector3 bx, Vector3 by, Vector3 bz);
- void qNonUnitToMatrix(Quaternion q, Matrix* out);
- void qUnitToMatrix3(Quaternion q, Matrix3* out);
- void qUnitToMatrix(Quaternion q, Matrix* out);
- int rasterizeLine2d(Vector2 pa, Vector2 pb, float cellSize, int (*found)(void* userData, int64_t x, int64_t y), void* userData);
- int rasterizeFatLine2d(Vector2 pa, Vector2 pb, float width, float cellSize, int (*found)(void* userData, int64_t x, int64_t y), void* userData);
- #endif // __c3dlas_h__
|