diff --git a/base/plugins/phys_jolt/phys_jolt.cpp b/base/plugins/phys_jolt/phys_jolt.cpp index 8bceecd7..2725666d 100644 --- a/base/plugins/phys_jolt/phys_jolt.cpp +++ b/base/plugins/phys_jolt/phys_jolt.cpp @@ -162,15 +162,19 @@ void *_jolt_body_create(int shape, float mass, float dimx, float dimy, float dim Body *body; ShapeSettings::ShapeResult result; + if (dimx <= 0.2) dimx = 0.21; + if (dimy <= 0.2) dimy = 0.21; + if (dimz <= 0.2) dimz = 0.21; + if (shape == 0) { // Box - BoxShapeSettings shape_settings(RVec3(dimx, dimy, dimz)); + BoxShapeSettings shape_settings(RVec3(dimx / 2.0, dimy / 2.0, dimz / 2.0)); shape_settings.SetEmbedded(); result = shape_settings.Create(); } else if (shape == 1) { // Sphere - SphereShapeSettings shape_settings(dimx); + SphereShapeSettings shape_settings(dimx / 2.0); shape_settings.SetEmbedded(); result = shape_settings.Create(); } @@ -197,12 +201,13 @@ void *_jolt_body_create(int shape, float mass, float dimx, float dimy, float dim // if (ccd) { if (shape != 2) { // != Mesh settings.mMotionQuality = EMotionQuality::LinearCast; - } - MassProperties mass_prop; - mass_prop.ScaleToMass(mass); - settings.mMassPropertiesOverride = mass_prop; - settings.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia; + MassProperties mass_prop; + mass_prop.ScaleToMass(mass); + settings.mMassPropertiesOverride = mass_prop; + + settings.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia; + } body = body_interface.CreateBody(settings); body_interface.AddBody(body->GetID(), EActivation::Activate); @@ -237,6 +242,12 @@ void _jolt_body_get_rot(void *b, void *r) { q->w = rotation.GetW(); } +void _jolt_body_sync_transform(void *b, vec4_t p, quat_t r) { + BodyInterface &body_interface = physics_system->GetBodyInterface(); + Body *body = (Body *)b; + body_interface.SetPositionAndRotation(body->GetID(), RVec3(p.x, p.y, p.z), Quat(r.x, r.y, r.z, r.w), EActivation::Activate); +} + extern "C" { void jolt_world_create() { _jolt_world_create(); @@ -269,4 +280,8 @@ extern "C" { void jolt_body_get_rot(void *b, void *r) { _jolt_body_get_rot(b, r); } + + void jolt_body_sync_transform(void *b, vec4_t p, quat_t r) { + _jolt_body_sync_transform(b, p, r); + } } diff --git a/base/plugins/phys_jolt/phys_jolt.h b/base/plugins/phys_jolt/phys_jolt.h index a36b061f..e781fd42 100644 --- a/base/plugins/phys_jolt/phys_jolt.h +++ b/base/plugins/phys_jolt/phys_jolt.h @@ -1,6 +1,9 @@ #pragma once +#include "iron_vec4.h" +#include "iron_quat.h" + #ifdef __cplusplus extern "C" { #endif @@ -20,6 +23,7 @@ void* jolt_body_create(int shape, float mass, float dimx, float dimy, float dimz void jolt_body_apply_impulse(void *b, float x, float y, float z); void jolt_body_get_pos(void *b, void *p); void jolt_body_get_rot(void *b, void *r); +void jolt_body_sync_transform(void *b, vec4_t p, quat_t r); #ifdef __cplusplus } diff --git a/base/sources/physics_body.ts b/base/sources/physics_body.ts index e21bdb49..3cbc26de 100644 --- a/base/sources/physics_body.ts +++ b/base/sources/physics_body.ts @@ -7,6 +7,7 @@ declare function jolt_body_create(shape: i32, mass: f32, dimx: f32, dimy: f32, d declare function jolt_body_apply_impulse(body: any, x: f32, y: f32, z: f32): void; declare function jolt_body_get_pos(body: any, pos: vec4_t): void; declare function jolt_body_get_rot(body: any, rot: quat_t): void; +declare function jolt_body_sync_transform(body: any, pos: vec4_t, rot: quat_t): void; type physics_body_t = { _body?: any; @@ -35,7 +36,10 @@ function physics_body_init(body: physics_body_t, obj: object_t) { map_set(physics_body_object_map, obj.uid, body); body.obj = obj; + transform_compute_dim(obj.transform); body.dimx = obj.transform.dim.x; + body.dimy = obj.transform.dim.y; + body.dimz = obj.transform.dim.z; let triangles: f32[] = null; if (body.shape == physics_shape_t.MESH) { @@ -80,7 +84,8 @@ function physics_body_apply_impulse(body: physics_body_t, dir: vec4_t) { } function physics_body_sync_transform(body: physics_body_t) { - // + let transform: transform_t = body.obj.transform; + jolt_body_sync_transform(body._body, transform.loc, transform.rot); } function physics_body_update(body: physics_body_t) {