Constraint#

struct nvConstraint#

Constraint base struct.

Public Members

nvConstraintType type#

Type of the constraint.

void *def#

Constraint definition class. (This needs to be casted)

nvBody *a#

First body.

nvBody *b#

Second body.

enum nvConstraintType#

Constraint types.

Values:

enumerator nvConstraintType_SPRING#

Spring constraint type. See nvSpring.

enumerator nvConstraintType_DISTANCEJOINT#

Distance joint constraint type. See nvDistanceJoint.

enumerator nvConstraintType_HINGEJOINT#

Hinge joint constraint type. See nvHingeJoint.

Spring Constraint#

struct nvSpring#

Spring constraint definition.

A spring constraint is a damped spring with rest length, stiffness and damping value.

Public Members

nv_float length#

Resting length of the spring.

nv_float stiffness#

Stiffness (strength) of the spring.

nv_float damping#

Damping of the spring.

nvVector2 anchor_a#

Local anchor point on body A.

nvVector2 anchor_b#

Local anchor point on body B.

nv_float target_vel#

Target relative velocity.

nv_float damping_bias#

Damping bias.

nvVector2 ra#

Anchor point on body A.

nvVector2 rb#

Anchor point on body B.

nvVector2 normal#

Normal of the constraint.

nv_float mass#

Constraint effective mass.

nv_float jc#

Accumulated constraint impulse.

nvConstraint *nvSpring_new(nvBody *a, nvBody *b, nvVector2 anchor_a, nvVector2 anchor_b, nv_float length, nv_float stiffness, nv_float damping)#

Create a new spring constraint.

Leave one of the body parameters as :code:NULL to link the body to world. Don’t forget to change the anchor point to be in world space as well.

Parameters:
  • a – First body

  • b – Second body

  • anchor_a – Local anchor point on body A

  • anchor_b – Local anchor point on body B

  • length – Length of the spring

  • stiffness – Stiffness (strength) of the spring

  • damping – Damping of the spring

Returns:

nvConstraint *

Distance Joint Constraint#

struct nvDistanceJoint#

Distance joint constraint definition.

A distance joint constraints the distance of two points on the two bodies to be constant. This acts like as if the two bodies are linked with a solid bar. TODO: lower upper limit

Public Members

nv_float length#

Length of the distance joint.

nvVector2 anchor_a#

Local anchor point on body A.

nvVector2 anchor_b#

Local anchor point on body B.

nvVector2 ra#

Anchor point on body A.

nvVector2 rb#

Anchor point on body B.

nvVector2 normal#

Normal of the constraint.

nv_float bias#

Constraint position correction bias.

nv_float mass#

Constraint effective mass.

nv_float jc#

Accumulated constraint impulse.

nvConstraint *nvDistanceJoint_new(nvBody *a, nvBody *b, nvVector2 anchor_a, nvVector2 anchor_b, nv_float length)#

Create a new distance joint constraint.

Leave one of the body parameters as :code:NULL to link the body to world. Don’t forget to change the anchor point to be in world space as well.

Parameters:
  • a – First body

  • b – Second body

  • anchor_a – Local anchor point on body A

  • anchor_b – Local anchor point on body B

  • length – Length of the joint

Returns:

nvConstraint *

Hinge Joint Constraint#

struct nvHingeJoint#

Hinge joint constraint definition.

A hinge joint, also known as revolute join, allows the bodies to rotate around a common axis. Ensuring the relative orientation of the bodies remains fixed.

Public Members

nvVector2 anchor#

Anchor point in world space.

bool enable_limits#

Enable angular limits or not.

nv_float upper_limit#

Upper angle limit.

nv_float lower_limit#

Lower angle limit.

nv_float angle#

Angle of the constraint.

nvVector2 anchor_a#

Joint anchor translated to body A.

nvVector2 anchor_b#

Joint anchor translated to body B.

nv_float upper_impulse#

Accumulated upper limit impulse.

nv_float lower_impulse#

Accumulated lower limit impulse.

nv_float reference_angle#

Reference angle for the constrain.

nv_float axial_mass#

Axial effective mass.

nvVector2 ra#

Anchor point on body A.

nvVector2 rb#

Anchor point on body B.

nvVector2 normal#

Normal of the distance constraint.

nv_float bias#

Distance constraint position correction bias.

nv_float mass#

Distance constraint effective mass.

nv_float jc#

Accumulated distance constraint impulse.

nvConstraint *nvHingeJoint_new(nvBody *a, nvBody *b, nvVector2 anchor)#

Create a new hinge joint constraint.

Leave one of the body parameters as :code:NULL to link the body to world. Don’t forget to change the anchor point to be in world space as well.

Parameters:
  • a – First body

  • b – Second body

  • anchor_a – Anchor point in world space.

Returns:

nvConstraint *