DetPhysDocs日本語

detphys3d.h3D world, bodies, convex hulls, snapshots, transfers (version 2)

The physics base is Box3D. It follows the 2D style (detphys.h, detphys_body.h) and reuses the 2D errors (DETPHYS_ERR_*), worker job types, snapshot kinds and detphys_snapshot_info / detphys_snapshot_stats. Lengths are mm, speeds mm/s, angular speeds mrad/s, forces mN, torques mN·m, materials × 1000, all integers. Orientations are integer quaternions (qx, qy, qz, qw; any length, the core normalizes them; pass a float quaternion multiplied by DETPHYS3D_QUAT_ONE [2^30] and rounded; 0, 0, 0, 0 = no rotation), so no trigonometry is used.

FunctionDescription
detphys3d_abi_versionThis header's version (DETPHYS3D_ABI_VERSION)
detphys3d_world_desc_defaultDefault world settings (60 Hz, 4 substeps, gravity (0, −10000, 0) mm/s², 1 worker, the core's pool)
detphys3d_shape_desc_defaultDefault shape settings (friction 600, density 1000000 = water, restitution 0, × 1000)
detphys3d_body_desc_defaultDefault body settings (dynamic body)
detphys3d_world_createCreates a world (NULL = defaults). NULL on failure
detphys3d_world_destroyDestroys it
detphys3d_world_get_descReads the settings it was created with
detphys3d_world_stepAdvances one tick
detphys3d_world_step_nAdvances count ticks (fewer calls when re-simulating after a rollback)
detphys3d_world_tickCurrent tick number
detphys3d_world_hashState hash (FNV-1a 64 over tick, body count and each body's position 3, quaternion 4, velocity 3, angular velocity 3 raw bits)Usage: Concepts › Ticks
detphys3d_world_engine_hashBox3D's own state hash (for checking)Usage: Desyncs › 3D worlds and sessions
detphys3d_world_get_statsBodies, awake count, contacts, hull count and more
detphys3d_world_add_hullBuilds and registers a convex hull from integer points (units_per_meter, 0 = mm). Returns its index; the same contents return the earlier indexUsage: Concepts › 3D
detphys3d_world_hull_countNumber of registered hulls
detphys3d_world_hull_infoHull information (vertex, face and triangle counts, radius, checksum)
detphys3d_world_hull_readReads a hull's vertices [m] and triangle indices for drawing
detphys3d_world_add_bodyCreates a body. Returns its ID (a serial number in creation order)
detphys3d_world_add_shapeAdds a shape to a body (compound bodies)Usage: Concepts › Moving concave shapes (3D)
detphys3d_world_remove_bodyRemoves a body (IDs are not reused)
detphys3d_world_set_transformSets position and orientation directly (mm, integer quaternion)
detphys3d_world_set_velocitySets velocity and angular velocity (mm/s, mrad/s)
detphys3d_world_apply_forceApplies a force (mN, for the next tick only)
detphys3d_world_apply_torqueApplies a torque (mN·m, for the next tick only)
detphys3d_world_apply_impulseApplies an impulse (mN·s, changes the velocity at once)
detphys3d_world_apply_angular_impulseApplies an angular impulse (mN·m·s)
detphys3d_world_body_countNumber of bodies created (removed ones included)
detphys3d_world_get_bodyReads one body's current state
detphys3d_world_read_bodiesReads all bodies into an array (fine to call every frame)
detphys3d_world_read_transformsLight readback for drawing only (7 floats per body: position xyz [m], quaternion)Usage: Concepts › 3D
detphys3d_world_body_shapesReads the shapes attached to a body
detphys3d_world_snapshot_sizeMeasures the current snapshot size (default DETPHYS3D_SNAPSHOT_DEFAULT = FULL)
detphys3d_world_snapshot_writeWrites a snapshot into a caller buffer
detphys3d_world_snapshot_restoreRestores a snapshot (the tick and body list too; registered hulls are kept; restoring a full one always starts a new shape version)
detphys3d_snapshot_read_infoReads an image header (no world needed)
detphys3d_world_get_snapshot_statsSnapshot status
detphys3d_world_transfer_sizeMeasures the state to send to another peer (transfer)
detphys3d_world_transfer_writeWrites a transfer (full image + shape registry contents + hull table)
detphys3d_world_transfer_restoreRestores a transfer (written by another world or device; rebuilds the registry or hull table first if they differ)
detphys3d_transfer_read_infoReads a transfer header (and verifies the checksum)
StructDescription
detphys3d_worldA 3D world (opaque)
detphys3d_world_descTick rate, substeps, gravity xyz, 1–32 workers, pool (DETPHYS3D_POOL_OWN / BOX3D / EXTERNAL), flags (NO_SLEEP, NO_CONTINUOUS, SSE2), contact tuning (0 = Box3D's defaults). 88 BUsage: Concepts › 3D
detphys3d_shape_descOne shape (DETPHYS3D_SHAPE_BOX / SPHERE / CAPSULE / HULL, size, center, orientation, material). 88 B
detphys3d_body_descBody settings (type DETPHYS3D_BODY_STATIC / KINEMATIC / DYNAMIC, position, integer quaternion, velocity, angular velocity, damping, gravity scale, flags [BULLET, NO_SLEEP, per-axis LOCK_*], tag, first shape). 176 B
detphys3d_body_viewReadback (ID, type, flags, tag, shape, integer position x_mm/y_mm/z_mm, floats for drawing). 96 BUsage: Determinism rules › 2. Never put floats into the simulation
detphys3d_hull_infoInformation about a registered hull
detphys3d_world_statsWorld status
detphys3d_transfer_infoTransfer header (sizes of hulls, registry and image, tick; after a restore, flags [DETPHYS3D_TRANSFER_REBUILT_REGISTRY, REPLACED_HULLS])
  • A full snapshot can be restored into another world that created the same shapes in the same order, but if the shape registry order differs it returns DETPHYS_ERR_FORMAT (the world is unchanged). To send state to another peer, use a transfer (sessions do this automatically).
  • Restoring a full snapshot with detphys_world_snapshot_restore / detphys3d_world_snapshot_restore always starts a new shape version (shape_version in detphys_snapshot_stats), even for an image taken by the same world, because an image from a world in another process cannot be told apart. The result and the hash are unchanged. If your own rollback ring mixes full and dyn snapshots, the first dyn after restoring a full one takes a new base, which costs about one full write. The core sessions (real-time and turn-based) only restore their own images and do not pay this.
  • Images and transfers are the same bytes on x64 and arm64 (iOS and 32-bit are not checked yet).
  • Not available yet: joints, sensors, contact events, ray queries.
  • The desync debugger can record 3D worlds (detphys_debug_record3d in detphys_debug.h above).
  • 3D moving concave shapes are in detphys3d_kinematic.h, next.

↑↓ to choose, Enter to open, Esc to close