Skip to content
Snippets Groups Projects
Commit 2149b27a authored by Florian Burgener's avatar Florian Burgener
Browse files

Anti-aliasing

parent db18d756
Branches
No related tags found
No related merge requests found
*.o
main
main.exe
.vscode
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 $@
......
......@@ -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];
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment