From 66e84eabf70a11d91abbbe8777b1746573a51bae Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 30 Aug 2023 22:58:18 +0500 Subject: Refactored files: - moved memory arenas to memory files - replaced r32 and r64 with f32 and f64 - prefixing internal libs with amr_ --- code/math.h | 130 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 65 insertions(+), 65 deletions(-) (limited to 'code/math.h') diff --git a/code/math.h b/code/math.h index 7a64285..ca5e96e 100644 --- a/code/math.h +++ b/code/math.h @@ -12,8 +12,8 @@ #define PIVOT_Z 2 typedef struct Vec2 { - r32 x; - r32 y; + f32 x; + f32 y; Vec2 operator-(Vec2 S) { @@ -39,7 +39,7 @@ typedef struct Vec2 { return R; } - Vec2 operator/(r32 s) + Vec2 operator/(f32 s) { Vec2 R = {0}; R.x = x/2; @@ -57,9 +57,9 @@ typedef struct Vec2 { } Vec2; typedef struct Vec3 { - r32 x; - r32 y; - r32 z; + f32 x; + f32 y; + f32 z; Vec3 operator+(Vec3 S) { @@ -70,7 +70,7 @@ typedef struct Vec3 { return R; } - Vec3 operator+(r32 S) + Vec3 operator+(f32 S) { Vec3 R = {0}; R.x = x + S; @@ -79,7 +79,7 @@ typedef struct Vec3 { return R; } - Vec3 operator*(r32 S) + Vec3 operator*(f32 S) { Vec3 R; R.x = x * S; @@ -89,7 +89,7 @@ typedef struct Vec3 { return R; } - Vec3 operator/(r32 S) + Vec3 operator/(f32 S) { Vec3 R; R.x = x / S; @@ -101,68 +101,68 @@ typedef struct Vec3 { } Vec3; typedef struct Vec4 { - r32 x; - r32 y; - r32 z; - r32 w; + f32 x; + f32 y; + f32 z; + f32 w; } Vec4; typedef struct Mat4 { - r32 x0, x1, x2, x3; - r32 y0, y1, y2, y3; - r32 z0, z1, z2, z3; - r32 w0, w1, w2, w3; + f32 x0, x1, x2, x3; + f32 y0, y1, y2, y3; + f32 z0, z1, z2, z3; + f32 w0, w1, w2, w3; } Mat4; -Vec3 InitVec3(r32 Val); -Vec3 InitVec3(r32 x, r32 y, r32 z); -r32 LenVec3(Vec3 V); +Vec3 InitVec3(f32 Val); +Vec3 InitVec3(f32 x, f32 y, f32 z); +f32 LenVec3(Vec3 V); Vec3 UnitVec3(Vec3 V); -r32 DotProductVec3(Vec3 S, Vec3 K); +f32 DotProductVec3(Vec3 S, Vec3 K); Vec3 CrossProductVec3(Vec3 S, Vec3 K); -Vec4 InitVec4(r32 x, r32 y, r32 z, r32 w); -Vec4 ScalerAdd4(Vec4 Vec, r32 Scaler); -Vec4 ScalerMul4(Vec4 Vec, r32 Scaler); -Vec4 ScalerDiv4(Vec4 Vec, r32 Scaler); +Vec4 InitVec4(f32 x, f32 y, f32 z, f32 w); +Vec4 ScalerAdd4(Vec4 Vec, f32 Scaler); +Vec4 ScalerMul4(Vec4 Vec, f32 Scaler); +Vec4 ScalerDiv4(Vec4 Vec, f32 Scaler); Vec4 AddVec4(Vec4 V, Vec4 K); -r32 LenVec4(Vec4 V); +f32 LenVec4(Vec4 V); Vec4 UnitVec4(Vec4 V); -r32 DotProductVec4(Vec4 S, Vec4 K); +f32 DotProductVec4(Vec4 S, Vec4 K); Vec4 Mul_Mat4Vec4(Mat4 Matrix, Vec4 S); Mat4 IdentityMat(); Mat4 Mul_Mat4Mat4(Mat4 M1, Mat4 M2); Mat4 CreateTranslationMat(Vec4 S); Mat4 CreateScaleMat(Vec4 S); -Mat4 CreateRotationMat(r32 Theta, u8 Pivot); -Mat4 CreateFrustum(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam); -Mat4 CreatePerspectiveUsingFrustum(r32 fov, r32 aspect, r32 nearCam, r32 farCam); -Mat4 CreateOrthographic(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam); -Mat4 CreateOrthographicWithRatio(r32 scrWidth, r32 scrHeight, r32 nearCam, r32 farCam); +Mat4 CreateRotationMat(f32 Theta, u8 Pivot); +Mat4 CreateFrustum(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam); +Mat4 CreatePerspectiveUsingFrustum(f32 fov, f32 aspect, f32 nearCam, f32 farCam); +Mat4 CreateOrthographic(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam); +Mat4 CreateOrthographicWithRatio(f32 scrWidth, f32 scrHeight, f32 nearCam, f32 farCam); Mat4 CreateLookAtMat4(Vec3 CameraPos, Vec3 CameraTarget, Vec3 Up); -Vec3 InitVec3(r32 val) +Vec3 InitVec3(f32 val) { Vec3 R = Vec3{val,val,val}; return R; } -Vec3 InitVec3(r32 x, r32 y, r32 z) +Vec3 InitVec3(f32 x, f32 y, f32 z) { Vec3 R = Vec3{x,y,z}; return R; } -r32 LenVec3(Vec3 V) +f32 LenVec3(Vec3 V) { - r32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z)); + f32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z)); return L; } Vec3 UnitVec3(Vec3 V) { Vec3 R; - r32 L = LenVec3(V); + f32 L = LenVec3(V); R.x = V.x/L; R.y = V.y/L; R.z = V.z/L; @@ -170,14 +170,14 @@ Vec3 UnitVec3(Vec3 V) return R; } -r32 DotProductVec3(Vec3 S, Vec3 K) +f32 DotProductVec3(Vec3 S, Vec3 K) { Vec3 R; R.x = S.x*K.x; R.y = S.y*K.y; R.z = S.z*K.z; - r32 DotProd = R.x + R.y + R.z; + f32 DotProd = R.x + R.y + R.z; return DotProd; } @@ -194,7 +194,7 @@ Vec3 CrossProductVec3(Vec3 S, Vec3 K) // @note: I am creating vectors in many places so created a function to make initialising abit easier -Vec4 InitVec4(r32 x, r32 y, r32 z, r32 w) +Vec4 InitVec4(f32 x, f32 y, f32 z, f32 w) { Vec4 V = {0}; V.x = x; @@ -206,7 +206,7 @@ Vec4 InitVec4(r32 x, r32 y, r32 z, r32 w) } -Vec4 ScalerAdd4(Vec4 Vec, r32 Scaler) +Vec4 ScalerAdd4(Vec4 Vec, f32 Scaler) { Vec.x += Scaler; Vec.y += Scaler; @@ -216,7 +216,7 @@ Vec4 ScalerAdd4(Vec4 Vec, r32 Scaler) return Vec; } -Vec4 ScalerMul4(Vec4 Vec, r32 Scaler) +Vec4 ScalerMul4(Vec4 Vec, f32 Scaler) { Vec.x *= Scaler; Vec.y *= Scaler; @@ -226,7 +226,7 @@ Vec4 ScalerMul4(Vec4 Vec, r32 Scaler) return Vec; } -Vec4 ScalerDiv4(Vec4 Vec, r32 Scaler) +Vec4 ScalerDiv4(Vec4 Vec, f32 Scaler) { Vec.x = Vec.x/Scaler; Vec.y = Vec.y/Scaler; @@ -247,16 +247,16 @@ Vec4 AddVec4(Vec4 V, Vec4 K) return Res; } -r32 LenVec4(Vec4 V) +f32 LenVec4(Vec4 V) { - r32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z) +Sq(V.w)); + f32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z) +Sq(V.w)); return L; } Vec4 UnitVec4(Vec4 V) { Vec4 R = {0}; - r32 L = LenVec4(V); + f32 L = LenVec4(V); R.x = V.x/L; R.y = V.y/L; R.z = V.z/L; @@ -265,7 +265,7 @@ Vec4 UnitVec4(Vec4 V) return R; } -r32 DotProductVec4(Vec4 S, Vec4 K) +f32 DotProductVec4(Vec4 S, Vec4 K) { Vec4 R = {0}; R.x = S.x*K.x; @@ -273,7 +273,7 @@ r32 DotProductVec4(Vec4 S, Vec4 K) R.z = S.z*K.z; R.w = S.w*K.w; - r32 DotProd = R.x + R.y + R.z + R.w; + f32 DotProd = R.x + R.y + R.z + R.w; return DotProd; } @@ -352,10 +352,10 @@ Mat4 CreateScaleMat(Vec4 S) return SM; } -Mat4 CreateRotationMat(r32 Theta, u8 Pivot) +Mat4 CreateRotationMat(f32 Theta, u8 Pivot) { - r32 CosTheta = cos(Theta); - r32 SinTheta = sin(Theta); + f32 CosTheta = cos(Theta); + f32 SinTheta = sin(Theta); Mat4 RotMat = {0}; if (Pivot == PIVOT_X) @@ -383,7 +383,7 @@ Mat4 CreateRotationMat(r32 Theta, u8 Pivot) return RotMat; } -Mat4 CreateFrustum(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam) +Mat4 CreateFrustum(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam) { Mat4 F = {0}; F.x0 = 2.0f*nearCam/(right - left); @@ -398,17 +398,17 @@ Mat4 CreateFrustum(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCa return F; } -Mat4 CreatePerspectiveUsingFrustum(r32 fov, r32 aspect, r32 nearCam, r32 farCam) +Mat4 CreatePerspectiveUsingFrustum(f32 fov, f32 aspect, f32 nearCam, f32 farCam) { - r32 top = nearCam*tan(fov)/2; - r32 bot = -top; - r32 right = top*aspect; - r32 left = -right; + f32 top = nearCam*tan(fov)/2; + f32 bot = -top; + f32 right = top*aspect; + f32 left = -right; return CreateFrustum(left, right, bot, top, nearCam, farCam); } -Mat4 CreateOrthographic(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam) +Mat4 CreateOrthographic(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam) { Mat4 F = {0}; F.x0 = 2.0f/(right - left); @@ -425,15 +425,15 @@ Mat4 CreateOrthographic(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 return F; } -Mat4 CreateOrthographicWithRatio(r32 scrWidth, r32 scrHeight, r32 nearCam, r32 farCam) +Mat4 CreateOrthographicWithRatio(f32 scrWidth, f32 scrHeight, f32 nearCam, f32 farCam) { - r32 ratio_h = scrWidth/scrHeight; - r32 left = -ratio_h; - r32 right = ratio_h; + f32 ratio_h = scrWidth/scrHeight; + f32 left = -ratio_h; + f32 right = ratio_h; - r32 ratio_v = scrHeight/scrWidth; - r32 top = ratio_v; - r32 bot = -ratio_v; + f32 ratio_v = scrHeight/scrWidth; + f32 top = ratio_v; + f32 bot = -ratio_v; return CreateOrthographic(left, right, bot, top, nearCam, farCam); } -- cgit v1.2.3