Nudge Physics
A single file, header-only 3D physics library
|
Set of functions regarding creation and removal of physic bodies. More...
Functions | |
unsigned | nudge::add_box (context_t *c, float mass, float hsizex, float hsizey, float hsizez, const Transform *T=NULL, const float comOffset[3]=NULL) |
Adds a new body to the simulation with a single box collider. | |
unsigned | nudge::add_box (context_t *c, float mass, float hsizex, float hsizey, float hsizez, const float *mMatrix16WithoutScaling, const float comOffset[3]=NULL) |
unsigned | nudge::add_sphere (context_t *c, float mass, float radius, const Transform *T=NULL, const float comOffset[3]=NULL) |
Adds a new body to the simulation with a single sphere collider. | |
unsigned | nudge::add_sphere (context_t *c, float mass, float radius, const float *mMatrix16WithoutScaling, const float comOffset[3]=NULL) |
unsigned | nudge::add_compound (context_t *c, float mass, float inertia[3], unsigned num_boxes, const float *hsizeTriplets, const Transform *boxOffsetTransforms, unsigned num_spheres, const float *radii, const Transform *sphereOffsetTransforms, const Transform *T=NULL, const float comOffset[3]=NULL, float *centerMeshAndRetrieveOldCenter3Out=NULL) |
Adds a new body to the simulation with a compound collider made up of num_boxes box colliders and num_spheres sphere colliders. | |
unsigned | nudge::add_compound (context_t *c, float mass, float inertia[3], unsigned num_boxes, const float *hsizeTriplets, const float *boxOffsetMatrices16WithoutScaling, unsigned num_spheres, const float *radii, const float *sphereOffsetMatrices16WithoutScaling, const float *mMatrix16WithoutScaling=NULL, const float comOffset[3]=NULL, float *centerMeshAndRetrieveOldCenter3Out=NULL) |
unsigned | nudge::add_clone (context_t *c, unsigned body_to_clone, float mass, const Transform *T=NULL, float scale_factor=1.f, const float newComOffsetInPreScaledUnits[3]=NULL) |
[Experimental] Adds a new body to the simulation cloning an existing body | |
unsigned | nudge::add_clone (context_t *c, unsigned body_to_clone, float mass, const float *mMatrix16WithoutScaling, float scale_factor=1.f, const float newComOffsetInPreScaledUnits[3]=NULL) |
void | nudge::remove_body (context_t *c, unsigned body) |
Removes a body from the simulation. | |
uint32_t | nudge::colliders_get_num_remaining_boxes (context_t *c) |
Return the number of box colliders that can still be added to the physic world. | |
uint32_t | nudge::colliders_get_num_remaining_spheres (context_t *c) |
Return the number of sphere colliders that can still be added to the physic world. | |
int | nudge::can_add_box (context_t *c) |
int | nudge::can_add_sphere (context_t *c) |
int | nudge::can_add_compound (context_t *c, unsigned num_boxes, unsigned num_spheres) |
int | nudge::can_add_clone (context_t *c, unsigned body_to_clone) |
unsigned | nudge::get_next_add_body_index (context_t *c) |
Allows to peek the body index that is going to be returned in next add_xxx(...) call. | |
void | nudge::body_recalculate_bounding_box (context_t *c, uint32_t body) |
Recalculates the bounding box of the body (BodyInfo::aabb_center and BodyInfo::aabb_extents) | |
void | nudge::body_change_motion_state (nudge::context_t *c, unsigned body, nudge::FlagMask new_motion_state, float mass_fallback=1.f) |
[Experimental] Changes the body motion state (i.e. the BF_IS_STATIC_OR_KINEMATIC_OR_DYNAMIC group of body flags) | |
void | nudge::body_scale (nudge::context_t *c, unsigned body, float scale_factor, float mass_scale_factor=0.f) |
[Experimental] Uniformly scales the specified body incrementally | |
Set of functions regarding creation and removal of physic bodies.
unsigned nudge::add_box | ( | context_t * | c, |
float | mass, | ||
float | hsizex, | ||
float | hsizey, | ||
float | hsizez, | ||
const Transform * | T = NULL , |
||
const float | comOffset[3] = NULL |
||
) |
Adds a new body to the simulation with a single box collider.
c | the nudge context |
mass | positive => dynamic; 0 => static; negative => kinematic (where the absolute value will be used as mass internally) |
hsizex | half box size in the x direction |
hsizey | half box size in the y direction |
hsizez | half box size in the z direction |
T | a pointer to a Transform |
comOffset | an optional array of 3 floats that determines the center of mass offset of the body |
unsigned nudge::add_box | ( | context_t * | c, |
float | mass, | ||
float | hsizex, | ||
float | hsizey, | ||
float | hsizez, | ||
const float * | mMatrix16WithoutScaling, | ||
const float | comOffset[3] = NULL |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
mMatrix16WithoutScaling | a pointer to a 4x4 column-major matrix with only translation and rotation |
unsigned nudge::add_sphere | ( | context_t * | c, |
float | mass, | ||
float | radius, | ||
const Transform * | T = NULL , |
||
const float | comOffset[3] = NULL |
||
) |
Adds a new body to the simulation with a single sphere collider.
c | the nudge context |
mass | positive => dynamic; 0 => static; negative => kinematic (where the absolute value will be used as mass internally) |
radius | the sphere radius |
T | a pointer to a Transform |
comOffset | an optional array of 3 floats that determines the center of mass offset of the body |
unsigned nudge::add_sphere | ( | context_t * | c, |
float | mass, | ||
float | radius, | ||
const float * | mMatrix16WithoutScaling, | ||
const float | comOffset[3] = NULL |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
mMatrix16WithoutScaling | a pointer to a 4x4 column-major matrix with only translation and rotation |
unsigned nudge::add_compound | ( | context_t * | c, |
float | mass, | ||
float | inertia[3], | ||
unsigned | num_boxes, | ||
const float * | hsizeTriplets, | ||
const Transform * | boxOffsetTransforms, | ||
unsigned | num_spheres, | ||
const float * | radii, | ||
const Transform * | sphereOffsetTransforms, | ||
const Transform * | T = NULL , |
||
const float | comOffset[3] = NULL , |
||
float * | centerMeshAndRetrieveOldCenter3Out = NULL |
||
) |
Adds a new body to the simulation with a compound collider made up of num_boxes box colliders and num_spheres sphere colliders.
c | the nudge context |
mass | positive => dynamic; 0 => static; negative => kinematic (where the absolute value will be used as mass internally) |
inertia | an inertia tensor in a 3-float array form that is used only if mass is not zero (see also the inertia helper functions); it can be NULL (in that case a box inertia on the body axis-aligned bounding box extents is used) |
num_boxes | |
hsizeTriplets | pointer to an array of size 3*num_boxes floats |
boxOffsetTransforms | pointer to an array of num_boxes Transforms |
num_spheres | |
radii | pointer to an array of num_sphere floats |
sphereOffsetTransforms | pointer to an array of num_sphere Transforms |
T | a pointer to a Transform |
comOffset | an optional input array of 3 floats that determines the center of mass offset of the body |
centerMeshAndRetrieveOldCenter3Out | [experimental] an optional output array of 3 floats: if set, the input mesh is recentered (before applying the comOffset) and the axis-aligned bounding box center that has been subtracted from the mesh is returned |
unsigned nudge::add_compound | ( | context_t * | c, |
float | mass, | ||
float | inertia[3], | ||
unsigned | num_boxes, | ||
const float * | hsizeTriplets, | ||
const float * | boxOffsetMatrices16WithoutScaling, | ||
unsigned | num_spheres, | ||
const float * | radii, | ||
const float * | sphereOffsetMatrices16WithoutScaling, | ||
const float * | mMatrix16WithoutScaling = NULL , |
||
const float | comOffset[3] = NULL , |
||
float * | centerMeshAndRetrieveOldCenter3Out = NULL |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
mMatrix16WithoutScaling | a pointer to a 4x4 column-major matrix with only translation and rotation |
unsigned nudge::add_clone | ( | context_t * | c, |
unsigned | body_to_clone, | ||
float | mass, | ||
const Transform * | T = NULL , |
||
float | scale_factor = 1.f , |
||
const float | newComOffsetInPreScaledUnits[3] = NULL |
||
) |
[Experimental] Adds a new body to the simulation cloning an existing body
c | the nudge context |
body_to_clone | the body to clone |
mass | positive => dynamic; 0 => static; negative => kinematic (where the absolute value will be used as mass internally) |
T | a pointer to a Transform |
scale_factor | positive => the uniform scaling factor to apply (to each single axis); negative => scale so that the half bounding box y-component of the body becomes exactly -scaling_factor; 0 => invalid value (asserts) |
newComOffsetInPreScaledUnits | if set, an absolute new center of mass offset will be added (replacing the old one if present) using the pre-scaled coordinates; otherwise the old center of mass offset (if present) is kept (and possibly scaled) |
unsigned nudge::add_clone | ( | context_t * | c, |
unsigned | body_to_clone, | ||
float | mass, | ||
const float * | mMatrix16WithoutScaling, | ||
float | scale_factor = 1.f , |
||
const float | newComOffsetInPreScaledUnits[3] = NULL |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
mMatrix16WithoutScaling | a pointer to a 4x4 column-major matrix with only translation and rotation |
void nudge::remove_body | ( | context_t * | c, |
unsigned | body | ||
) |
Removes a body from the simulation.
uint32_t nudge::colliders_get_num_remaining_boxes | ( | context_t * | c | ) |
Return the number of box colliders that can still be added to the physic world.
uint32_t nudge::colliders_get_num_remaining_spheres | ( | context_t * | c | ) |
Return the number of sphere colliders that can still be added to the physic world.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Allows to peek the body index that is going to be returned in next add_xxx(...) call.
c | the nudge context |
void nudge::body_recalculate_bounding_box | ( | context_t * | c, |
uint32_t | body | ||
) |
Recalculates the bounding box of the body (BodyInfo::aabb_center and BodyInfo::aabb_extents)
c | the nudge context |
body | the body index |
void nudge::body_change_motion_state | ( | nudge::context_t * | c, |
unsigned | body, | ||
nudge::FlagMask | new_motion_state, | ||
float | mass_fallback = 1.f |
||
) |
[Experimental] Changes the body motion state (i.e. the BF_IS_STATIC_OR_KINEMATIC_OR_DYNAMIC group of body flags)
c | the nudge context |
body | the index of the body |
new_motion_state | the desired new motion state; it must be: BF_IS_STATIC, BF_IS_KINEMATIC or BF_IS_DYNAMIC |
mass_fallback | a mass fallback used only when 'new_motion_state' is BF_IS_DYNAMIC and the body had zero mass (the body was static) |
void nudge::body_scale | ( | nudge::context_t * | c, |
unsigned | body, | ||
float | scale_factor, | ||
float | mass_scale_factor = 0.f |
||
) |
[Experimental] Uniformly scales the specified body incrementally
c | the nudge context |
body | the target body |
scale_factor | positive => the uniform scaling factor to apply (to each single axis); negative => scale so that the half bounding box y-component of the body becomes exactly -scaling_factor; 0 => invalid value (asserts) |
mass_scale_factor | positive => the scaling amount to apply to the mass; 0 => sets 'mass_scale_factor' to the cube of the 'scaling_factor' argument; negative => sets the new mass exactly to -mass_scale_factor |