implemented collision constraint solver
This commit is contained in:
parent
256fef97d9
commit
e86fa1bdef
10 changed files with 95 additions and 62 deletions
23
src/player.c
23
src/player.c
|
|
@ -25,23 +25,6 @@ void player_spawn(Player* self, Vector at) {
|
|||
}
|
||||
|
||||
void player_collision_solver(Player* self, List* contacts) {
|
||||
RigidBody* body = self->rigidbody;
|
||||
Collision hit;
|
||||
const Vector vel = vaddf(rigidbody_get_velocity(body), vmulff(rigidbody_get_force(body), delta_time()));
|
||||
Vector avrg = ZeroVector;
|
||||
int n = 0;
|
||||
list_foreach(Contact, contact, contacts) {
|
||||
hit = contact->hit;
|
||||
Vector norm = vnormalizedf(hit.penetration_vector);
|
||||
LOG_INFO("n %f %f", norm.x, norm.y);
|
||||
float dot = fmaxf(0, vdotf(norm, hit.velocity));
|
||||
avrg = vaddf(vmulff(avrg, (float)n), vsubf(vel, vmulff(norm, dot)));
|
||||
++n;
|
||||
avrg = vmulff(avrg, 1.0f / (float)n);
|
||||
}
|
||||
LOG_INFO("vel %f %f", vel.x, vel.y);
|
||||
LOG_INFO("for %f %f", avrg.x, avrg.y);
|
||||
// rigidbody_add_impulse(body, vinvf(avrg), 0);
|
||||
default_contact_solver(Player_as_PhysicsEntity(self), contacts);
|
||||
}
|
||||
|
||||
|
|
@ -78,11 +61,11 @@ void player_start(Player* self) {
|
|||
|
||||
void player_update(Player* self, float dt) {
|
||||
Vector velocity = rigidbody_get_velocity(self->rigidbody);
|
||||
Vector velocity_target = {directional.x, velocity.y};
|
||||
Vector velocity_target = {directional.x, directional.y};
|
||||
rigidbody_accelerate(self->rigidbody, vmulff(vsubf(velocity_target, velocity), 20.f), 0);
|
||||
rigidbody_accelerate(self->rigidbody, (Vector){0.0f, 20.f}, 0);
|
||||
// rigidbody_accelerate(self->rigidbody, (Vector){0.0f, 20.f}, 0);
|
||||
|
||||
LOG_INFO("%f %f", self->transform.position.x, self->transform.position.y);
|
||||
// LOG_INFO("%f %f", self->transform.position.x, self->transform.position.y);
|
||||
}
|
||||
|
||||
void player_collision(Player* self, Collision hit) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue