Updated canvas size
This commit is contained in:
1 file changed
+16
-17
+16
-17
@@ -2,7 +2,6 @@
|
|||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
Vector2 body_collision(mass_body_t *a, mass_body_t *b) {
|
Vector2 body_collision(mass_body_t *a, mass_body_t *b) {
|
||||||
Vector2 diff = vec2_diff(&a->position, &b->position);
|
Vector2 diff = vec2_diff(&a->position, &b->position);
|
||||||
float len = vec2_len(diff);
|
float len = vec2_len(diff);
|
||||||
@@ -49,8 +48,8 @@ void collide(mass_body_t *a, mass_body_t *b, const Vector2 *normal,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void collide_rigid(mass_body_t *a, float restitution) {
|
void collide_rigid(mass_body_t *a, float restitution) {
|
||||||
float max_x = GetRenderWidth() / 2.0f - a->radius;
|
float max_x = GetRenderWidth() * 10 / 2.0f - a->radius;
|
||||||
float max_y = GetRenderHeight() / 2.0f - a->radius;
|
float max_y = GetRenderHeight() * 10 / 2.0f - a->radius;
|
||||||
|
|
||||||
if (a->position.x > max_x) {
|
if (a->position.x > max_x) {
|
||||||
a->position.x = max_x;
|
a->position.x = max_x;
|
||||||
@@ -73,26 +72,26 @@ void collide_rigid(mass_body_t *a, float restitution) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mechanics(universe_t* uni){
|
void mechanics(universe_t *uni) {
|
||||||
mass_body_t body_1;
|
mass_body_t body_1;
|
||||||
mass_body_t body_2;
|
mass_body_t body_2;
|
||||||
Vector2 collision;
|
Vector2 collision;
|
||||||
Vector2 scaled_speed;
|
Vector2 scaled_speed;
|
||||||
for (unsigned int i = 0; i < uni->num_bodies; i++) {
|
for (unsigned int i = 0; i < uni->num_bodies; i++) {
|
||||||
body_1 = uni->bodies[i];
|
body_1 = uni->bodies[i];
|
||||||
scaled_speed = vec2_scale(&body_1.speed, 1.0 / simx);
|
scaled_speed = vec2_scale(&body_1.speed, 1.0 / simx);
|
||||||
body_1.position = vec2_sum(&body_1.position, &scaled_speed);
|
body_1.position = vec2_sum(&body_1.position, &scaled_speed);
|
||||||
if (i < uni->num_bodies - 1) {
|
if (i < uni->num_bodies - 1) {
|
||||||
for (unsigned int y = i + 1; y < uni->num_bodies; y++) {
|
for (unsigned int y = i + 1; y < uni->num_bodies; y++) {
|
||||||
body_2 = uni->bodies[y];
|
body_2 = uni->bodies[y];
|
||||||
collision = body_collision(&body_1, &body_2);
|
collision = body_collision(&body_1, &body_2);
|
||||||
if (!vec2_is_null(collision)) {
|
if (!vec2_is_null(collision)) {
|
||||||
collide(&body_1, &body_2, &collision, 1.0);
|
collide(&body_1, &body_2, &collision, 1.0);
|
||||||
}
|
|
||||||
uni->bodies[y] = body_2;
|
|
||||||
}
|
}
|
||||||
|
uni->bodies[y] = body_2;
|
||||||
}
|
}
|
||||||
collide_rigid(&body_1, 1.1);
|
|
||||||
uni->bodies[i] = body_1;
|
|
||||||
}
|
}
|
||||||
|
collide_rigid(&body_1, 1.1);
|
||||||
|
uni->bodies[i] = body_1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user