separation to vec.h, generic vector ops, camera class and its usage for spatial rendering
This commit is contained in:
50
src/util.h
50
src/util.h
@@ -1,6 +1,7 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include "vec.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <physfs.h>
|
||||
@@ -78,40 +79,13 @@ _Alignas(4)
|
||||
} t_color;
|
||||
|
||||
|
||||
/* a point in some space (integer) */
|
||||
typedef struct vec2 {
|
||||
int x, y;
|
||||
} t_vec2;
|
||||
|
||||
|
||||
/* a point in some space (floating point) */
|
||||
typedef struct fvec2 {
|
||||
_Alignas(8)
|
||||
float x;
|
||||
float y;
|
||||
} t_fvec2;
|
||||
|
||||
|
||||
/* a point in some three dimension space (floating point) */
|
||||
/* y goes up, x goes to the right */
|
||||
typedef struct fvec3 {
|
||||
_Alignas(8)
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} t_fvec3;
|
||||
|
||||
|
||||
/* a point in some space (short) */
|
||||
typedef struct shvec2 {
|
||||
short x, y;
|
||||
} t_shvec2;
|
||||
|
||||
|
||||
/* a rectangle with the origin at the upper left (integer) */
|
||||
typedef struct rect {
|
||||
int x, y;
|
||||
int w, h;
|
||||
_Alignas(16)
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t w;
|
||||
int32_t h;
|
||||
} t_rect;
|
||||
|
||||
|
||||
@@ -135,15 +109,9 @@ t_frect to_frect(t_rect rect);
|
||||
t_fvec2 frect_center(t_frect rect);
|
||||
|
||||
|
||||
/* aren't macros to prevent double evaluation with side effects */
|
||||
/* maybe could be inlined? i hope LTO will resolve this */
|
||||
t_fvec2 fvec2_from_vec2(t_vec2 vec);
|
||||
t_fvec2 fvec2_from_shvec2(t_shvec2 vec);
|
||||
|
||||
#define m_to_fvec2(p_any_vec2) (_Generic((p_any_vec2), \
|
||||
t_vec2: fvec2_from_vec2, \
|
||||
t_shvec2: fvec2_from_shvec2 \
|
||||
)(p_any_vec2))
|
||||
typedef struct matrix4 {
|
||||
t_fvec4 row[4];
|
||||
} t_matrix4;
|
||||
|
||||
|
||||
/* decrements an lvalue (which should be an int), stopping at 0 */
|
||||
|
Reference in New Issue
Block a user