# physx_scene.h ## Index
`tm_physx_scene_o`
`tm_physx_actor_o`
`tm_physx_shape_o`
`tm_physx_joint_o`
`tm_physx_mover_o`
`TM_TT_TYPE__PHYSX_RIGID_STATIC_COMPONENT`
`TM_TT_TYPE__PHYSX_RIGID_BODY_COMPONENT`
`TM_TT_TYPE__PHYSX_RIGID_BODY_SHAPE_COMPONENT`
`TM_TT_TYPE__PHYSX_JOINT_COMPONENT`
`TM_TT_TYPE__PHYSX_MOVER_COMPONENT`
`TM_TT_TYPE__PHYSX_VISUALIZATION_PARAMETERS`
`enum TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS`
`TM_PHYSX_CONVEX_COOKED_DATA_FORMAT`
`TM_ENTITY_BB__PHYSX_SCENE`
`struct tm_physx_rigid_static_component_t`
`struct tm_physx_rigid_body_component_t`
`struct tm_physx_rigid_body_shape_component_t`
`struct tm_physx_joint_component_t`
`struct tm_physx_mover_component_t`
`TM_ENTITY_SYSTEM__PHYSX`
`struct tm_physx_scene_settings_t`
`struct tm_physx_raycast_flags_t`
`struct tm_physx_raycast_hit_t`
`struct tm_physx_raycast_t`
`struct tm_physx_overlap_hit_t`
`struct tm_physx_penetration_t`
`TM_PHYSX_RAYCAST__COLLIDES_WITH_ALL`
`TM_PHYSX_ON_CONTACT_EVENT`
`struct tm_physx_on_contact_t`
`TM_PHYSX_ON_TRIGGER_EVENT`
`struct tm_physx_on_trigger_t`
`TM_PHYSX_ON_JOINT_BREAK_EVENT`
`struct tm_physx_on_joint_break_t`
`enum tm_physx_force_flags`

`struct tm_physx_scene_api`
`default_scene_settings()`
`parse_scene_settings()`
`create()`
`update()`
`visualize()`
`visualization_settings()`
`set_visualization_settings()`
`raycast()`
`sweep()`
`overlap()`
`compute_penetration()`
`on_contact()`
`on_trigger()`
`on_joint_break()`
`velocity()`
`set_velocity()`
`angular_velocity()`
`set_angular_velocity()`
`is_kinematic()`
`set_kinematic()`
`add_force()`
`add_torque()`
`add_force_at()`
`push()`
`push_at()`
`break_joint()`
`is_joint_broken()`

`tm_physx_scene_api_version`
## API
### `tm_physx_scene_o`
~~~c typedef struct tm_physx_scene_o tm_physx_scene_o; ~~~
### `tm_physx_actor_o`
~~~c typedef struct tm_physx_actor_o tm_physx_actor_o; ~~~
### `tm_physx_shape_o`
~~~c typedef struct tm_physx_shape_o tm_physx_shape_o; ~~~
### `tm_physx_joint_o`
~~~c typedef struct tm_physx_joint_o tm_physx_joint_o; ~~~
### `tm_physx_mover_o`
~~~c typedef struct tm_physx_mover_o tm_physx_mover_o; ~~~
### `TM_TT_TYPE__PHYSX_RIGID_STATIC_COMPONENT`
~~~c #define TM_TT_TYPE__PHYSX_RIGID_STATIC_COMPONENT "tm_physx_rigid_static_component" #define TM_TT_TYPE_HASH__PHYSX_RIGID_STATIC_COMPONENT TM_STATIC_HASH("tm_physx_rigid_static_component", 0x3eefdbd1f78914a2ULL) ~~~
### `TM_TT_TYPE__PHYSX_RIGID_BODY_COMPONENT`
~~~c #define TM_TT_TYPE__PHYSX_RIGID_BODY_COMPONENT "tm_physx_rigid_body_component" #define TM_TT_TYPE_HASH__PHYSX_RIGID_BODY_COMPONENT TM_STATIC_HASH("tm_physx_rigid_body_component", 0xc3da0fe4200c7849ULL) ~~~
### `TM_TT_TYPE__PHYSX_RIGID_BODY_SHAPE_COMPONENT`
~~~c #define TM_TT_TYPE__PHYSX_RIGID_BODY_SHAPE_COMPONENT "tm_physx_rigid_body_shape_component" #define TM_TT_TYPE_HASH__PHYSX_RIGID_BODY_SHAPE_COMPONENT TM_STATIC_HASH("tm_physx_rigid_body_shape_component", 0x992878166693e1f5ULL) ~~~
### `TM_TT_TYPE__PHYSX_JOINT_COMPONENT`
~~~c #define TM_TT_TYPE__PHYSX_JOINT_COMPONENT "tm_physx_joint_component" #define TM_TT_TYPE_HASH__PHYSX_JOINT_COMPONENT TM_STATIC_HASH("tm_physx_joint_component", 0x89a451f03be2ffbfULL) ~~~
### `TM_TT_TYPE__PHYSX_MOVER_COMPONENT`
~~~c #define TM_TT_TYPE__PHYSX_MOVER_COMPONENT "tm_physx_mover_component" #define TM_TT_TYPE_HASH__PHYSX_MOVER_COMPONENT TM_STATIC_HASH("tm_physx_mover_component", 0x9900daa429805a72ULL) ~~~
### `TM_TT_TYPE__PHYSX_VISUALIZATION_PARAMETERS`
~~~c #define TM_TT_TYPE__PHYSX_VISUALIZATION_PARAMETERS "tm_physx_visualization_parameters" #define TM_TT_TYPE_HASH__PHYSX_VISUALIZATION_PARAMETERS TM_STATIC_HASH("tm_physx_visualization_parameters", 0xd912e0a560fa2858ULL) ~~~
### `enum TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS`
~~~c enum { TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__VISUALIZE, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__SCALE, // float TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__BODY_AXES, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__CONTACT_POINT, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__ACTOR_AXES, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__COLLISION_AABBS, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__COLLISION_SHAPES, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__COLLISION_DYNAMIC, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__JOINT_LOCAL_FRAMES, // bool TM_TT_PROP__PHYSX_VISUALIZATION_PARAMETERS__JOINT_LIMITS, // bool }; ~~~
### `TM_PHYSX_CONVEX_COOKED_DATA_FORMAT`
~~~c #define TM_PHYSX_CONVEX_COOKED_DATA_FORMAT "tm_physx_convex_cooked_data" #define TM_PHYSX_MESH_COOKED_DATA_FORMAT "tm_physx_mesh_cooked_data" #define TM_PHYSX_HEIGHTFIELD_COOKED_DATA_FORMAT "tm_physx_heightfield_cooked_data" ~~~ Format for cooked convex data.
### `TM_ENTITY_BB__PHYSX_SCENE`
~~~c #define TM_ENTITY_BB__PHYSX_SCENE ~~~
### `struct tm_physx_rigid_static_component_t`
~~~c struct tm_physx_rigid_static_component_t { tm_physx_actor_o *actor; }; ~~~
### `struct tm_physx_rigid_body_component_t`
~~~c struct tm_physx_rigid_body_component_t { tm_physx_actor_o *actor; }; ~~~
### `struct tm_physx_rigid_body_shape_component_t`
~~~c struct tm_physx_rigid_body_shape_component_t { tm_entity_t body_entity; tm_physx_shape_o *shape; }; ~~~
### `struct tm_physx_joint_component_t`
~~~c struct tm_physx_joint_component_t { tm_physx_joint_o *joint; }; ~~~
### `struct tm_physx_mover_component_t`
~~~c struct tm_physx_mover_component_t { tm_physx_mover_o *mover; uint32_t collision_idx; tm_vec3_t velocity; bool is_standing; bool disable_gravity; TM_PAD(6); }; ~~~
### `TM_ENTITY_SYSTEM__PHYSX`
~~~c #define TM_ENTITY_SYSTEM__PHYSX ~~~ Entity system that updates PhysX.
### `struct tm_physx_scene_settings_t`
~~~c typedef struct tm_physx_scene_settings_t { // If this flag is set -- the physics simulation is run in "editor" mode. This means that no // dynamic bodies are created -- instead all bodies are created static. This is useful in an // "editor" interface, where we don't want physics to run. Default: `false`. bool editor_mode; // If this flag is set, continuous collision detection (CCD) is enabled. Default: `true`. bool ccd; TM_PAD(2); // Gravity vector in the scene. Default: `(0, -9.81, 0)`. tm_vec3_t gravity; // Provides a bounding box for the scene. Default: `(-inf, -100, -inf) -- (inf, inf, inf)`. tm_vec3_t bounding_box_min, bounding_box_max; } tm_physx_scene_settings_t; ~~~
### `struct tm_physx_raycast_flags_t`
Flags for raycasts. ~~~c typedef struct tm_physx_raycast_flags_t { // Ignore static shapes. bool ignore_static; // Ignore dynamic shapes. bool ignore_dynamic; } tm_physx_raycast_flags_t; ~~~
### `struct tm_physx_raycast_hit_t`
Describes a hit found by a raycast. ~~~c typedef struct tm_physx_raycast_hit_t { // Position of the hit. tm_vec3_t pos; // Shape surface normal at the hit point. tm_vec3_t normal; // Distance the raycast travelled before hitting. float distance; TM_PAD(4); // Entity that owns the body that was hit. tm_entity_t body; // Entity that owns the shape that was hit. tm_entity_t shape; } tm_physx_raycast_hit_t; ~~~
### `struct tm_physx_raycast_t`
Return value of a PhysX raycast. ~~~c typedef struct tm_physx_raycast_t { // True, if a blocking hit was found. bool has_block; TM_PAD(7); // Describes the blocking hit (if any). tm_physx_raycast_hit_t block; // Returns the number of touching hits found (if any). uint32_t num_touches; TM_PAD(4); } tm_physx_raycast_t; ~~~
### `struct tm_physx_overlap_hit_t`
Describes a hit found by an overlap. ~~~c typedef struct tm_physx_overlap_hit_t { // Entity that owns the body that was hit. tm_entity_t body; // Entity that owns the shape that was hit. tm_entity_t shape; } tm_physx_overlap_hit_t; ~~~
### `struct tm_physx_penetration_t`
Describes a physics pentetration with the direction and depth needed to get out of the penetration. ~~~c typedef struct tm_physx_penetration_t { // False if these objects do not overlap, in which case `direction` and `depth` will be zeroed. bool has_overlap; TM_PAD(3); // Unit vector that describes the direction `shape_0` passed to `compute_penetration` has to // translate in in order to get out of the penetration. tm_vec3_t direction; // Non-negative number that describes the penetration depth. float depth; } tm_physx_penetration_t; ~~~
### `TM_PHYSX_RAYCAST__COLLIDES_WITH_ALL`
~~~c #define TM_PHYSX_RAYCAST__COLLIDES_WITH_ALL 0xffffffffffffffffULL ~~~ Special value to use for `collision_id` to get a raycast that collides with everything.
### `TM_PHYSX_ON_CONTACT_EVENT`
~~~c #define TM_PHYSX_ON_CONTACT_EVENT ~~~ Used to report contact events. Note: When two actors contact at multiple points, we still only report a single contact event -- for the "first" contact point found.
### `struct tm_physx_on_contact_t`
~~~c typedef struct tm_physx_on_contact_t { // Entity of actors involed in contact. tm_entity_t actor_0, actor_1; // Entity of shapes involved in contact. tm_entity_t shape_0, shape_1; // Position where contact occurred. tm_vec3_t pos; // The normal of the contacting surfaces at the hit point. The normal goes from e1 -> e0. tm_vec3_t normal; // True if this contact is the first touch between the two actors. False for continuous touch // (if enabled). bool first_touch; // True if this is a lost touch event. (Lost touch reporting must be enabled to receive lost // touch events). bool lost_touch; TM_PAD(6); } tm_physx_on_contact_t; ~~~
### `TM_PHYSX_ON_TRIGGER_EVENT`
~~~c #define TM_PHYSX_ON_TRIGGER_EVENT ~~~ Used to report contacts with trigger shapes.
### `struct tm_physx_on_trigger_t`
~~~c typedef struct tm_physx_on_trigger_t { // The entity of the trigger's actor. tm_entity_t trigger_entity; // The entity of the trigger's collision shape. tm_entity_t trigger_shape; // The entity of the actor that contacted the trigger. tm_entity_t touched_entity; // The entity of the shape that contacted the trigger. tm_entity_t touched_shape; // *true* if this is a lost touch notification, otherwise it is a touch notification. bool lost_touch; TM_PAD(7); } tm_physx_on_trigger_t; ~~~
### `TM_PHYSX_ON_JOINT_BREAK_EVENT`
~~~c #define TM_PHYSX_ON_JOINT_BREAK_EVENT ~~~ Used to report breaking joints
### `struct tm_physx_on_joint_break_t`
~~~c typedef struct tm_physx_on_joint_break_t { // The entity of the joint. tm_entity_t joint; } tm_physx_on_joint_break_t; ~~~
### `enum tm_physx_force_flags`
Specifies how a force or torque should be applied. ~~~c enum tm_physx_force_flags { // If set, a normal force is applied. This has units (kg*m)/(s^2), i.e. no time has been // multiplied into the force parameter. TM_PHYSX_FORCE_FLAGS__FORCE = 0, // If set, the force is applied as an impulse, i.e. the time step (dt) is assumed to have // already been multiplied into the force parameter. TM_PHYSX_FORCE_FLAGS__IMPULSE = 1, // If set, the force is applied as an acceleration. I.e., the body's mass is assumed to have // already been divided out of the force parameter. TM_PHYSX_FORCE_FLAGS__ACCELERATION = 2, // A shortcut for `(TM_PHYSX_FORCE_FLAGS__IMPULSE | TM_PHYSX_FORCE_FLAGS__ACCELERATION)`. I.e., // in this case the time step is assumed to have been multiplied in and the mass divided. This // makes the force parameter act as a velocity change. TM_PHYSX_FORCE_FLAGS__VELOCITY_CHANGE = 3, // If set, the force is assumed to be continuous. I.e., it will be applied in every physics // substep, or not applied at all, if no substeps are taken. // // Continuous forces are not applied to sleeping bodies. It is assumed that if the body came to // rest under the continuous force, it should continue to stay at rest. This allows bodies to // come to rest in a force field, for example. If you are applying a continuous force that // changes drastically, you may want to explicitly wake bodies so that they can react to the // changes. // // Note that it does not make sense to combine this flag with [[TM_PHYSX_FORCE_FLAGS__IMPULSE]], // since an impulse represents an instant change. TM_PHYSX_FORCE_FLAGS__CONTINUOUS = 4, }; ~~~
### `struct tm_physx_scene_api`
#### `default_scene_settings()` ~~~c tm_physx_scene_settings_t (*default_scene_settings)(void); ~~~ Returns the default settings for a PhysX scene. Used with a call to `create()`. #### `parse_scene_settings()` ~~~c tm_physx_scene_settings_t (*parse_scene_settings)(struct tm_the_truth_o *tt, tm_tt_id_t id); ~~~ Parses the settings for a PhysX scene from a `TM_TT_TYPE__PHYSICS_SCENE_SETTINGS` object `id` in The Truth `tt`. If `id` is `NULL`, returns the default settings. #### `create()` ~~~c tm_physx_scene_o *(*create)(struct tm_entity_context_o *ctx, tm_physx_scene_settings_t settings); ~~~ Creates the PhysX scene in the specified entity context. Note that the PhysX scene is not automatically created by `TM_ENTITY_CREATE_COMPONENTS_ALL`, you have to explicitly create it using this call. #### `update()` ~~~c void (*update)(tm_physx_scene_o *physx, float dt); ~~~ Updates the physics simulation. #### `visualize()` ~~~c void (*visualize)(tm_physx_scene_o *physx, struct tm_primitive_drawer_buffer_t *pbuffer, struct tm_primitive_drawer_buffer_t *vbuffer, struct tm_allocator_i *a); ~~~ Draw PhysX debug visualization into the specified `pbuf` and `vbuf`. #### `visualization_settings()` ~~~c tm_tt_id_t (*visualization_settings)(tm_physx_scene_o *physx, struct tm_the_truth_o *settings_tt); ~~~ Returns the settings objects to control the physics visualization settings in The Truth `settings_tt`. If no such object exists, it is automatically created. #### `set_visualization_settings()` ~~~c void (*set_visualization_settings)(tm_physx_scene_o *physx, struct tm_the_truth_o *settings_tt, tm_tt_id_t settings_id); ~~~ Set an object to use for the PhysX visualization settings. #### `raycast()` ~~~c tm_physx_raycast_t (*raycast)(tm_physx_scene_o *physx, tm_vec3_t from, tm_vec3_t dir, float distance, tm_tt_id_t collision_id, tm_physx_raycast_flags_t flags, tm_physx_raycast_hit_t *touches, uint32_t max_touches); ~~~ Performs a raycast in the PhysX world and returns the result. The raycast starts at `from`, is cast in the direction of `dir` (a unit vector) for the specified `distance`. `collision_id` specifies the ID in The Truth of the `TM_TT_TYPE__PHYSICS_COLLISION` object that holds the raycast's collision type. This determines which shape the raycast collides with (by the `collides_with` value of the collision type). A value of `0` will use the `Default` collision type. A value of `TM_PHYSX_RAYCAST__COLLIDES_WITH_ALL` will cast a ray that collides with everything. `touches` is an array of size `max_touches` used to return the touching hits (if any). You can use a nullptr if you don't wish to receive touching hits. #### `sweep()` ~~~c tm_physx_raycast_t (*sweep)(tm_physx_scene_o *physx, const struct tm_physics_shape_component_t *shape, const tm_transform_t *shape_transform, tm_vec3_t dir, float distance, tm_tt_id_t collision_id, tm_physx_raycast_flags_t flags, tm_physx_raycast_hit_t *touches, uint32_t max_touches); ~~~ As `raycast()` but performs a shape sweep instead. #### `overlap()` ~~~c uint32_t (*overlap)(tm_physx_scene_o *physx, const struct tm_physics_shape_component_t *shape, const tm_transform_t *shape_transform, tm_tt_id_t collision_id, tm_physx_raycast_flags_t flags, tm_physx_overlap_hit_t *touches, uint32_t max_touches); ~~~ Performs an overlap check between the specified shape and the scene. Returns the number of found touching entities. #### `compute_penetration()` ~~~c tm_physx_penetration_t (*compute_penetration)(tm_physx_scene_o *physx, const struct tm_physics_shape_component_t *shape_0, const tm_transform_t *transform_0, const struct tm_physics_shape_component_t *shape_1, const tm_transform_t *transform_1); ~~~ If the two passed shapes overlap, this will return a `tm_physx_penetration_t` struct which tells the users the minimum translational distance to get out of the penetration. The `direction` of `tm_physx_penetration_t` is the direction that `shape_0` requires to get out of the penetration. #### `on_contact()` ~~~c /* carray */ tm_physx_on_contact_t *(*on_contact)(tm_physx_scene_o *physx); ~~~ Returns a carray of all the events from the last frame. Note that PhysX may take 0, 1, 2 or more substeps for each game frame and that will influence the number of events returned by these functions. I.e., if PhysX take no steps, no events will be returned. If PhysX takes 2 steps, all the events from both those steps will be returned, twice the number of events you would see if PhysX just took a single step. #### `on_trigger()` ~~~c /* carray */ tm_physx_on_trigger_t *(*on_trigger)(tm_physx_scene_o *physx); ~~~ #### `on_joint_break()` ~~~c /* carray */ tm_physx_on_joint_break_t *(*on_joint_break)(tm_physx_scene_o *physx); ~~~ #### `velocity()` ~~~c tm_vec3_t (*velocity)(tm_physx_scene_o *physx, tm_entity_t e); ~~~ Gets/sets the velocity of the rigid body component of the entity `e`. ???: Should this be done with a component interface instead of the C API, or maybe both? #### `set_velocity()` ~~~c void (*set_velocity)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t vel); ~~~ #### `angular_velocity()` ~~~c tm_vec3_t (*angular_velocity)(tm_physx_scene_o *physx, tm_entity_t e); ~~~ #### `set_angular_velocity()` ~~~c void (*set_angular_velocity)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t vel); ~~~ #### `is_kinematic()` ~~~c bool (*is_kinematic)(tm_physx_scene_o *physx, tm_entity_t e); ~~~ Gets/sets kinematic flag of the rigid body component of the entity `e`. ??? Should this be done instead by directly manipulating the `kinematic` flag of the entity data, or should both modes be supported? #### `set_kinematic()` ~~~c void (*set_kinematic)(tm_physx_scene_o *physx, tm_entity_t e, bool is_kinematic); ~~~ #### `add_force()` ~~~c void (*add_force)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t force, uint32_t flags); ~~~ Applies force or torque to the rigid body in `e`. `flags` is a combination of `enum tm_physx_force_flags` that specifies how the force should be applied. #### `add_torque()` ~~~c void (*add_torque)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t torque, uint32_t flags); ~~~ #### `add_force_at()` ~~~c void (*add_force_at)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t force, tm_vec3_t pos, uint32_t flags); ~~~ Applies both force and torque by applying force at a specific (global) position `pos`. Note that the flag `TM_PHYSX_FORCE_FLAGS__ACCELERATION` cannot be used in this case, since a velocity change is not enough to determine the torque to apply. #### `push()` ~~~c void (*push)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t vel, float mass); ~~~ Convenience function for applying forces from things like bullets, shrapnel, etc. Applies a force as if the body had been hit by a point `mass` travelling it speed `vel` (relative to the hit object). A perfectly inelastic collision is assumed. #### `push_at()` ~~~c void (*push_at)(tm_physx_scene_o *physx, tm_entity_t e, tm_vec3_t vel, float mass, tm_vec3_t pos); ~~~ As `push()`, but also applies torque to the pushed body by pushing it at a specific position `pos` (in world coordinates). #### `break_joint()` ~~~c void (*break_joint)(tm_physx_scene_o *physx, tm_entity_t e); ~~~ Breaks the joint in entity `e`. (If it has an unbroken joint.) #### `is_joint_broken()` ~~~c bool (*is_joint_broken)(tm_physx_scene_o *physx, tm_entity_t e); ~~~ Returns *true* if `e` has a joint and the joint is broken. If `e` has no joint, or the joint is still intact, returns *false*.
### `tm_physx_scene_api_version`
~~~c #define tm_physx_scene_api_version ~~~