Compare commits

..

2 Commits

3 changed files with 15 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#ifndef BASE_MATH_H #ifndef BASE_MATH_H
#define BASE_MATH_H #define BASE_MATH_H
typedef struct Vec2F32 Vec2F32; typedef union Vec2F32 Vec2F32;
union Vec2F32 { union Vec2F32 {
struct { struct {
f32 x; f32 x;
@ -10,14 +10,14 @@ union Vec2F32 {
f32 v[2]; f32 v[2];
}; };
typedef struct Vec3F32 Vec3F32; typedef union Vec3F32 Vec3F32;
union Vec3F32 { union Vec3F32 {
struct { struct {
f32 x; f32 x;
f32 y; f32 y;
f32 z; f32 z;
}; };
f32 v[2]; f32 v[3];
}; };
Vec3F32 vec3f32_rotate_x(Vec3F32 vector, float angle); Vec3F32 vec3f32_rotate_x(Vec3F32 vector, float angle);

View File

@ -15,7 +15,8 @@ Vec2F32 g_projected_points[POINTS];
Vec3F32 camera_position = {.x = 0, .y = 0, .z = -5}; Vec3F32 camera_position = {.x = 0, .y = 0, .z = -5};
Vec3F32 cube_rotation = {.x = 0, .y = 0, .z = 0}; Vec3F32 cube_rotation = {.x = 0, .y = 0, .z = 0};
int is_running; s32 is_running;
s32 previous_frame_time = 0;
// Perspective Projection (perspective divide) // Perspective Projection (perspective divide)
// Formula // Formula
@ -69,6 +70,13 @@ void process_input(void) {
} }
void update(void) { void update(void) {
// while(!SDL_TICKS_PASSED(SDL_GetTicks(), previous_frame_time + FRAME_TARGET_TIME)); // NOTE(tijani): SLOWWWW!!!!
s32 time_to_wait = FRAME_TARGET_TIME - (SDL_GetTicks() - previous_frame_time);
if (time_to_wait > 0 && time_to_wait <= FRAME_TARGET_TIME) {
SDL_Delay(time_to_wait);
}
// previous_frame_time = SDL_GetTicks(); // NOTE(tijani): SLOWWW!!! because it locks the OS into this.
cube_rotation.x += 0.01; cube_rotation.x += 0.01;
cube_rotation.y += 0.01; cube_rotation.y += 0.01;
cube_rotation.z += 0.01; cube_rotation.z += 0.01;

View File

@ -3,6 +3,9 @@
#include <SDL.h> #include <SDL.h>
#define FPS 60
#define FRAME_TARGET_TIME (1000 / FPS)
SDL_Window *window = NULL; SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL; SDL_Renderer *renderer = NULL;
SDL_Texture *colour_buffer_texture = NULL; SDL_Texture *colour_buffer_texture = NULL;