Nudge Physics
A single file, header-only 3D physics library
|
General-Math Functions. Functions without the nm_ prefix take as arguments nudge structures (e.g. nudge::Transform), and some of them were present in the original nudge release. The other functions, the ones with the nm_ prefix, have been added to ease user experience, or to support some extended feature, and are more generic. More...
Functions | |
Transform * | nudge::Mat4WithoutScalingToTransform (Transform *Tout, const float *matrix16WithoutScaling) |
Converts a column-major 16-floats matrix without any scaling applied to a nudge::Transform. | |
Transform | nudge::Mat4WithoutScalingToTransform (const float *matrix16WithoutScaling) |
Converts a column-major 16-floats matrix without any scaling applied to a nudge::Transform. | |
float * | nudge::TransformToMat4 (float *matrix16Out, const Transform *T) |
Converts a nudge::Transform to a column-major 16-floats matrix. | |
void | nudge::TransformAssignToBody (context_t *c, unsigned body, Transform newT, float deltaTime, int16_t aux_body=-1) |
Assigns a new Transform to a body, and sets its linear and angular velocities based on the differences between the new transform and the old one: this is essential when manually moving bodies by changing their transform. | |
void | nudge::TransformAdvanceBodyFromVelocities (context_t *c, unsigned body, float deltaTime) |
Advances the body's transform based on its linear and angular velocities. | |
Transform | nudge::TransformSlerp (Transform T0, Transform T1, float time) |
Applies (spherical) lerp between T0 and T1. | |
Transform | nudge::TransformMul (Transform T0, Transform T1) |
Multiplies two transforms. | |
void | nudge::nm_QuatAdvance (float *__restrict qOut4, const float *__restrict q4, const float *__restrict angVel3, float halfTimeStep) |
Advances a quaternion given an angular velocity and a (small) time step. | |
float * | nudge::nm_QuatFromMat4 (float *__restrict result4, const float *__restrict m16) |
Turns the 3x3 submatrix of a 16-floats column-major matrix (without scaling applied) into a quaternion. | |
float * | nudge::nm_Mat4SetRotationFromQuat (float *__restrict result16, const float *__restrict q4) |
Replaces the 3x3 submatrix of a 16-floats column-major matrix with the 3x3 matrix representing the given quaternion. | |
float * | nudge::nm_QuatFromMat3 (float *__restrict result4, const float *__restrict m9) |
Turns the 3x3 9-floats column-major rotation matrix (without scaling applied) into a quaternion. | |
float * | nudge::nm_Mat3FromQuat (float *__restrict result9, const float *__restrict q4) |
Converts the given quaternion the a 3x3 9-floats column-major rotation matrix. | |
void | nudge::nm_QuatGetAngularVelocity (float *__restrict angVel3, const float *newQuat4, const float *oldQuat4, float halfTimeStep) |
Given an old and a new quaternion and a small time step, it calculates the angular velocities. | |
float * | nudge::nm_QuatSlerp (float *__restrict result4, const float *__restrict a4, const float *__restrict b4, float slerpTime_In_0_1, int normalizeResult4AfterLerp) |
Performs a spherical lerp between two quaternions (in 4-floats format) | |
float * | nudge::nm_QuatMul (float *qOut4, const float *a4, const float *b4) |
Multiplies two 4-floats quaternions. | |
void | nudge::nm_QuatNormalize (float *__restrict q4) |
normalizes a 4-floats quaternion in place | |
float * | nudge::nm_QuatFromAngleAxis (float *__restrict qOut4, float rfAngle, float rkAxisX, float rkAxisY, float rkAxisZ) |
Generates a 4-floats quaternion based on an orientation arouns an axis. | |
void | nudge::nm_QuatToAngleAxis (const float *__restrict q4, float *__restrict rfAngleOut1, float *__restrict rkAxisOut3) |
Calculates the angle-axis representation of the given 4-float quaternion. | |
float | nudge::nm_Vec3Normalize (float *__restrict v3) |
Normalizes a 3-floats vector in place. | |
float | nudge::nm_Vec3Normalized (float *__restrict v3Out, const float *__restrict v3) |
Get a normalizes copy of an input 3-floats vector. | |
float | nudge::nm_Vec3Dot (const float *__restrict a3, const float *__restrict b3) |
Computes the dot product between two 3-floats vectors. | |
float * | nudge::nm_Vec3Cross (float *__restrict vOut3, const float *__restrict a3, const float *__restrict b3) |
Computes the cross product between two 3-floats vectors. | |
float * | nudge::nm_QuatMulVec3 (float *__restrict vOut3, const float *__restrict q4, const float *__restrict vIn3) |
Transforms a 3-floats vector by a 4-floats quaternion. | |
float * | nudge::nm_QuatGetAxis (float *__restrict vOut3, const float *__restrict q4, float axisX, float axisY, float axisZ) |
Transforms a particular axis from the input quaternion space to word space. | |
float * | nudge::nm_QuatGetAxisX (float *__restrict axisOut3, const float *__restrict q4) |
float * | nudge::nm_QuatGetAxisY (float *__restrict axisOut3, const float *__restrict q4) |
float * | nudge::nm_QuatGetAxisZ (float *__restrict axisOut3, const float *__restrict q4) |
float * | nudge::nm_QuatRotate (float *__restrict qInOut4, float angle, float axisX, float axisY, float axisZ) |
Rotates an input 4-floats unit quaternion by an angle in radians around a specified axis. | |
float * | nudge::nm_Mat4Mul (float *result16, const float *ml16, const float *mr16) |
Multiplies two column-major 16-floats 4x4 matrices. | |
General-Math Functions. Functions without the nm_ prefix take as arguments nudge structures (e.g. nudge::Transform), and some of them were present in the original nudge release. The other functions, the ones with the nm_ prefix, have been added to ease user experience, or to support some extended feature, and are more generic.
Transform * nudge::Mat4WithoutScalingToTransform | ( | Transform * | Tout, |
const float * | matrix16WithoutScaling | ||
) |
Converts a column-major 16-floats matrix without any scaling applied to a nudge::Transform.
Tout | the output nudge::Transform |
matrix16WithoutScaling | the input column-major 16-floats matrix without any scaling applied |
Transform nudge::Mat4WithoutScalingToTransform | ( | const float * | matrix16WithoutScaling | ) |
Converts a column-major 16-floats matrix without any scaling applied to a nudge::Transform.
matrix16WithoutScaling | the input column-major 16-floats matrix without any scaling applied |
float * nudge::TransformToMat4 | ( | float * | matrix16Out, |
const Transform * | T | ||
) |
Converts a nudge::Transform to a column-major 16-floats matrix.
matrix16Out | the output column-major 16-floats matrix |
T | the input nudge::Transform |
void nudge::TransformAssignToBody | ( | context_t * | c, |
unsigned | body, | ||
Transform | newT, | ||
float | deltaTime, | ||
int16_t | aux_body = -1 |
||
) |
Assigns a new Transform to a body, and sets its linear and angular velocities based on the differences between the new transform and the old one: this is essential when manually moving bodies by changing their transform.
c | the nudge context |
body | the target body index |
newT | the new transform |
deltaTime | the (small) time difference in seconds (used to calculate linear and angular velocities: v = space/time) |
aux_body | [experimental] if the aux_body index is >=0, then additional linear and angular velocities are calculated and summed, so that the aux_body 'should' generate a 'dragging' effect on 'body' (the idea was to experiment with a kind of platform-convey effect that does not depend on friction only) |
void nudge::TransformAdvanceBodyFromVelocities | ( | context_t * | c, |
unsigned | body, | ||
float | deltaTime | ||
) |
Advances the body's transform based on its linear and angular velocities.
c | the nudge context |
body | the target body index |
deltaTime | the (small) time difference in seconds |
Applies (spherical) lerp between T0 and T1.
T0 | |
T1 | |
time | must be in the [0,1] interval |
Multiplies two transforms.
T0 | |
T1 |
void nudge::nm_QuatAdvance | ( | float *__restrict | qOut4, |
const float *__restrict | q4, | ||
const float *__restrict | angVel3, | ||
float | halfTimeStep | ||
) |
Advances a quaternion given an angular velocity and a (small) time step.
qOut4 | the resulting quaternion in 4-floats format |
q4 | the input quaternion in 4-floats format |
angVel3 | the angular velocity in 3-floats format |
halfTimeStep | the half of the delta time: must be small for this function to work |
float * nudge::nm_QuatFromMat4 | ( | float *__restrict | result4, |
const float *__restrict | m16 | ||
) |
Turns the 3x3 submatrix of a 16-floats column-major matrix (without scaling applied) into a quaternion.
result4 | the resulting quaternion in 4-floats format |
m16 | the input 16-floats column-major matrix (without scaling applied) |
float * nudge::nm_Mat4SetRotationFromQuat | ( | float *__restrict | result16, |
const float *__restrict | q4 | ||
) |
Replaces the 3x3 submatrix of a 16-floats column-major matrix with the 3x3 matrix representing the given quaternion.
result16 | the input/output 16-floats column-major matrix |
q4 | the input quaternion in 4-floats format |
float * nudge::nm_QuatFromMat3 | ( | float *__restrict | result4, |
const float *__restrict | m9 | ||
) |
Turns the 3x3 9-floats column-major rotation matrix (without scaling applied) into a quaternion.
result4 | the resulting quaternion in 4-floats format |
m9 | the input 9-floats column-major rotation matrix (without scaling applied) |
float * nudge::nm_Mat3FromQuat | ( | float *__restrict | result9, |
const float *__restrict | q4 | ||
) |
Converts the given quaternion the a 3x3 9-floats column-major rotation matrix.
result9 | the input/output 9-floats column-major rotation matrix |
q4 | the input quaternion in 4-floats format |
void nudge::nm_QuatGetAngularVelocity | ( | float *__restrict | angVel3, |
const float * | newQuat4, | ||
const float * | oldQuat4, | ||
float | halfTimeStep | ||
) |
Given an old and a new quaternion and a small time step, it calculates the angular velocities.
angVel3 | the resulting angular velocity between the two quaternions |
newQuat4 | the new quaternion |
oldQuat4 | the old quaternion |
halfTimeStep | half time step: must be small for this function to work |
float * nudge::nm_QuatSlerp | ( | float *__restrict | result4, |
const float *__restrict | a4, | ||
const float *__restrict | b4, | ||
float | slerpTime_In_0_1, | ||
int | normalizeResult4AfterLerp | ||
) |
Performs a spherical lerp between two quaternions (in 4-floats format)
result4 | the resulting quaternion |
a4 | the first quaternion |
b4 | the second quaternion |
slerpTime_In_0_1 | time in [0,1] interval |
normalizeResult4AfterLerp | if not zero, when the function performs a lerp (because a4 and b4 are close enough) the resulting quaternion is normalized (default: 1) |
float * nudge::nm_QuatMul | ( | float * | qOut4, |
const float * | a4, | ||
const float * | b4 | ||
) |
Multiplies two 4-floats quaternions.
qOut4 | the result |
a4 | the first input 4-floats quaternion |
b4 | the second input 4-floats quaternion |
void nudge::nm_QuatNormalize | ( | float *__restrict | q4 | ) |
normalizes a 4-floats quaternion in place
q4 | the input/output 4-floats quaternion |
float * nudge::nm_QuatFromAngleAxis | ( | float *__restrict | qOut4, |
float | rfAngle, | ||
float | rkAxisX, | ||
float | rkAxisY, | ||
float | rkAxisZ | ||
) |
Generates a 4-floats quaternion based on an orientation arouns an axis.
qOut4 | the result |
rfAngle | the input angle in radians |
rkAxisX | the first component of the (normalized) axis |
rkAxisY | the second component of the (normalized) axis |
rkAxisZ | the third component of the (normalized) axis |
void nudge::nm_QuatToAngleAxis | ( | const float *__restrict | q4, |
float *__restrict | rfAngleOut1, | ||
float *__restrict | rkAxisOut3 | ||
) |
Calculates the angle-axis representation of the given 4-float quaternion.
q4 | input quaternion |
rfAngleOut1 | output angle in radians |
rkAxisOut3 | output 3-floats vector |
float nudge::nm_Vec3Normalize | ( | float *__restrict | v3 | ) |
Normalizes a 3-floats vector in place.
v3 | the input/output 3-floats vector |
float nudge::nm_Vec3Normalized | ( | float *__restrict | v3Out, |
const float *__restrict | v3 | ||
) |
Get a normalizes copy of an input 3-floats vector.
v3Out | the output 3-floats vector |
v3 | the input 3-floats vector |
float nudge::nm_Vec3Dot | ( | const float *__restrict | a3, |
const float *__restrict | b3 | ||
) |
Computes the dot product between two 3-floats vectors.
a3 | the first input 3-floats vector |
b3 | the second input 3-floats vector |
float * nudge::nm_Vec3Cross | ( | float *__restrict | vOut3, |
const float *__restrict | a3, | ||
const float *__restrict | b3 | ||
) |
Computes the cross product between two 3-floats vectors.
vOut3 | the output 3-floats vector |
a3 | the first input 3-floats vector |
b3 | the second input 3-floats vector |
float * nudge::nm_QuatMulVec3 | ( | float *__restrict | vOut3, |
const float *__restrict | q4, | ||
const float *__restrict | vIn3 | ||
) |
Transforms a 3-floats vector by a 4-floats quaternion.
vOut3 | the output 3-floats vector |
q4 | the input 4-floats unit quaternion |
vIn3 | the input 3-floats vector |
float * nudge::nm_QuatGetAxis | ( | float *__restrict | vOut3, |
const float *__restrict | q4, | ||
float | axisX, | ||
float | axisY, | ||
float | axisZ | ||
) |
Transforms a particular axis from the input quaternion space to word space.
vOut3 | the output 3-floats vector |
q4 | the first input 4-floats unit quaternion |
axisX | the first component of the input axis |
axisY | the second component of the input axis |
axisZ | the third component of the input axis |
|
inline |
|
inline |
|
inline |
float * nudge::nm_QuatRotate | ( | float *__restrict | qInOut4, |
float | angle, | ||
float | axisX, | ||
float | axisY, | ||
float | axisZ | ||
) |
Rotates an input 4-floats unit quaternion by an angle in radians around a specified axis.
qInOut4 | the input/output 4-floats unit quaternion |
angle | the input angle in radians |
axisX | the first component of the input axis |
axisY | the second component of the input axis |
axisZ | the third component of the input axis |
float * nudge::nm_Mat4Mul | ( | float * | result16, |
const float * | ml16, | ||
const float * | mr16 | ||
) |
Multiplies two column-major 16-floats 4x4 matrices.
result16 | the resulting column-major 16-floats 4x4 matrix (can be the same as one of the other arguments) |
ml16 | the first column-major 16-floats 4x4 matrix (can be the same as one of the other arguments) |
mr16 | the second column-major 16-floats 4x4 matrix (can be the same as one of the other arguments) |