#ifndef BR_DEFS_H
#define BR_DEFS_H
// Inspired by BRender SDK includes (https://rr2000.cwaboard.co.uk/R4/BRENDER/BRENDER.zip)
#include <math.h> // sqrtf
#define PI 3.14159265358979323846
#define TAU 6.283185307179586
#define BR_MAC3(a, b, c, d, e, f) ((a) * (b) + (c) * (d) + (e) * (f))
#define BR_SQR3(a, b, c) ((a) * (a) + (b) * (b) + (c) * (c))
#define BrAngleToRadian(a) ((br_scalar)((a) * (PI / 32768.0))) // a * 0.00009587379924285257
#define BrRadianToAngle(r) ((br_angle)(long)((r) * (32768.0 / PI))) // r * 10430.378350470453
#define BR_VECTOR3(a, b, c) \
{ a, b, c }
#define BR_VECTOR4(a, b, c, d) \
{ a, b, c, d }
#define BR_COLOUR_RGB(r, g, b) \
((((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b)))
#define BR_ALPHA(c) (((c) >> 24) & 0xFF)
#define BR_ANGLE_DEG(deg) ((br_angle)((deg)*182))
#define BR_ANGLE_RAD(rad) ((br_angle)((rad)*10430))
#define BrDegreeToRadian(d) ((br_scalar)((d) * (PI / 180.0)))
#define BrRadianToDegree(r) ((br_scalar)((r) * (180.0 / PI)))
#define BrDegreeToAngle(d) ((br_angle)(long)((d) * (65536.0f / 360.0f))) // "d * 182.044444444"
#define BrAngleToDegrees(a) ((br_angle)(long)((a) * (360.0f / 65536.0f))) // "d * 0.0054931640625"
#define BR_SCALAR(x) ((br_scalar)(x))
#define BR_COLOUR_RGBA(r, g, b, a) \
((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b)))
#define BR_LENGTH2(a, b) ((br_scalar)sqrtf((a) * (a) + (b) * (b)))
#define BR_LENGTH3(a, b, c) ((br_scalar)sqrtf((a) * (a) + (b) * (b) + (c) * (c)))
#define BR_SCALAR_EPSILON 1.192092896e-7f
#define BR_SCALAR_MAX 3.402823466e+38f
#define BR_SCALAR_MIN (-3.402823466e+38f)
#define BR_SIMPLEHEAD(l) (void*)(((br_simple_list*)(l))->head)
#define BR_SIMPLENEXT(n) (void*)(((br_simple_node*)(n))->next)
#define BR_FOR_SIMPLELIST(list, ptr) for ((ptr) = BR_SIMPLEHEAD(list); (ptr); (ptr) = BR_SIMPLENEXT(ptr))
#define BR_SIMPLEREMOVE(n) ((void*)BrSimpleRemove((br_simple_node*)(n)))
#define V_X 0
#define V_Y 1
#define V_Z 2
#define V_W 3
#define BR_FONTF_PROPORTIONAL 1
#define BR_SIN(a) ((br_scalar)sinf(BrAngleToRadian(a)))
#define BR_COS(a) ((br_scalar)cosf(BrAngleToRadian(a)))
#define BR_TAN(a) ((br_scalar)tanf(BrAngleToRadian(a)))
#define BR_ASIN(a) BrRadianToAngle(asin(a))
#define BR_ACOS(a) BrRadianToAngle(acos(a))
#define BR_ATAN2(a, b) BrRadianToAngle(atan2((a), (b)))
#define BR_ATAN2FAST(a, b) BrRadianToAngle(atan2((a), (b)))
#define BR_ASIZE(a) (sizeof(a) / sizeof((a)[0]))
#if BR_ENDIAN_BIG
#define BrHtoNL(x) (x)
#define BrHtoNS(x) (x)
#define BrHtoNF(x) (x)
#else
#define BrHtoNL(x) BrSwap32(x)
#define BrHtoNS(x) BrSwap16(x)
#define BrHtoNF(x) BrSwapFloat(x)
#endif
#endif /* BR_DEFS_H */