nuclear@15: #ifndef VMATH_H_ nuclear@15: #define VMATH_H_ nuclear@15: nuclear@21: #include nuclear@26: #include "fixedp.h" nuclear@21: nuclear@21: #ifndef M_PI nuclear@21: #define M_PI 3.1415926536 nuclear@21: #endif nuclear@21: nuclear@15: typedef struct { nuclear@15: float x, y, z, w; nuclear@15: } vec4_t; nuclear@15: nuclear@15: typedef struct { nuclear@15: float x, y, z; nuclear@15: } vec3_t; nuclear@15: nuclear@15: typedef struct { nuclear@15: float x, y; nuclear@15: } vec2_t; nuclear@15: nuclear@25: typedef struct { nuclear@25: fixed x, y, z, w; nuclear@25: } vec4x_t; nuclear@25: nuclear@25: typedef struct { nuclear@25: fixed x, y, z; nuclear@25: } vec3x_t; nuclear@25: nuclear@25: typedef struct { nuclear@25: fixed x, y; nuclear@25: } vec2x_t; nuclear@25: nuclear@28: typedef struct { nuclear@28: vec3_t origin, dir; nuclear@28: } ray3_t; nuclear@28: nuclear@28: #define vec3_dot(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z) nuclear@28: nuclear@28: #define vec2_lerp(res, a, b, t) \ nuclear@28: do { \ nuclear@28: (res).x = (a).x + ((b).x - (a).x) * (t); \ nuclear@28: (res).y = (a).y + ((b).y - (a).y) * (t); \ nuclear@28: } while(0) nuclear@28: nuclear@28: #define vec3_lerp(res, a, b, t) \ nuclear@28: do { \ nuclear@28: (res).x = (a).x + ((b).x - (a).x) * (t); \ nuclear@28: (res).y = (a).y + ((b).y - (a).y) * (t); \ nuclear@28: (res).z = (a).z + ((b).z - (a).z) * (t); \ nuclear@28: } while(0) nuclear@28: nuclear@28: #define ray3_point(res, ray, t) \ nuclear@28: do { \ nuclear@28: (res).x = (ray).origin.x + (ray).dir.x * (t); \ nuclear@28: (res).y = (ray).origin.y + (ray).dir.y * (t); \ nuclear@28: (res).z = (ray).origin.z + (ray).dir.z * (t); \ nuclear@28: } while(0) nuclear@25: nuclear@25: #define vec2_to_fixed2(v, f) \ nuclear@25: do { \ nuclear@28: (f).x = fixedf((v).x); \ nuclear@28: (f).y = fixedf((v).y); \ nuclear@25: } while(0) nuclear@25: nuclear@25: #define vec3_to_fixed3(v, f) \ nuclear@25: do { \ nuclear@28: (f).x = fixedf((v).x); \ nuclear@28: (f).y = fixedf((v).y); \ nuclear@28: (f).z = fixedf((v).z); \ nuclear@25: } while(0) nuclear@25: nuclear@25: #define vec4_to_fixed4(v, f) \ nuclear@25: do { \ nuclear@28: (f).x = fixedf((v).x); \ nuclear@28: (f).y = fixedf((v).y); \ nuclear@28: (f).z = fixedf((v).z); \ nuclear@28: (f).w = fixedf((v).w); \ nuclear@25: } while(0) nuclear@25: nuclear@25: nuclear@25: #define fixed2_to_vec2(f, v) \ nuclear@25: do { \ nuclear@28: (v).x = fixed_float((f).x); \ nuclear@28: (v).y = fixed_float((f).y); \ nuclear@25: } while(0) nuclear@25: nuclear@25: #define fixed3_to_vec3(f, v) \ nuclear@25: do { \ nuclear@28: (v).x = fixed_float((f).x); \ nuclear@28: (v).y = fixed_float((f).y); \ nuclear@28: (v).z = fixed_float((f).z); \ nuclear@25: } while(0) nuclear@25: nuclear@25: #define fixed4_to_vec4(f, v) \ nuclear@25: do { \ nuclear@28: (v).x = fixed_float((f).x); \ nuclear@28: (v).y = fixed_float((f).y); \ nuclear@28: (v).z = fixed_float((f).z); \ nuclear@28: (v).w = fixed_float((f).w); \ nuclear@25: } while(0) nuclear@25: nuclear@15: nuclear@15: #endif /* VMATH_H_ */