21#define B3_PI 3.14159265359f
24#define B3_DEG_TO_RAD 0.01745329251f
27#define B3_RAD_TO_DEG 57.2957795131f
30#define B3_MIN_SCALE 0.01f
70#if defined( BOX3D_DOUBLE_PRECISION )
118static const b3Vec3 b3Vec3_zero = { 0.0f, 0.0f, 0.0f };
119static const b3Vec3 b3Vec3_one = { 1.0f, 1.0f, 1.0f };
120static const b3Vec3 b3Vec3_axisX = { 1.0f, 0.0f, 0.0f };
121static const b3Vec3 b3Vec3_axisY = { 0.0f, 1.0f, 0.0f };
122static const b3Vec3 b3Vec3_axisZ = { 0.0f, 0.0f, 1.0f };
123static const b3Quat b3Quat_identity = { { 0.0f, 0.0f, 0.0f }, 1.0f };
124static const b3Transform b3Transform_identity = { { 0.0f, 0.0f, 0.0f }, { { 0.0f, 0.0f, 0.0f }, 1.0f } };
126 { 0.0f, 0.0f, 0.0f },
127 { 0.0f, 0.0f, 0.0f },
128 { 0.0f, 0.0f, 0.0f },
130static const b3Matrix3 b3Mat3_identity = {
131 { 1.0f, 0.0f, 0.0f },
132 { 0.0f, 1.0f, 0.0f },
133 { 0.0f, 0.0f, 1.0f },
137static const b3Pos b3Pos_zero = { 0.0f, 0.0f, 0.0f };
138static const b3WorldTransform b3WorldTransform_identity = { { 0.0f, 0.0f, 0.0f }, { { 0.0f, 0.0f, 0.0f }, 1.0f } };
143 return a < b ? a : b;
149 return a > b ? a : b;
155 return a < lower ? lower : ( upper < a ? upper : a );
164 return a < 0 ? -a : a;
170 return a < b ? a : b;
176 return a > b ? a : b;
182 return a < lower ? lower : ( upper < a ? upper : a );
188 return ( 1.0f - alpha ) * a + alpha * b;
202B3_INLINE
float b3Sin(
float radians )
209B3_INLINE
float b3Cos(
float radians )
219 return remainderf( radians, 2.0f *
B3_PI );
225 return B3_LITERAL(
b3Vec3 ){ a.x + b.x, a.y + b.y, a.z + b.z };
231 return B3_LITERAL(
b3Vec3 ){ a.x - b.x, a.y - b.y, a.z - b.z };
237 return B3_LITERAL(
b3Vec3 ){ a.x * b.x, a.y * b.y, a.z * b.z };
243 return B3_LITERAL(
b3Vec3 ){ -a.x, -a.y, -a.z };
249 return a.x * b.x + a.y * b.y + a.z * b.z;
255 return sqrtf(
b3Dot( v, v ) );
261 return a.x * a.x + a.y * a.y + a.z * a.z;
267 b3Vec3 dv = { b.x - a.x, b.y - a.y, b.z - a.z };
274 b3Vec3 dv = { b.x - a.x, b.y - a.y, b.z - a.z };
275 return dv.x * dv.x + dv.y * dv.y + dv.z * dv.z;
281 float lengthSquared = a.x * a.x + a.y * a.y + a.z * a.z;
283 if ( lengthSquared > 1000.0f * FLT_MIN )
285 float s = 1.0f / sqrtf( lengthSquared );
286 b3Vec3 u = { s * a.x, s * a.y, s * a.z };
290 return B3_LITERAL(
b3Vec3 ){ 0.0f, 0.0f, 0.0f };
298 if ( *length < FLT_EPSILON )
303 float invLength = 1.0f / *length;
304 b3Vec3 n = { invLength * a.x, invLength * a.y, invLength * a.z };
315 if ( a.x < -0.5f || 0.5f < a.x )
317 p = B3_LITERAL(
b3Vec3 ){ a.y, -a.x, 0.0f };
321 p = B3_LITERAL(
b3Vec3 ){ 0.0f, a.z, -a.y };
330 float aa =
b3Dot( a, a );
331 return b3AbsFloat( 1.0f - aa ) < 100.0f * FLT_EPSILON;
337 return B3_LITERAL(
b3Vec3 ){ a.x + s * b.x, a.y + s * b.y, a.z + s * b.z };
343 return B3_LITERAL(
b3Vec3 ){ a.x - s * b.x, a.y - s * b.y, a.z - s * b.z };
349 return B3_LITERAL(
b3Vec3 ){ s * a.x, s * a.y, s * a.z };
356 c.x = a.y * b.z - a.z * b.y;
357 c.y = a.z * b.x - a.x * b.z;
358 c.z = a.x * b.y - a.y * b.x;
365 B3_ASSERT( 0.0f <= alpha && alpha <= 1.0f );
368 ( 1.0f - alpha ) * a.x + alpha * b.x,
369 ( 1.0f - alpha ) * a.y + alpha * b.y,
370 ( 1.0f - alpha ) * a.z + alpha * b.z,
389 return B3_LITERAL(
b3Vec3 ){
399 return B3_LITERAL(
b3Vec3 ){
400 a.x >= 0.0f ? 1.0f : -1.0f,
401 a.y >= 0.0f ? 1.0f : -1.0f,
402 a.z >= 0.0f ? 1.0f : -1.0f,
409 return B3_LITERAL(
b3Vec3 ){
419 return B3_LITERAL(
b3Vec3 ){
449 float qq = q.v.x * q.v.x + q.v.y * q.v.y + q.v.z * q.v.z + q.s * q.s;
450 return 1.0f - 20.0f * FLT_EPSILON < qq && qq < 1.0f + 20.0f * FLT_EPSILON;
478 return a.v.x * b.v.x + a.v.y * b.v.y + a.v.z * b.v.z + a.s * b.s;
487 b3Quat q = { t3, q1.s * q2.s -
b3Dot( q1.v, q2.v ) };
498 b3Quat q = { t3, q1.s * q2.s +
b3Dot( q1.v, q2.v ) };
505 return B3_LITERAL(
b3Quat ){ { -q.v.x, -q.v.y, -q.v.z }, q.s };
511 return B3_LITERAL(
b3Quat ){ { -q.v.x, -q.v.y, -q.v.z }, -q.s };
518 if ( lengthSq > 1000.0f * FLT_MIN )
520 float s = 1.0f / sqrtf( lengthSq );
521 b3Quat qn = { { s * q.v.x, s * q.v.y, s * q.v.z }, s * q.s };
525 return b3Quat_identity;
533 b3Quat q = { { cs.sine * axis.x, cs.sine * axis.y, cs.sine * axis.z }, cs.
cosine };
540 float length = sqrtf( q.v.x * q.v.x + q.v.y * q.v.y + q.v.z * q.v.z );
541 *radians = 2.0f *
b3Atan2( length, q.s );
544 float invLength = 1.0f / length;
545 b3Vec3 axis = { invLength * q.v.x, invLength * q.v.y, invLength * q.v.z };
555 float length = sqrtf( q.v.x * q.v.x + q.v.y * q.v.y + q.v.z * q.v.z );
556 return 2.0f *
b3Atan2( length, q.s );
570 float twist = q.s < 0.0f ?
b3Atan2( -q.v.z, -q.s ) :
b3Atan2( q.v.z, q.s );
580 float x = sqrtf( q.v.z * q.v.z + q.s * q.s );
581 float y = sqrtf( q.v.x * q.v.x + q.v.y * q.v.y );
582 float swing = 2.0f *
b3Atan2( y, x );
593 q1 = B3_LITERAL(
b3Quat ){ { -q1.v.x, -q1.v.y, -q1.v.z }, -q1.s };
597 q.v =
b3Lerp( q1.v, q2.v, alpha );
598 q.s = ( 1.0f - alpha ) * q1.s + alpha * q2.s;
638 return b3Add( rv, t.p );
654 return B3_LITERAL(
b3Pos ){ v.x, v.y, v.z };
660 return B3_LITERAL(
b3Vec3 ){ (float)p.x, (
float)p.y, (float)p.z };
669#if defined( BOX3D_DOUBLE_PRECISION )
671 return (
double)f > x ? nextafterf( f, -FLT_MAX ) : f;
680#if defined( BOX3D_DOUBLE_PRECISION )
682 return (
double)f < x ? nextafterf( f, FLT_MAX ) : f;
691 return B3_LITERAL(
b3Vec3 ){ (float)( a.x - b.x ), (float)( a.y - b.y ), (float)( a.z - b.z ) };
697 return B3_LITERAL(
b3Pos ){ p.x + d.x, p.y + d.y, p.z + d.z };
703 return B3_LITERAL(
b3Pos ){
704 ( 1.0f - t ) * a.x + t * b.x,
705 ( 1.0f - t ) * a.y + t * b.y,
706 ( 1.0f - t ) * a.z + t * b.z,
714 return B3_LITERAL(
b3Pos ){ t.p.x + r.x, t.p.y + r.y, t.p.z + r.z };
720 b3Vec3 d = { (float)( p.x - t.p.x ), (float)( p.y - t.p.y ), (float)( p.z - t.p.z ) };
729 b3Vec3 d = { (float)( B.p.x - A.p.x ), (float)( B.p.y - A.p.y ), (float)( B.p.z - A.p.z ) };
740 C.p = B3_LITERAL(
b3Pos ){ A.p.x + r.x, A.p.y + r.y, A.p.z + r.z };
749 r.p = B3_LITERAL(
b3Vec3 ){ (float)( t.p.x - base.x ), (float)( t.p.y - base.y ), (float)( t.p.z - base.z ) };
771 out.upperBound.x =
b3RoundUpFloat( origin.x + localBox.upperBound.x );
772 out.upperBound.y =
b3RoundUpFloat( origin.y + localBox.upperBound.y );
773 out.upperBound.z =
b3RoundUpFloat( origin.z + localBox.upperBound.z );
787 m.cx.x * a.x + m.cy.x * a.y + m.cz.x * a.z,
788 m.cx.y * a.x + m.cy.y * a.y + m.cz.y * a.z,
789 m.cx.z * a.x + m.cy.z * a.y + m.cz.z * a.z,
798 { -a.cx.x, -a.cx.y, -a.cx.z },
799 { -a.cy.x, -a.cy.y, -a.cy.z },
800 { -a.cz.x, -a.cz.y, -a.cz.z },
809 { a.cx.x + b.cx.x, a.cx.y + b.cx.y, a.cx.z + b.cx.z },
810 { a.cy.x + b.cy.x, a.cy.y + b.cy.y, a.cy.z + b.cy.z },
811 { a.cz.x + b.cz.x, a.cz.y + b.cz.y, a.cz.z + b.cz.z },
820 { a.cx.x - b.cx.x, a.cx.y - b.cx.y, a.cx.z - b.cx.z },
821 { a.cy.x - b.cy.x, a.cy.y - b.cy.y, a.cy.z - b.cy.z },
822 { a.cz.x - b.cz.x, a.cz.y - b.cz.y, a.cz.z - b.cz.z },
830 { s * a.cx.x, s * a.cx.y, s * a.cx.z },
831 { s * a.cy.x, s * a.cy.y, s * a.cy.z },
832 { s * a.cz.x, s * a.cz.y, s * a.cz.z },
851 out.cx = B3_LITERAL(
b3Vec3 ){ m.cx.x, m.cy.x, m.cz.x };
852 out.cy = B3_LITERAL(
b3Vec3 ){ m.cx.y, m.cy.y, m.cz.y };
853 out.cz = B3_LITERAL(
b3Vec3 ){ m.cx.z, m.cy.z, m.cz.z };
861 float det =
b3Det( m );
864 float invDet = 1.0f / det;
880 float det =
b3Det( m );
883 float invDet = 1.0f / det;
890 invDet *
b3Dot( s.cx, a ),
891 invDet *
b3Dot( s.cy, a ),
892 invDet *
b3Dot( s.cz, a ),
904 float det =
b3Det( m );
907 float invDet = 1.0f / det;
922 out.cx =
b3Abs( m.cx );
923 out.cy =
b3Abs( m.cy );
924 out.cz =
b3Abs( m.cz );
934 float xx = q.v.x * q.v.x;
935 float yy = q.v.y * q.v.y;
936 float zz = q.v.z * q.v.z;
937 float xy = q.v.x * q.v.y;
938 float xz = q.v.x * q.v.z;
939 float xw = q.v.x * q.s;
940 float yz = q.v.y * q.v.z;
941 float yw = q.v.y * q.s;
942 float zw = q.v.z * q.s;
945 { 1.0f - 2.0f * ( yy + zz ), 2.0f * ( xy + zw ), 2.0f * ( xz - yw ) },
946 { 2.0f * ( xy - zw ), 1.0f - 2.0f * ( xx + zz ), 2.0f * ( yz + xw ) },
947 { 2.0f * ( xz + yw ), 2.0f * ( yz - xw ), 1.0f - 2.0f * ( xx + yy ) },
959 b3AABB a = { points[0], points[0] };
960 for (
int i = 1; i < count; ++i )
962 a.lowerBound =
b3Min( a.lowerBound, points[i] );
963 a.upperBound =
b3Max( a.upperBound, points[i] );
966 b3Vec3 r = { radius, radius, radius };
967 a.lowerBound =
b3Sub( a.lowerBound, r );
968 a.upperBound =
b3Add( a.upperBound, r );
976 if ( a.lowerBound.x > b.lowerBound.x || b.upperBound.x > a.upperBound.x )
978 if ( a.lowerBound.y > b.lowerBound.y || b.upperBound.y > a.upperBound.y )
980 if ( a.lowerBound.z > b.lowerBound.z || b.upperBound.z > a.upperBound.z )
989 b3Vec3 delta =
b3Sub( a.upperBound, a.lowerBound );
990 return 2.0f * ( delta.x * delta.y + delta.y * delta.z + delta.z * delta.x );
996 return b3MulSV( 0.5f,
b3Add( a.upperBound, a.lowerBound ) );
1002 return b3MulSV( 0.5f,
b3Sub( a.upperBound, a.lowerBound ) );
1009 out.lowerBound =
b3Min( a.lowerBound, b.lowerBound );
1010 out.upperBound =
b3Max( a.upperBound, b.upperBound );
1017 b3Vec3 radius = { extension, extension, extension };
1020 out.lowerBound =
b3Sub( a.lowerBound, radius );
1021 out.upperBound =
b3Add( a.upperBound, radius );
1029 if ( a.upperBound.x < b.lowerBound.x || a.lowerBound.x > b.upperBound.x )
1031 if ( a.upperBound.y < b.lowerBound.y || a.lowerBound.y > b.upperBound.y )
1033 if ( a.upperBound.z < b.lowerBound.z || a.lowerBound.z > b.upperBound.z )
1055 return b3Clamp( point, a.lowerBound, a.upperBound );
1140B3_FORCE_INLINE
b3Vec3& operator*=(
b3Vec3& a,
float s )
1151 return { -a.x, -a.y, -a.z };
1157 return { s * a.x, s * a.y, s * a.z };
1163 return { s * a.x, s * a.y, s * a.z };
1169 return { a.x * b.x, a.y * b.y, a.z * b.z };
1175 return { a.x + b.x, a.y + b.y, a.z + b.z };
1181 return { a.x - b.x, a.y - b.y, a.z - b.z };
1184#if defined( BOX3D_DOUBLE_PRECISION )
1189 return { a.x + b.x, a.y + b.y, a.z + b.z };
1195 return { a.x - b.x, a.y - b.y, a.z - b.z };
1201 return { (float)( a.x - b.x ), (float)( a.y - b.y ), (float)( a.z - b.z ) };
#define B3_ASSERT(condition)
Assert that a condition is true.
Definition base.h:127
#define B3_VALIDATE(...)
Validation is typically only enabled in debug builds.
Definition base.h:140
float cosine
cosine and sine
Definition math_functions.h:52
float b3Sin(float radians)
Definition math_functions.h:202
b3AABB b3AABB_Union(b3AABB a, b3AABB b)
Get the union of two axis-aligned bounding boxes.
Definition math_functions.h:1006
b3Pos b3ToPos(b3Vec3 v)
Convert a vector to a world position.
Definition math_functions.h:652
b3AABB b3MakeAABB(const b3Vec3 *points, int count, float radius)
Get the AABB of a point cloud.
Definition math_functions.h:956
int b3MinInt(int a, int b)
Definition math_functions.h:141
bool b3IsValidPlane(b3Plane a)
Is this a valid plane? Normal is a unit vector. Not Nan or infinity.
b3Vec3 b3Clamp(b3Vec3 a, b3Vec3 lower, b3Vec3 upper)
Component-wise clamped value.
Definition math_functions.h:427
b3Pos b3TransformWorldPoint(b3WorldTransform t, b3Vec3 p)
Transform a local point to a world position. Rotation in float, translation in double.
Definition math_functions.h:711
bool b3AABB_Contains(b3AABB a, b3AABB b)
Does a fully contain b?
Definition math_functions.h:974
b3Vec3 b3InvRotateVector(b3Quat q, b3Vec3 v)
Inverse rotate a vector.
Definition math_functions.h:465
bool b3IsValidAABB(b3AABB a)
Is this a valid bounding box? Not Nan or infinity. Upper bound greater than or equal to lower bound.
bool b3IsNormalized(b3Vec3 a)
Is a vector normalized? In other words, does it have unit length?
Definition math_functions.h:328
b3Vec3 b3ToVec3(b3Pos p)
Lossy conversion of a world position to a float vector.
Definition math_functions.h:658
B3_FORCE_INLINE b3Matrix3 b3MakeMatrixFromQuat(b3Quat q)
Make a matrix from a quaternion.
Definition math_functions.h:932
b3SegmentDistanceResult b3SegmentDistance(b3Vec3 p1, b3Vec3 q1, b3Vec3 p2, b3Vec3 q2)
Compute the closest points on two line segments.
bool b3IsNormalizedQuat(b3Quat q)
Does the supplied quaternion have unit length?
Definition math_functions.h:447
float b3AABB_Area(b3AABB a)
Get the surface area of an axis-aligned bounding box.
Definition math_functions.h:987
b3Matrix3 b3InvertMatrix(b3Matrix3 m)
General matrix inverse.
Definition math_functions.h:859
b3Transform b3ToRelativeTransform(b3WorldTransform t, b3Pos base)
Shift a world transform into the frame of a base position.
Definition math_functions.h:745
b3Matrix3 b3InvertT(b3Matrix3 m)
Invert a matrix.
Definition math_functions.h:902
float b3Cos(float radians)
Definition math_functions.h:209
b3Matrix3 b3SubMM(b3Matrix3 a, b3Matrix3 b)
Matrix subtraction.
Definition math_functions.h:817
b3Vec3 b3Sub(b3Vec3 a, b3Vec3 b)
Vector subtraction.
Definition math_functions.h:229
#define B3_MIN_SCALE
Minimum scale used for scaling collision meshes, etc.
Definition math_functions.h:30
b3WorldTransform b3MulWorldTransforms(b3WorldTransform A, b3Transform B)
Compose a world transform with a local transform.
Definition math_functions.h:735
b3Vec3 b3Pos
In single precision mode these types are the same.
Definition math_functions.h:90
b3Quat b3NegateQuat(b3Quat q)
Component-wise quaternion negation.
Definition math_functions.h:509
b3Transform b3InvMulWorldTransforms(b3WorldTransform A, b3WorldTransform B)
Relative transform of frame B in frame A. The narrow phase boundary.
Definition math_functions.h:725
float b3Dot(b3Vec3 a, b3Vec3 b)
Vector dot product.
Definition math_functions.h:247
b3Vec3 b3ClosestPointToAABB(b3Vec3 point, b3AABB a)
Get the closest point on an axis-aligned bounding box.
Definition math_functions.h:1053
b3Matrix3 b3Steiner(float mass, b3Vec3 origin)
Get the inertia tensor of an offset point.
b3Vec3 b3Solve3(b3Matrix3 m, b3Vec3 a)
Solve a matrix equation.
Definition math_functions.h:878
b3Quat b3InvMulQuat(b3Quat q1, b3Quat q2)
Compute a relative quaternion.
Definition math_functions.h:493
float b3DistanceSquared(b3Vec3 a, b3Vec3 b)
Squared distance between two points.
Definition math_functions.h:272
float b3AbsFloat(float a)
Definition math_functions.h:162
b3Matrix3 b3NegateMat3(b3Matrix3 a)
Negate a matrix.
Definition math_functions.h:795
b3Vec3 b3GetLengthAndNormalize(float *length, b3Vec3 a)
Normalize a vector and return the length.
Definition math_functions.h:295
b3Quat b3ComputeQuatBetweenUnitVectors(b3Vec3 v1, b3Vec3 v2)
Find a quaternion that rotates one vector to another.
b3Matrix3 b3Transpose(b3Matrix3 m)
Matrix transpose.
Definition math_functions.h:848
float b3UnwindAngle(float radians)
Convert any angle into the range [-pi, pi].
Definition math_functions.h:216
b3Matrix3 b3AbsMatrix3(b3Matrix3 m)
Get the component-wise absolute value of a matrix.
Definition math_functions.h:919
b3Vec3 b3MulMV(b3Matrix3 m, b3Vec3 a)
Multiply a matrix times a column vector.
Definition math_functions.h:784
b3Transform b3MulTransforms(b3Transform a, b3Transform b)
Multiply two transforms.
Definition math_functions.h:606
float b3GetQuatAngle(b3Quat q)
Get the angle for a quaternion in radians.
Definition math_functions.h:553
b3AABB b3AABB_Transform(b3Transform transform, b3AABB a)
Transform an axis-aligned bounding box.
Definition math_functions.h:1043
float b3DotQuat(b3Quat a, b3Quat b)
Compute dot product of two quaternions. Useful for polarity tests.
Definition math_functions.h:476
b3Vec3 b3AABB_Center(b3AABB a)
Get the center of an axis-aligned bounding box.
Definition math_functions.h:994
float b3RoundUpFloat(double x)
Narrow a world coordinate to float, rounding toward positive infinity.
Definition math_functions.h:678
float b3Distance(b3Vec3 a, b3Vec3 b)
Distance between two points.
Definition math_functions.h:265
b3Quat b3MakeQuatFromMatrix(const b3Matrix3 *m)
Extract a quaternion from a rotation matrix.
b3Pos b3OffsetPos(b3Pos p, b3Vec3 d)
p + d
Definition math_functions.h:695
float b3Atan2(float y, float x)
Compute an approximate arctangent in the range [-pi, pi] This is hand coded for cross-platform determ...
b3CosSin b3ComputeCosSin(float radians)
Compute the cosine and sine of an angle in radians.
b3Vec3 b3Add(b3Vec3 a, b3Vec3 b)
Vector addition.
Definition math_functions.h:223
b3Vec3 b3SubPos(b3Pos a, b3Pos b)
a - b, demoted to float. The primary precision boundary operation.
Definition math_functions.h:689
bool b3IsValidQuat(b3Quat q)
Is this a valid quaternion? Not NaN or infinity. Is normalized.
b3Vec3 b3Max(b3Vec3 a, b3Vec3 b)
Component-wise maximum value.
Definition math_functions.h:417
b3Quat b3NLerp(b3Quat q1, b3Quat q2, float alpha)
Linearly interpolate and normalize between two quaternions.
Definition math_functions.h:588
b3Matrix3 b3AddMM(b3Matrix3 a, b3Matrix3 b)
Matrix addition.
Definition math_functions.h:806
b3Vec3 b3MulSV(float s, b3Vec3 a)
s * a
Definition math_functions.h:347
b3Vec3 b3MulAdd(b3Vec3 a, float s, b3Vec3 b)
a + s * b
Definition math_functions.h:335
b3SegmentDistanceResult b3LineDistance(b3Vec3 p1, b3Vec3 d1, b3Vec3 p2, b3Vec3 d2)
Compute the closest points on two infinite lines.
int b3MaxInt(int a, int b)
Definition math_functions.h:147
b3Vec3 b3RotateVector(b3Quat q, b3Vec3 v)
Rotate a vector.
Definition math_functions.h:454
b3Vec3 b3Neg(b3Vec3 a)
Vector negation.
Definition math_functions.h:241
b3Vec3 b3Sign(b3Vec3 a)
Component-wise -1 or 1 (1 if zero).
Definition math_functions.h:397
b3Vec3 b3SafeScale(b3Vec3 a)
Create a safe scaling value for scaling collision.
Definition math_functions.h:438
b3Vec3 b3Lerp(b3Vec3 a, b3Vec3 b, float alpha)
Linearly interpolate between two vectors.
Definition math_functions.h:363
b3Vec3 b3Mul(b3Vec3 a, b3Vec3 b)
Vector component-wise multiplication.
Definition math_functions.h:235
bool b3IsBoundedAABB(b3AABB a)
Is this AABB reasonably close to the origin? See B3_HUGE.
b3Vec3 b3InvTransformPoint(b3Transform t, b3Vec3 v)
Inverse transform a point.
Definition math_functions.h:642
#define B3_PI
https://en.wikipedia.org/wiki/Pi
Definition math_functions.h:21
float b3LerpFloat(float a, float b, float alpha)
Interpolate a scalar.
Definition math_functions.h:186
b3Vec3 b3Blend2(float s, b3Vec3 a, float t, b3Vec3 b)
Blend two vectors: s * a + t * b.
Definition math_functions.h:376
B3_FORCE_INLINE b3Transform b3InvMulTransforms(b3Transform a, b3Transform b)
Creates a transform that converts a local point in frame B to a local point in frame A.
Definition math_functions.h:617
bool b3IsValidTransform(b3Transform a)
Is this a valid transform? Not NaN or infinity. Is normalized.
bool b3IsValidMatrix3(b3Matrix3 a)
Is this a valid matrix? Not NaN or infinity.
float b3GetTwistAngle(b3Quat q)
Twist angle around the z-axis, used for twist limit and revolute angle limit.
Definition math_functions.h:566
int b3ClampInt(int a, int lower, int upper)
Definition math_functions.h:153
b3Vec3 b3PointToSegmentDistance(b3Vec3 a, b3Vec3 b, b3Vec3 q)
Compute the closest point on the segment a-b to the target q.
b3AABB b3AABB_Inflate(b3AABB a, float extension)
Add uniform padding to an axis-aligned bounding box.
Definition math_functions.h:1015
b3Vec3 b3GetAxisAngle(float *radians, b3Quat q)
Get the axis and angle from a quaternion. Assumes the quaternion is normalized.
Definition math_functions.h:538
b3Quat b3Conjugate(b3Quat q)
Quaternion conjugate (cheap inverse).
Definition math_functions.h:503
bool b3IsValidPosition(b3Pos p)
Is this a valid world position? Not NaN or infinity.
float b3Det(b3Matrix3 m)
Compute the determinant of a 3-by-3 matrix.
Definition math_functions.h:778
float b3GetSwingAngle(b3Quat q)
Swing angle used for cone limit.
Definition math_functions.h:577
b3AABB b3OffsetAABB(b3AABB localBox, b3Pos origin)
Translate a local AABB by a world origin, rounding outward so the float box always contains the doubl...
Definition math_functions.h:765
float b3ClampFloat(float a, float lower, float upper)
Definition math_functions.h:180
bool b3AABB_Overlaps(b3AABB a, b3AABB b)
Do two axis-aligned boxes overlap?
Definition math_functions.h:1026
b3Transform b3InvertTransform(b3Transform t)
Get the inverse of a transform.
Definition math_functions.h:626
float b3MaxFloat(float a, float b)
Definition math_functions.h:174
b3Vec3 b3Perp(b3Vec3 a)
Get a unit vector that is perpendicular to the supplied vector.
Definition math_functions.h:309
b3Vec3 b3MulSub(b3Vec3 a, float s, b3Vec3 b)
a - s * b
Definition math_functions.h:341
b3Vec3 b3InvTransformWorldPoint(b3WorldTransform t, b3Pos p)
Transform a world position to a local point. One double subtraction, then float.
Definition math_functions.h:718
bool b3IsValidFloat(float a)
Is this a valid number? Not NaN or infinity.
bool b3IsValidWorldTransform(b3WorldTransform t)
Is this a valid world transform? Not NaN or infinity. Rotation is normalized.
bool b3IsSaneAABB(b3AABB a)
Is this AABB valid and reasonable?
b3Vec3 b3Normalize(b3Vec3 a)
Normalize a vector. Returns a zero vector if the input vector is very small.
Definition math_functions.h:279
b3Vec3 b3TransformPoint(b3Transform t, b3Vec3 v)
Transform a point.
Definition math_functions.h:635
b3Matrix3 b3MulMM(b3Matrix3 a, b3Matrix3 b)
Matrix multiplication.
Definition math_functions.h:838
b3Transform b3WorldTransform
In single precision mode these types are the same.
Definition math_functions.h:93
float b3RoundDownFloat(double x)
Narrow a world coordinate to float, rounding toward negative infinity.
Definition math_functions.h:667
b3Quat b3MakeQuatFromAxisAngle(b3Vec3 axis, float radians)
Make a quaternion that is equivalent to rotating around an axis by a specified angle.
Definition math_functions.h:529
b3Vec3 b3AABB_Extents(b3AABB a)
Get the extents (half-widths) of an axis-aligned bounding box.
Definition math_functions.h:1000
bool b3IsValidVec3(b3Vec3 a)
Is this a valid vector? Not NaN or infinity.
b3Vec3 b3Cross(b3Vec3 a, b3Vec3 b)
https://en.wikipedia.org/wiki/Cross_product
Definition math_functions.h:353
b3Quat b3NormalizeQuat(b3Quat q)
Normalize a quaternion.
Definition math_functions.h:515
b3Pos b3LerpPosition(b3Pos a, b3Pos b, float t)
World position interpolation for sweeps and sampling.
Definition math_functions.h:701
b3Vec3 b3Min(b3Vec3 a, b3Vec3 b)
Component-wise minimum value.
Definition math_functions.h:407
b3WorldTransform b3MakeWorldTransform(b3Transform t)
Promote a float transform to a world transform. Lossless.
Definition math_functions.h:754
float b3LengthSquared(b3Vec3 a)
Vector length squared.
Definition math_functions.h:259
b3Quat b3MulQuat(b3Quat q1, b3Quat q2)
Multiply two quaternions.
Definition math_functions.h:482
float b3MinFloat(float a, float b)
Definition math_functions.h:168
b3Vec3 b3Abs(b3Vec3 a)
Component-wise absolute value.
Definition math_functions.h:387
b3Matrix3 b3MulSM(float s, b3Matrix3 a)
Multiply a matrix by a scalar, component-wise.
Definition math_functions.h:827
float b3Length(b3Vec3 v)
Vector length.
Definition math_functions.h:253
Axis aligned bounding box.
Definition math_functions.h:105
Cosine and sine pair.
Definition math_functions.h:50
A 3x3 matrix.
Definition math_functions.h:99
A plane.
Definition math_functions.h:113
A quaternion.
Definition math_functions.h:58
The closest points between to segments or infinite lines.
Definition math_functions.h:1060
A 2D vector.
Definition math_functions.h:34
A 3D vector.
Definition math_functions.h:41