reworked constraint solver to work relative to the overlap point
This commit is contained in:
parent
635fb7b69f
commit
f8462d8e2c
|
@ -41,16 +41,15 @@ Vector _internal_calculate_contact_force(RigidBody* self, Contact* contact) {
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
int _internal_default_contact_solver(RigidBody* body, Contact* contact, Transform pre_solve) {
|
int _internal_default_contact_solver(RigidBody* body, Contact* contact, Transform pre_solve) {
|
||||||
// the desired position is anywhere the overlapping vertex is further along the normal than the contact point
|
|
||||||
Collision hit = contact->hit;
|
Collision hit = contact->hit;
|
||||||
Transform* trans = rigidbody_get_transform(body);
|
Transform* trans = rigidbody_get_transform(body);
|
||||||
const Vector world_collision_point = vaddf(transform_point(&pre_solve, hit.point), hit.penetration_vector);
|
const Vector world_collision_point = vaddf(transform_point(&pre_solve, hit.point), hit.penetration_vector);
|
||||||
const float min_dot = vdotf(hit.normal, world_collision_point);
|
const float current_dot = vdotf(hit.normal, vsubf(transform_point(trans, hit.point), world_collision_point));
|
||||||
const float current_dot = vdotf(hit.normal, transform_point(trans, hit.point));
|
if(current_dot >= 0.0)
|
||||||
if(current_dot >= min_dot)
|
|
||||||
return 1;
|
return 1;
|
||||||
const Vector target = vaddf(trans->position, vmulff(hit.normal, min_dot - current_dot));
|
// the desired position is anywhere the overlapping vertex is further along the normal than the contact point
|
||||||
trans->position = vmovetowardsf(trans->position, target, 0.01f);
|
const Vector target = vaddf(trans->position, vmulff(hit.normal, -current_dot));
|
||||||
|
trans->position = vmovetowardsf(trans->position, target, 1.f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue