diff --git a/.gitignore b/.gitignore index 95916b85437d46518c6531e342efa1517d93339e..08922dccc5a85b6b1d5d767ebfecd7b368d6b5e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.o main +main.exe .vscode diff --git a/Makefile b/Makefile index af52a6849f1c0436abe5a4f8b63d5986244b31da..25019ee4e9b4d46db44836a9318bc24ceab3c652 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,16 @@ TARGET = main -CC:=gcc +# CCFLAGS +CC = gcc # CFLAGS:=-g -Ofast -Wall -Wextra -fsanitize=address -fsanitize=leak -std=gnu11 # CFLAGS:=-fsanitize=address -CFLAGS:=-g -O3 -Wall -Wextra -std=gnu11 -LDFLAGS:=-lm -lGL -lGLU -lglut +CFLAGS = -g -O3 -Wall -Wextra -std=gnu11 +LDFLAGS = -lm + +ifeq ($(OS),Windows_NT) + LDFLAGS += -lopengl32 -lglu32 -lfreeglut +else + LDFLAGS += -lGL -lGLU -lglut +endif %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ diff --git a/PlanetarySystem.c b/PlanetarySystem.c index 72efa145628e26b8c2b60cf91cf81b8b7a40eca5..15f48cd846e37261697d420204358693cefe5dd7 100644 --- a/PlanetarySystem.c +++ b/PlanetarySystem.c @@ -10,8 +10,8 @@ #include "Vector2.h" #include "drawing.h" -const uint32_t SCREEN_WIDTH = 1000; -const uint32_t SCREEN_HEIGHT = 1000; +const uint32_t SCREEN_WIDTH = 800; +const uint32_t SCREEN_HEIGHT = 800; const double G = 6.67430 * 1E-11; @@ -112,7 +112,7 @@ void planetary_system_update(PlanetarySystem *planetary_system, double interval) int32_t length = object->points_length; - if (length > 0 && vector2_norm(vector2_substract(object->points[0], object->current_position)) < 1E9 * 1.5) + if (length > 0 && vector2_norm(vector2_substract(object->points[0], object->current_position)) < 1E9) continue; for (int32_t j = (length == 200) ? length - 1 : length; j >= 1; j -= 1) { object->points[j] = object->points[j - 1]; diff --git a/PlanetarySystem.h b/PlanetarySystem.h index 4a5effdde4945e387f9246b9d11bfbccba4b4385..29019531a590d6f17f107f13e111747667f85e47 100644 --- a/PlanetarySystem.h +++ b/PlanetarySystem.h @@ -5,8 +5,8 @@ #include "CelestialObject.h" -const uint32_t SCREEN_WIDTH; -const uint32_t SCREEN_HEIGHT; +extern const uint32_t SCREEN_WIDTH; +extern const uint32_t SCREEN_HEIGHT; typedef struct PlanetarySystem { int32_t objects_length; diff --git a/Vector2.c b/Vector2.c index 0770586bcb122fb80859f8a33e6a00b29c987728..459a285a32ff701c18d201431ecd31509f50213d 100644 --- a/Vector2.c +++ b/Vector2.c @@ -51,8 +51,8 @@ bool vector2_is_similiar(Vector2 a, Vector2 b, double epsilon) { } Vector2 vector2_fit_canvas(Vector2 v, uint32_t width, uint32_t height) { - double x = round((width - 1) / 2.0 + v.x * (width - 1) / 2.0); - double y = round((height - 1) / 2.0 + v.y * (height - 1) / 2.0); + double x = width / 2.0 * (1 + v.x); + double y = height / 2.0 * (1 + v.y); return vector2_create(x, y); } diff --git a/main.c b/main.c index c5d2ffb50168ae3a39b74366d8e412a80030aa30..2847df6c73ea0e6aa929ede2dbbb2bc66a7b0d1b 100644 --- a/main.c +++ b/main.c @@ -52,7 +52,7 @@ void draw() { if (elapsed_time % REFRESH_RATE == 0 && elapsed_time != 0) { char title[100]; - sprintf(title, "Solar System (%d : %ld)", elapsed_time / REFRESH_RATE, (time(NULL) - true_time_shift) % 1000); + sprintf(title, "Solar System (%d : %lld)", elapsed_time / REFRESH_RATE, (time(NULL) - true_time_shift) % 1000); glutSetWindowTitle(title); } @@ -62,7 +62,7 @@ void draw() { sprintf(text, "Simulation Speed : %d days per second", time_elasping_per_second / 86400); draw_text(text, vector2_create(8, 32)); - glFlush(); + glutSwapBuffers(); } void handle_keyboard_input(unsigned char key, int UNUSED(x), int UNUSED(y)) { @@ -118,7 +118,8 @@ int main(int argc, char *argv[]) { planetary_system = planetary_system_create(); glutInit(&argc, argv); - glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutSetOption(GLUT_MULTISAMPLE, 16); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); glutCreateWindow(WINDOW_NAME);