Files
armorpaint/paint/sources/physics_world.ts
T

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-03-13 23:50:11 +01:00
///if arm_physics
2025-03-11 15:17:26 +01:00
///include "../libs/asim.h"
2024-08-05 23:24:40 +02:00
2025-02-28 18:27:40 +01:00
declare function asim_world_create(): void;
declare function asim_world_destroy(): void;
2025-08-27 23:45:33 +02:00
declare function asim_world_update(time_step: f32): void;
2025-02-28 18:27:40 +01:00
declare function asim_world_get_contact(): physics_pair_t;
2024-08-05 23:24:40 +02:00
declare type physics_pair_t = {
pos_a_x: f32;
pos_a_y: f32;
pos_a_z: f32;
2024-03-21 21:06:41 +01:00
};
2024-03-13 23:50:11 +01:00
2024-08-05 23:24:40 +02:00
type physics_world_t = {
empty?: i32;
2024-08-02 20:41:11 +02:00
};
2024-03-13 23:50:11 +01:00
2024-08-02 20:41:11 +02:00
let physics_world_active: physics_world_t;
2024-03-13 23:50:11 +01:00
2024-08-05 23:24:40 +02:00
function physics_world_create(): physics_world_t {
2025-02-28 18:27:40 +01:00
asim_world_create();
2024-08-05 23:24:40 +02:00
let world: physics_world_t = {};
physics_world_active = world;
return world;
2024-03-13 23:50:11 +01:00
}
2024-08-02 20:41:11 +02:00
function physics_world_update(world: physics_world_t) {
2025-08-27 23:45:33 +02:00
asim_world_update(sys_delta());
2024-03-13 23:50:11 +01:00
2024-08-05 23:24:40 +02:00
let keys: i32[] = imap_keys(physics_body_object_map);
for (let i: i32 = 0; i < keys.length; ++i) {
let body: physics_body_t = map_get(physics_body_object_map, keys[i]);
physics_body_update(body);
}
2024-03-13 23:50:11 +01:00
}
2024-08-02 20:41:11 +02:00
function physics_world_get_contact_pairs(world: physics_world_t, body: physics_body_t): physics_pair_t[] {
2024-08-05 23:24:40 +02:00
let pairs: physics_pair_t[] = [];
2025-02-28 18:27:40 +01:00
let p: physics_pair_t = asim_world_get_contact();
2024-08-05 23:24:40 +02:00
array_push(pairs, p);
return pairs;
}
function physics_world_destroy() {
if (physics_world_active != null) {
2025-02-28 18:27:40 +01:00
asim_world_destroy();
2024-08-05 23:24:40 +02:00
}
2024-03-13 23:50:11 +01:00
}
///end