#ifndef COMMON_H #define COMMON_H #include "cglm/struct/quat.h" #include "cglm/struct/vec4.h" #include "cglm/struct/vec3.h" #include #define RAY_EPSILON 5.192092896e-05F #define COLOR_CLAMP(color) (unsigned char)fminf(fmaxf(color, 0.0f), 255.0f) #define BIAS_RAY_ORIGION(positon, normal) glms_vec3_add(positon, glms_vec3_scale(normal, RAY_EPSILON)) inline float random_float() { return (float)rand() / (float)RAND_MAX; } inline uint32_t hash_uint32(uint32_t x) { x = ((x >> 16) ^ x) * 0x45d9f3b; x = ((x >> 16) ^ x) * 0x45d9f3b; x = (x >> 16) ^ x; return x; } inline bool has_flag(int flags, int flag) { return (flags & flag) != 0; } inline versors euler_to_quat(float x, float y, float z) { versors qx = glms_quatv(glm_rad(x), (vec3s){1.0f, 0.0f, 0.0f}); versors qy = glms_quatv(glm_rad(y), (vec3s){0.0f, 1.0f, 0.0f}); versors qz = glms_quatv(glm_rad(z), (vec3s){0.0f, 0.0f, 1.0f}); return glms_quat_mul(glms_quat_mul(qz, qy), qx); } inline vec3s quat_get_forward(versors quat) { vec3s forward = glms_quat_rotatev(quat, (vec3s){0.0f, 0.0f, -1.0f}); return forward; } inline vec3s quat_get_up(versors quat) { return glms_quat_rotatev(quat, (vec3s){0.0f, 1.0f, 0.0f}); } inline vec3s quat_get_right(versors quat) { return glms_quat_rotatev(quat, (vec3s){1.0f, 0.0f, 0.0f}); } #endif // COMMON_H