Fixed orbit

This commit is contained in:
h3cx committed 2026-10-01 19:09:54 +02:00
1 parent 2a7669aa21
commit c729ab4f90
7 files changed
+110 -85

No files matched your search

+15 -17
View File
@@ -73,25 +73,23 @@ void collide_rigid(mass_body_t *a, float restitution) {
}
void mechanics(universe_t *uni) {
mass_body_t body_1;
mass_body_t body_2;
Vector2 collision;
Vector2 scaled_speed;
// Advance every body to the same simulated time before checking contacts.
for (unsigned int i = 0; i < uni->num_bodies; i++) {
body_1 = uni->bodies[i];
scaled_speed = vec2_scale(body_1.speed, 1.0 / simx);
body_1.position = vec2_sum(body_1.position, scaled_speed);
if (i < uni->num_bodies - 1) {
for (unsigned int y = i + 1; y < uni->num_bodies; y++) {
body_2 = uni->bodies[y];
collision = body_collision(&body_1, &body_2);
if (!vec2_is_null(collision)) {
collide(&body_1, &body_2, collision, 0.99);
}
uni->bodies[y] = body_2;
mass_body_t *body = &uni->bodies[i];
body->position = vec2_sum(body->position,
vec2_scale(body->speed, PHYSICS_TIMESTEP));
}
for (unsigned int i = 0; i < uni->num_bodies; i++) {
mass_body_t *body_1 = &uni->bodies[i];
for (unsigned int y = i + 1; y < uni->num_bodies; y++) {
mass_body_t *body_2 = &uni->bodies[y];
Vector2 collision = body_collision(body_1, body_2);
if (!vec2_is_null(collision)) {
collide(body_1, body_2, collision, 0.99);
}
}
collide_rigid(&body_1, 1.1);
uni->bodies[i] = body_1;
if (WALL_COLLISIONS) {
collide_rigid(body_1, 1.0f);
}
}
}