JSim 2026.06.01-p(1)
Loading...
Searching...
No Matches
driverheader.h File Reference

Stable C ABI for constructing, configuring, stepping, and querying JSim worlds. More...

#include <stdint.h>

Go to the source code of this file.

Functions

void c_doThing (void)
 No-op sanity probe for link/load validation.
uint64_t c_rsCreateWorld (double fixed_dt_s, int enable_gravity)
 Creates a new physics world and returns its opaque handle.
void c_rsDestroyWorld (uint64_t world_handle)
 Destroys a previously created world and releases all associated resources.
int c_rsCreateBody (uint64_t world_handle, double mass_kg)
 Creates a new rigid body in a world.
int c_rsCreateGamepiece (uint64_t world_handle, double radius_m, double mass_kg, double restitution)
 Creates a new generic gamepiece using sphere hitbox parameters.
int c_rsCreateGamepieceWithType (uint64_t world_handle, int type, double radius_m, double mass_kg, double restitution)
 Creates a new generic gamepiece with an explicit type tag.
int c_rsCreateGamepieceWithTypeName (uint64_t world_handle, const char *type_name, double radius_m, double mass_kg, double restitution)
 Creates a new generic gamepiece with a human-readable type name.
const char * c_rsGetGamepieceTypeName (uint64_t world_handle, int gamepiece_index)
 Reads the registered type name for a gamepiece.
int c_rsPickGamepiece (uint64_t world_handle, int gamepiece_index, double intake_x, double intake_y, double intake_z, double capture_radius, double carry_offset_x, double carry_offset_y, double carry_offset_z)
 Request pickup of a gamepiece into a carrier.
int c_rsPlaceGamepiece (uint64_t world_handle, int gamepiece_index, double x_m, double y_m, double z_m)
 Place a gamepiece at a world position and mark grounded.
int c_rsOuttakeGamepiece (uint64_t world_handle, int gamepiece_index, double px, double py, double pz, double vx, double vy, double vz)
 Outtake a gamepiece from a muzzle pose with velocity (launch).
int c_rsSetBodyPosition (uint64_t world_handle, int body_index, double x_m, double y_m, double z_m)
 Sets a body's world-space position.
int c_rsSetBodyLinearVelocity (uint64_t world_handle, int body_index, double vx_mps, double vy_mps, double vz_mps)
 Sets a body's world-space linear velocity.
int c_rsSetBodyOrientation (uint64_t world_handle, int body_index, double qw, double qx, double qy, double qz)
 Set a rigid body's orientation.
int c_rsGetBodyOrientation (uint64_t world_handle, int body_index, double *out_qw, double *out_qx, double *out_qy, double *out_qz)
 Read a rigid body's orientation quaternion.
int c_rsSetBodyGravityEnabled (uint64_t world_handle, int body_index, int enabled)
 Enables or disables gravity for a single body.
int c_rsSetBodyMaterial (uint64_t world_handle, int body_index, double restitution, double friction_kinetic, double friction_static, double collision_damping)
 Sets per-body material coefficients used in contact response.
int c_rsSetBodyMaterialId (uint64_t world_handle, int body_index, int32_t material_id)
 Assigns a numeric material id to a body.
int c_rsSetBodyCollisionFilter (uint64_t world_handle, int body_index, uint32_t collision_layer_bits, uint32_t collision_mask_bits)
 Sets broad-phase collision filtering for a body.
int c_rsSetBodyAerodynamicSphere (uint64_t world_handle, int body_index, double radius_m, double drag_coefficient)
 Configures spherical aerodynamic metadata for a body.
int c_rsSetBodyAerodynamicBox (uint64_t world_handle, int body_index, double x_m, double y_m, double z_m, double drag_coefficient)
 Configures box aerodynamic metadata for a body.
int c_rsSetGamepiecePosition (uint64_t world_handle, int gamepiece_index, double x_m, double y_m, double z_m)
 Sets a gamepiece's world-space position.
int c_rsSetGamepieceLinearVelocity (uint64_t world_handle, int gamepiece_index, double vx_mps, double vy_mps, double vz_mps)
 Sets a gamepiece's world-space linear velocity.
int c_rsGetGamepiecePosition (uint64_t world_handle, int gamepiece_index, double *x_m, double *y_m, double *z_m)
 Reads a gamepiece's world-space position.
int c_rsGetGamepieceLinearVelocity (uint64_t world_handle, int gamepiece_index, double *vx_mps, double *vy_mps, double *vz_mps)
 Reads a gamepiece's world-space linear velocity.
int c_rsSetWorldAerodynamics (uint64_t world_handle, int enabled, double air_density_kgpm3, double linear_drag_coefficient_n_per_mps, double magnus_coefficient, double default_drag_coefficient, double default_drag_reference_area_m2)
 Configures world-level aerodynamic constants and feature toggle.
int c_rsSetMaterialInteraction (uint64_t world_handle, int32_t material_a_id, int32_t material_b_id, double restitution, double friction, int enabled)
 Adds or updates a material-pair interaction override.
int c_rsStepWorld (uint64_t world_handle, int steps)
 Advances the world by steps fixed timesteps.
int c_rsSetWorldGravity (uint64_t world_handle, double gx_mps2, double gy_mps2, double gz_mps2)
 Sets world gravity acceleration vector.
int c_rsGetBodyPosition (uint64_t world_handle, int body_index, double *x_m, double *y_m, double *z_m)
 Reads a body's world-space position.
int c_rsGetBodyLinearVelocity (uint64_t world_handle, int body_index, double *vx_mps, double *vy_mps, double *vz_mps)
 Reads a body's world-space linear velocity.
int c_rsGetBodyPose7Array (uint64_t world_handle, double *out_pose7, int max_bodies)
 Exports body poses as a tightly packed 7-tuple array.
int c_rsGetBodyVelocity6Array (uint64_t world_handle, double *out_velocity6, int max_bodies)
 Exports body velocities as a tightly packed 6-tuple array.
int c_rsGetBodyState13Array (uint64_t world_handle, double *out_state13, int max_bodies)
 Exports full body state as a tightly packed 13-tuple array.
int c_rsCreateAssembly (uint64_t world_handle)
 Creates and registers a rigid assembly container.

Detailed Description

Stable C ABI for constructing, configuring, stepping, and querying JSim worlds.

This header is intentionally C-compatible so it can be consumed from JNI, Python/ctypes, C#, Rust FFI, and other foreign-function interfaces without requiring C++ name mangling support.

General conventions:

  • All distances are meters.
  • All velocities are meters per second.
  • All angular quantities are radians or radians/second.
  • All masses are kilograms.
  • All time values are seconds.
  • A world handle value of 0 is invalid.
  • Functions returning int use 0 for success and non-zero for failure.
  • Indices are zero-based and must reference an existing body.
  • Pointer out-parameters must be non-null unless explicitly documented as optional.

Error model:

  • Invalid handle, invalid body index, invalid pointer, or invalid numeric input results in a non-zero error code.
  • APIs are best-effort deterministic and do not throw C++ exceptions across this ABI.

Threading model:

  • World mutation functions are not re-entrant for the same world handle.
  • Callers should serialize writes and step operations per world.
  • Query-only calls should not race with mutating calls unless external locking is used.

Function Documentation

◆ c_doThing()

void c_doThing ( void )

No-op sanity probe for link/load validation.

This function exists primarily as a simple symbol to validate library load paths in integration tests and downstream wrappers.

◆ c_rsCreateAssembly()

int c_rsCreateAssembly ( uint64_t world_handle)

Creates and registers a rigid assembly container.

Parameters
world_handleTarget world handle.
Returns
Non-negative assembly index on success; negative on failure.

◆ c_rsCreateBody()

int c_rsCreateBody ( uint64_t world_handle,
double mass_kg )

Creates a new rigid body in a world.

Parameters
world_handleTarget world handle.
mass_kgBody mass in kilograms.
Returns
Non-negative body index on success; negative value on failure.

◆ c_rsCreateGamepiece()

int c_rsCreateGamepiece ( uint64_t world_handle,
double radius_m,
double mass_kg,
double restitution )

Creates a new generic gamepiece using sphere hitbox parameters.

Parameters
world_handleTarget world handle.
radius_mSphere hitbox radius in meters.
mass_kgGamepiece mass in kilograms.
restitutionCoefficient of restitution in [0, 1].
Returns
Non-negative gamepiece index on success; negative value on failure.

◆ c_rsCreateGamepieceWithType()

int c_rsCreateGamepieceWithType ( uint64_t world_handle,
int type,
double radius_m,
double mass_kg,
double restitution )

Creates a new generic gamepiece with an explicit type tag.

Parameters
world_handleTarget world handle.
typeInteger type tag (application-defined). For Java usage, map from GamePieceType.ordinal().
radius_mSphere hitbox radius in meters (ignored for non-spherical types currently).
mass_kgGamepiece mass in kilograms.
restitutionCoefficient of restitution in [0, 1].
Returns
Non-negative gamepiece index on success; negative value on failure.

◆ c_rsCreateGamepieceWithTypeName()

int c_rsCreateGamepieceWithTypeName ( uint64_t world_handle,
const char * type_name,
double radius_m,
double mass_kg,
double restitution )

Creates a new generic gamepiece with a human-readable type name.

This API lets callers register/import named gamepiece types (for example "generic_sphere", "generic_cube", "fuel_rebuilt_2026"). The driver will store the provided name for use by higher-level tooling; core physics will continue to use spherical defaults until specific type implementations are available.

Parameters
world_handleTarget world handle.
type_nameNull-terminated UTF-8 name for the gamepiece type. May be NULL to indicate unnamed/default.
radius_mSphere hitbox radius in meters (ignored for non-spherical types currently).
mass_kgGamepiece mass in kilograms.
restitutionCoefficient of restitution in [0, 1].
Returns
Non-negative gamepiece index on success; negative value on failure.

◆ c_rsCreateWorld()

uint64_t c_rsCreateWorld ( double fixed_dt_s,
int enable_gravity )

Creates a new physics world and returns its opaque handle.

Parameters
fixed_dt_sFixed simulation timestep in seconds. Typical FRC values are 0.005-0.02.
enable_gravityNon-zero enables gravity by default; zero disables it.
Returns
Opaque non-zero world handle on success; 0 on failure.

◆ c_rsDestroyWorld()

void c_rsDestroyWorld ( uint64_t world_handle)

Destroys a previously created world and releases all associated resources.

Parameters
world_handleOpaque world handle returned by c_rsCreateWorld().

Safe behavior:

  • Passing an invalid handle is ignored or treated as an error internally, but callers should not rely on double-destroy semantics.
  • After destruction, all body indices and references from that world are invalid.

◆ c_rsGetBodyLinearVelocity()

int c_rsGetBodyLinearVelocity ( uint64_t world_handle,
int body_index,
double * vx_mps,
double * vy_mps,
double * vz_mps )

Reads a body's world-space linear velocity.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
vx_mpsOutput pointer for x velocity in meters/second.
vy_mpsOutput pointer for y velocity in meters/second.
vz_mpsOutput pointer for z velocity in meters/second.
Returns
0 on success, non-zero on failure.

◆ c_rsGetBodyOrientation()

int c_rsGetBodyOrientation ( uint64_t world_handle,
int body_index,
double * out_qw,
double * out_qx,
double * out_qy,
double * out_qz )

Read a rigid body's orientation quaternion.

Returns
0 on success, non-zero on error.

◆ c_rsGetBodyPose7Array()

int c_rsGetBodyPose7Array ( uint64_t world_handle,
double * out_pose7,
int max_bodies )

Exports body poses as a tightly packed 7-tuple array.

Parameters
world_handleTarget world handle.
out_pose7Output buffer of length at least (7 * max_bodies).
max_bodiesMaximum number of bodies to write.
Returns
Number of bodies written on success (>= 0), negative on failure.

Layout per body i:

  • out_pose7[i * 7 + 0] = x (m)
  • out_pose7[i * 7 + 1] = y (m)
  • out_pose7[i * 7 + 2] = z (m)
  • out_pose7[i * 7 + 3] = qw
  • out_pose7[i * 7 + 4] = qx
  • out_pose7[i * 7 + 5] = qy
  • out_pose7[i * 7 + 6] = qz

◆ c_rsGetBodyPosition()

int c_rsGetBodyPosition ( uint64_t world_handle,
int body_index,
double * x_m,
double * y_m,
double * z_m )

Reads a body's world-space position.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
x_mOutput pointer for x position in meters.
y_mOutput pointer for y position in meters.
z_mOutput pointer for z position in meters.
Returns
0 on success, non-zero on failure.

◆ c_rsGetBodyState13Array()

int c_rsGetBodyState13Array ( uint64_t world_handle,
double * out_state13,
int max_bodies )

Exports full body state as a tightly packed 13-tuple array.

Parameters
world_handleTarget world handle.
out_state13Output buffer of length at least (13 * max_bodies).
max_bodiesMaximum number of bodies to write.
Returns
Number of bodies written on success (>= 0), negative on failure.

Layout per body i:

  • out_state13[i * 13 + 0] = x (m)
  • out_state13[i * 13 + 1] = y (m)
  • out_state13[i * 13 + 2] = z (m)
  • out_state13[i * 13 + 3] = qw
  • out_state13[i * 13 + 4] = qx
  • out_state13[i * 13 + 5] = qy
  • out_state13[i * 13 + 6] = qz
  • out_state13[i * 13 + 7] = vx (m/s)
  • out_state13[i * 13 + 8] = vy (m/s)
  • out_state13[i * 13 + 9] = vz (m/s)
  • out_state13[i * 13 + 10] = wx (rad/s)
  • out_state13[i * 13 + 11] = wy (rad/s)
  • out_state13[i * 13 + 12] = wz (rad/s)

◆ c_rsGetBodyVelocity6Array()

int c_rsGetBodyVelocity6Array ( uint64_t world_handle,
double * out_velocity6,
int max_bodies )

Exports body velocities as a tightly packed 6-tuple array.

Parameters
world_handleTarget world handle.
out_velocity6Output buffer of length at least (6 * max_bodies).
max_bodiesMaximum number of bodies to write.
Returns
Number of bodies written on success (>= 0), negative on failure.

Layout per body i:

  • out_velocity6[i * 6 + 0] = vx (m/s)
  • out_velocity6[i * 6 + 1] = vy (m/s)
  • out_velocity6[i * 6 + 2] = vz (m/s)
  • out_velocity6[i * 6 + 3] = wx (rad/s)
  • out_velocity6[i * 6 + 4] = wy (rad/s)
  • out_velocity6[i * 6 + 5] = wz (rad/s)

◆ c_rsGetGamepieceLinearVelocity()

int c_rsGetGamepieceLinearVelocity ( uint64_t world_handle,
int gamepiece_index,
double * vx_mps,
double * vy_mps,
double * vz_mps )

Reads a gamepiece's world-space linear velocity.

Parameters
world_handleTarget world handle.
gamepiece_indexZero-based gamepiece index.
vx_mpsOutput pointer for x velocity in meters/second.
vy_mpsOutput pointer for y velocity in meters/second.
vz_mpsOutput pointer for z velocity in meters/second.
Returns
0 on success, non-zero on failure.

◆ c_rsGetGamepiecePosition()

int c_rsGetGamepiecePosition ( uint64_t world_handle,
int gamepiece_index,
double * x_m,
double * y_m,
double * z_m )

Reads a gamepiece's world-space position.

Parameters
world_handleTarget world handle.
gamepiece_indexZero-based gamepiece index.
x_mOutput pointer for x position in meters.
y_mOutput pointer for y position in meters.
z_mOutput pointer for z position in meters.
Returns
0 on success, non-zero on failure.

◆ c_rsGetGamepieceTypeName()

const char * c_rsGetGamepieceTypeName ( uint64_t world_handle,
int gamepiece_index )

Reads the registered type name for a gamepiece.

Parameters
world_handleTarget world handle.
gamepiece_indexZero-based gamepiece index.
Returns
Null-terminated UTF-8 type name on success, or NULL on failure.

◆ c_rsOuttakeGamepiece()

int c_rsOuttakeGamepiece ( uint64_t world_handle,
int gamepiece_index,
double px,
double py,
double pz,
double vx,
double vy,
double vz )

Outtake a gamepiece from a muzzle pose with velocity (launch).

◆ c_rsPickGamepiece()

int c_rsPickGamepiece ( uint64_t world_handle,
int gamepiece_index,
double intake_x,
double intake_y,
double intake_z,
double capture_radius,
double carry_offset_x,
double carry_offset_y,
double carry_offset_z )

Request pickup of a gamepiece into a carrier.

Parameters
world_handleTarget world handle.
gamepiece_indexZero-based gamepiece index returned by c_rsCreateGamepiece().
intake_xIntake world x position.
intake_yIntake world y position.
intake_zIntake world z position.
capture_radiusCapture radius in meters.
carry_offset_xCarry offset x in meters.
carry_offset_yCarry offset y in meters.
carry_offset_zCarry offset z in meters.
Returns
0 on success (picked), non-zero on failure.

◆ c_rsPlaceGamepiece()

int c_rsPlaceGamepiece ( uint64_t world_handle,
int gamepiece_index,
double x_m,
double y_m,
double z_m )

Place a gamepiece at a world position and mark grounded.

◆ c_rsSetBodyAerodynamicBox()

int c_rsSetBodyAerodynamicBox ( uint64_t world_handle,
int body_index,
double x_m,
double y_m,
double z_m,
double drag_coefficient )

Configures box aerodynamic metadata for a body.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
x_mBox size along body-local x in meters.
y_mBox size along body-local y in meters.
z_mBox size along body-local z in meters.
drag_coefficientDimensionless drag coefficient (Cd).
Returns
0 on success, non-zero on failure.

◆ c_rsSetBodyAerodynamicSphere()

int c_rsSetBodyAerodynamicSphere ( uint64_t world_handle,
int body_index,
double radius_m,
double drag_coefficient )

Configures spherical aerodynamic metadata for a body.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
radius_mSphere radius in meters.
drag_coefficientDimensionless drag coefficient (Cd).
Returns
0 on success, non-zero on failure.

◆ c_rsSetBodyCollisionFilter()

int c_rsSetBodyCollisionFilter ( uint64_t world_handle,
int body_index,
uint32_t collision_layer_bits,
uint32_t collision_mask_bits )

Sets broad-phase collision filtering for a body.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
collision_layer_bitsBitmask describing layers this body belongs to.
collision_mask_bitsBitmask describing layers this body can interact with.
Returns
0 on success, non-zero on failure.

A pair (A, B) is considered eligible only if both expressions are non-zero:

  • (A.layer_bits & B.mask_bits)
  • (B.layer_bits & A.mask_bits)

◆ c_rsSetBodyGravityEnabled()

int c_rsSetBodyGravityEnabled ( uint64_t world_handle,
int body_index,
int enabled )

Enables or disables gravity for a single body.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
enabledNon-zero to enable gravity for this body, zero to disable.
Returns
0 on success, non-zero on failure.

◆ c_rsSetBodyLinearVelocity()

int c_rsSetBodyLinearVelocity ( uint64_t world_handle,
int body_index,
double vx_mps,
double vy_mps,
double vz_mps )

Sets a body's world-space linear velocity.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
vx_mpsVelocity x component in meters/second.
vy_mpsVelocity y component in meters/second.
vz_mpsVelocity z component in meters/second.
Returns
0 on success, non-zero on failure.

◆ c_rsSetBodyMaterial()

int c_rsSetBodyMaterial ( uint64_t world_handle,
int body_index,
double restitution,
double friction_kinetic,
double friction_static,
double collision_damping )

Sets per-body material coefficients used in contact response.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
restitutionCoefficient of restitution, generally in [0, 1].
friction_kineticKinetic friction coefficient, typically >= 0.
friction_staticStatic friction coefficient, typically >= 0.
collision_dampingAdditional collision damping term, typically >= 0.
Returns
0 on success, non-zero on failure.

◆ c_rsSetBodyMaterialId()

int c_rsSetBodyMaterialId ( uint64_t world_handle,
int body_index,
int32_t material_id )

Assigns a numeric material id to a body.

Parameters
world_handleTarget world handle.
body_indexZero-based body index.
material_idApplication-defined material identifier.
Returns
0 on success, non-zero on failure.

The material id is used by world-level material interaction tables to override restitution/friction for specific material pairs.

◆ c_rsSetBodyOrientation()

int c_rsSetBodyOrientation ( uint64_t world_handle,
int body_index,
double qw,
double qx,
double qy,
double qz )

Set a rigid body's orientation.

Returns
0 on success, non-zero on error.

◆ c_rsSetBodyPosition()

int c_rsSetBodyPosition ( uint64_t world_handle,
int body_index,
double x_m,
double y_m,
double z_m )

Sets a body's world-space position.

Parameters
world_handleTarget world handle.
body_indexZero-based body index returned by c_rsCreateBody().
x_mPosition x in meters.
y_mPosition y in meters.
z_mPosition z in meters.
Returns
0 on success, non-zero on failure.

◆ c_rsSetGamepieceLinearVelocity()

int c_rsSetGamepieceLinearVelocity ( uint64_t world_handle,
int gamepiece_index,
double vx_mps,
double vy_mps,
double vz_mps )

Sets a gamepiece's world-space linear velocity.

Parameters
world_handleTarget world handle.
gamepiece_indexZero-based gamepiece index.
vx_mpsVelocity x component in meters/second.
vy_mpsVelocity y component in meters/second.
vz_mpsVelocity z component in meters/second.
Returns
0 on success, non-zero on failure.

◆ c_rsSetGamepiecePosition()

int c_rsSetGamepiecePosition ( uint64_t world_handle,
int gamepiece_index,
double x_m,
double y_m,
double z_m )

Sets a gamepiece's world-space position.

Parameters
world_handleTarget world handle.
gamepiece_indexZero-based gamepiece index.
x_mPosition x in meters.
y_mPosition y in meters.
z_mPosition z in meters.
Returns
0 on success, non-zero on failure.

◆ c_rsSetMaterialInteraction()

int c_rsSetMaterialInteraction ( uint64_t world_handle,
int32_t material_a_id,
int32_t material_b_id,
double restitution,
double friction,
int enabled )

Adds or updates a material-pair interaction override.

Parameters
world_handleTarget world handle.
material_a_idFirst material id in the pair.
material_b_idSecond material id in the pair.
restitutionPair-specific restitution coefficient.
frictionPair-specific friction coefficient.
enabledNon-zero enables this interaction entry; zero disables it.
Returns
0 on success, non-zero on failure.

Pair lookup is symmetric: (A, B) and (B, A) resolve to the same entry.

◆ c_rsSetWorldAerodynamics()

int c_rsSetWorldAerodynamics ( uint64_t world_handle,
int enabled,
double air_density_kgpm3,
double linear_drag_coefficient_n_per_mps,
double magnus_coefficient,
double default_drag_coefficient,
double default_drag_reference_area_m2 )

Configures world-level aerodynamic constants and feature toggle.

Parameters
world_handleTarget world handle.
enabledNon-zero enables aerodynamic forces; zero disables them.
air_density_kgpm3Air density in kg/m^3.
linear_drag_coefficient_n_per_mpsLinear drag coefficient in N/(m/s).
magnus_coefficientMagnus lift scale factor.
default_drag_coefficientDefault dimensionless Cd when body value is unset.
default_drag_reference_area_m2Default area in m^2 when body geometry is unset.
Returns
0 on success, non-zero on failure.

◆ c_rsSetWorldGravity()

int c_rsSetWorldGravity ( uint64_t world_handle,
double gx_mps2,
double gy_mps2,
double gz_mps2 )

Sets world gravity acceleration vector.

Parameters
world_handleTarget world handle.
gx_mps2Gravity x component in m/s^2.
gy_mps2Gravity y component in m/s^2.
gz_mps2Gravity z component in m/s^2.
Returns
0 on success, non-zero on failure.

◆ c_rsStepWorld()

int c_rsStepWorld ( uint64_t world_handle,
int steps )

Advances the world by steps fixed timesteps.

Parameters
world_handleTarget world handle.
stepsNumber of fixed-dt integration steps; must be >= 0.
Returns
0 on success, non-zero on failure.