mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
fix: float4 did not have the functions named float4 + renamve to and create function
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// stores a 2D point using a floating-point number
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} float2;
|
||||
|
||||
// adds two float2s together
|
||||
// adds one float2 to another
|
||||
static inline float2 float2_add(float2 v1, float2 v2) {
|
||||
return (float2){v1.x + v2.x, v1.y + v2.y};
|
||||
}
|
||||
@@ -17,8 +18,13 @@ static inline float2 float2_sub(float2 v1, float2 v2) {
|
||||
return (float2){v1.x - v2.x, v1.y - v2.y};
|
||||
}
|
||||
|
||||
// multiplies the float2 by some value
|
||||
static inline float2 float2_mlt(float2 v, float n) {
|
||||
// multiplies one float2 by another
|
||||
static inline float2 float2_mlt(float2 v1, float2 v2) {
|
||||
return (float2){v1.x * v2.x, v1.y * v2.y};
|
||||
}
|
||||
|
||||
// scales the float2 by some value
|
||||
static inline float2 float2_scale(float2 v, float n) {
|
||||
return (float2){v.x * n, v.y * n};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// stores a 3D point using a floating-point number
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} float3;
|
||||
|
||||
// adds two float3s together
|
||||
// adds one float3 to another
|
||||
static inline float3 float3_add(float3 v1, float3 v2) {
|
||||
return (float3){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
|
||||
}
|
||||
@@ -18,8 +19,13 @@ static inline float3 float3_sub(float3 v1, float3 v2) {
|
||||
return (float3){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z};
|
||||
}
|
||||
|
||||
// multiplies the float3 by some value
|
||||
static inline float3 float3_mlt(float3 v, float n) {
|
||||
// multiplies one float3 by another
|
||||
static inline float3 float3_mlt(float3 v1, float3 v2) {
|
||||
return (float3){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z};
|
||||
}
|
||||
|
||||
// scales the float3 by some value
|
||||
static inline float3 float3_scale(float3 v, float n) {
|
||||
return (float3){v.x * n, v.y * n, v.z * n};
|
||||
}
|
||||
|
||||
@@ -46,5 +52,5 @@ static inline float3 float3_norm(float3 v) {
|
||||
|
||||
// gets the dot product of two float3s
|
||||
static inline float float3_dot(float3 v1, float3 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y +v1.z * v2.z;
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// stores a 3D point using a floating-point number
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
@@ -9,43 +10,48 @@ typedef struct {
|
||||
float w;
|
||||
} float4;
|
||||
|
||||
// adds two float3s together
|
||||
static inline float4 float3_add(float4 v1, float4 v2) {
|
||||
// adds one float4 to another
|
||||
static inline float4 float4_add(float4 v1, float4 v2) {
|
||||
return (float4){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w};
|
||||
}
|
||||
|
||||
// subtracts one float3 from another
|
||||
static inline float4 float3_sub(float4 v1, float4 v2) {
|
||||
// subtracts one float4 from another
|
||||
static inline float4 float4_sub(float4 v1, float4 v2) {
|
||||
return (float4){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w};
|
||||
}
|
||||
|
||||
// multiplies the float3 by some value
|
||||
static inline float4 float3_mlt(float4 v, float n) {
|
||||
// multiplies one float4 by another
|
||||
static inline float4 float4_mlt(float4 v1, float4 v2) {
|
||||
return (float4){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w};
|
||||
}
|
||||
|
||||
// scales the float4 by some value
|
||||
static inline float4 float4_scale(float4 v, float n) {
|
||||
return (float4){v.x * n, v.y * n, v.z * n, v.w * n};
|
||||
}
|
||||
|
||||
// divides the float3 by some value
|
||||
static inline float4 float3_div(float4 v, float n) {
|
||||
// divides the float4 by some value
|
||||
static inline float4 float4_div(float4 v, float n) {
|
||||
return (float4){v.x / n, v.y / n, v.z / n, v.w / n};
|
||||
}
|
||||
|
||||
// gets the squared length of float3
|
||||
static inline float float3_len2(float4 v) {
|
||||
// gets the squared length of float4
|
||||
static inline float float4_len2(float4 v) {
|
||||
return (v.x * v.x) + (v.y * v.y) + (v.z * v.z);
|
||||
}
|
||||
|
||||
// gets the length of float3 (magnitude)
|
||||
static inline float float3_len(float4 v) {
|
||||
return sqrtf(float3_len2(v));
|
||||
// gets the length of float4 (magnitude)
|
||||
static inline float float4_len(float4 v) {
|
||||
return sqrtf(float4_len2(v));
|
||||
}
|
||||
|
||||
// normalizes the float3
|
||||
// normalizes the float4
|
||||
static inline float4 float3_norm(float4 v) {
|
||||
float len = float3_len(v);
|
||||
return float3_div(v, len);
|
||||
float len = float4_len(v);
|
||||
return float4_div(v, len);
|
||||
}
|
||||
|
||||
// gets the dot product of two float3s
|
||||
static inline float float3_dot(float4 v1, float4 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y +v1.z * v2.z + v1.w * v2.w;
|
||||
// gets the dot product of two float4s
|
||||
static inline float float4_dot(float4 v1, float4 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user