Skip to content

Commit

Permalink
Remove damping threshold and clamp damping to 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed May 25, 2024
1 parent f3cd4c5 commit 7178ab0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
18 changes: 6 additions & 12 deletions src/api/l_physics_collider.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,35 +442,29 @@ static int l_lovrColliderSetAngularVelocity(lua_State* L) {

static int l_lovrColliderGetLinearDamping(lua_State* L) {
Collider* collider = luax_checkcollider(L, 1);
float damping, threshold;
lovrColliderGetLinearDamping(collider, &damping, &threshold);
float damping = lovrColliderGetLinearDamping(collider);
lua_pushnumber(L, damping);
lua_pushnumber(L, threshold);
return 2;
return 1;
}

static int l_lovrColliderSetLinearDamping(lua_State* L) {
Collider* collider = luax_checkcollider(L, 1);
float damping = luax_checkfloat(L, 2);
float threshold = luax_optfloat(L, 3, 0.0f);
lovrColliderSetLinearDamping(collider, damping, threshold);
lovrColliderSetLinearDamping(collider, damping);
return 0;
}

static int l_lovrColliderGetAngularDamping(lua_State* L) {
Collider* collider = luax_checkcollider(L, 1);
float damping, threshold;
lovrColliderGetAngularDamping(collider, &damping, &threshold);
float damping = lovrColliderGetAngularDamping(collider);
lua_pushnumber(L, damping);
lua_pushnumber(L, threshold);
return 2;
return 1;
}

static int l_lovrColliderSetAngularDamping(lua_State* L) {
Collider* collider = luax_checkcollider(L, 1);
float damping = luax_checkfloat(L, 2);
float threshold = luax_optfloat(L, 3, 0.0f);
lovrColliderSetAngularDamping(collider, damping, threshold);
lovrColliderSetAngularDamping(collider, damping);
return 0;
}

Expand Down
22 changes: 10 additions & 12 deletions src/modules/physics/physics.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ Collider* lovrColliderCreate(World* world, float position[3], Shape* shape) {
quat_identity(collider->lastOrientation);

if (type == JPH_MotionType_Dynamic) {
lovrColliderSetLinearDamping(collider, world->defaultLinearDamping, 0.f);
lovrColliderSetAngularDamping(collider, world->defaultAngularDamping, 0.f);
lovrColliderSetLinearDamping(collider, world->defaultLinearDamping);
lovrColliderSetAngularDamping(collider, world->defaultAngularDamping);
lovrColliderSetSleepingAllowed(collider, world->defaultIsSleepingAllowed);
}

Expand Down Expand Up @@ -1452,26 +1452,24 @@ void lovrColliderSetAngularVelocity(Collider* collider, float velocity[3]) {
JPH_BodyInterface_SetAngularVelocity(collider->world->bodies, collider->id, vec3_toJolt(velocity));
}

void lovrColliderGetLinearDamping(Collider* collider, float* damping, float* threshold) {
float lovrColliderGetLinearDamping(Collider* collider) {
JPH_MotionProperties* properties = JPH_Body_GetMotionProperties(collider->body);
*damping = JPH_MotionProperties_GetLinearDamping(properties);
*threshold = 0.f;
return JPH_MotionProperties_GetLinearDamping(properties);
}

void lovrColliderSetLinearDamping(Collider* collider, float damping, float threshold) {
void lovrColliderSetLinearDamping(Collider* collider, float damping) {
JPH_MotionProperties* properties = JPH_Body_GetMotionProperties(collider->body);
JPH_MotionProperties_SetLinearDamping(properties, damping);
JPH_MotionProperties_SetLinearDamping(properties, MAX(damping, 0.f));
}

void lovrColliderGetAngularDamping(Collider* collider, float* damping, float* threshold) {
float lovrColliderGetAngularDamping(Collider* collider) {
JPH_MotionProperties* properties = JPH_Body_GetMotionProperties(collider->body);
*damping = JPH_MotionProperties_GetAngularDamping(properties);
*threshold = 0.f;
return JPH_MotionProperties_GetAngularDamping(properties);
}

void lovrColliderSetAngularDamping(Collider* collider, float damping, float threshold) {
void lovrColliderSetAngularDamping(Collider* collider, float damping) {
JPH_MotionProperties* properties = JPH_Body_GetMotionProperties(collider->body);
JPH_MotionProperties_SetAngularDamping(properties, damping);
JPH_MotionProperties_SetAngularDamping(properties, MAX(damping, 0.f));
}

void lovrColliderApplyForce(Collider* collider, float force[3]) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/physics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ void lovrColliderGetLinearVelocity(Collider* collider, float velocity[3]);
void lovrColliderSetLinearVelocity(Collider* collider, float velocity[3]);
void lovrColliderGetAngularVelocity(Collider* collider, float velocity[3]);
void lovrColliderSetAngularVelocity(Collider* collider, float velocity[3]);
void lovrColliderGetLinearDamping(Collider* collider, float* damping, float* threshold);
void lovrColliderSetLinearDamping(Collider* collider, float damping, float threshold);
void lovrColliderGetAngularDamping(Collider* collider, float* damping, float* threshold);
void lovrColliderSetAngularDamping(Collider* collider, float damping, float threshold);
float lovrColliderGetLinearDamping(Collider* collider);
void lovrColliderSetLinearDamping(Collider* collider, float damping);
float lovrColliderGetAngularDamping(Collider* collider);
void lovrColliderSetAngularDamping(Collider* collider, float damping);
void lovrColliderApplyForce(Collider* collider, float force[3]);
void lovrColliderApplyForceAtPosition(Collider* collider, float force[3], float position[3]);
void lovrColliderApplyTorque(Collider* collider, float torque[3]);
Expand Down

0 comments on commit 7178ab0

Please sign in to comment.