math_graphics.h angepasst;

lerp angepasst;

git-svn-id: svn://ammerhai.com/home/mike/pokemon_repo@21 24008968-59e6-ed4c-a10b-0b2c954b24ab
This commit is contained in:
mikeb 2021-07-27 16:28:15 +00:00
parent efc6477180
commit c7a9c2f78f
4 changed files with 34 additions and 28 deletions

Binary file not shown.

Binary file not shown.

View File

@ -257,24 +257,6 @@ void change_map_size(char direction, int amount) {
free(old_map);
}
float ilerp(float a, float b, float v) {
return (v - a) / (b - a);
}
V2 ilerp(V2 a, V2 b, V2 v) {
return (v - a) / (b - a);
}
float remap(float in_a, float in_b, float out_a, float out_b, float v) {
float t = ilerp(in_a, in_b, v);
return lerp(out_a, t, out_b);
}
V2 remap(V2 in_a, V2 in_b, V2 out_a, V2 out_b, V2 v) {
V2 t = ilerp(in_a, in_b, v);
return lerp(out_a, t, out_b);
}
//Userinputs, Steuerung, FensterÄnderungen -> WindowProc
LRESULT WindowMsgs(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam) {
LRESULT Result = 0;

View File

@ -70,10 +70,19 @@ constexpr inline T min(T a, T b) {
return a < b ? a : b;
}
constexpr float lerp(float a, float t, float b) {
constexpr float lerp(float a, float b, float t) {
return (1.0f - t) * a + t * b;
}
float ilerp(float a, float b, float v) {
return (v - a) / (b - a);
}
float remap(float in_a, float in_b, float out_a, float out_b, float v) {
float t = ilerp(in_a, in_b, v);
return lerp(out_a, out_b, t);
}
//-----------------------------------------------
//Vektorberechnung 2-dim
@ -103,7 +112,6 @@ union V2 {
}
};
//Negation von 2-dim Vektor
inline V2 operator -(V2 a) {
return {
@ -154,12 +162,13 @@ inline V2 operator *(V2 a, float b) {
};
}
//Skalarmultiplikation -> mit V2 Pointer
inline V2 &operator *= (V2 &a, float b) {
a = a * b;
return a;
}
//Division mit nem Skalar Oo -> Skalar geteilt durch Vektor
//Division mit einem Skalar Oo -> Skalar geteilt durch Vektor
inline V2 operator /(float a, V2 b) {
return {
a / b.x,
@ -167,7 +176,7 @@ inline V2 operator /(float a, V2 b) {
};
}
//Division mit nem Skalar Oo -> Vektor geteilt durch Skalar
//Division mit einem Skalar Oo -> Vektor geteilt durch Skalar
inline V2 operator /(V2 a, float b) {
return {
a.x / b,
@ -175,6 +184,7 @@ inline V2 operator /(V2 a, float b) {
};
}
//Division mit einem Skalar -> 2 Vektoren
inline V2 operator /(V2 a, V2 b) {
return {
a.x / b.x,
@ -182,12 +192,12 @@ inline V2 operator /(V2 a, V2 b) {
};
}
inline V2& operator /= (V2& a, float b) {
//Division mit einem Skalar -> mit V2 Pointer
inline V2 &operator /= (V2 &a, float b) {
a = a / b;
return a;
}
//Skalarprodukt
inline float dot(V2 a, V2 b) {
return a.x * b.x + a.y * b.y;
@ -237,6 +247,7 @@ inline V2 clamp01(V2 a) {
};
}
//Vektor mit den kleinsten Werten 2er Vektoren
inline V2 min(V2 a, V2 b) {
return {
min(a.x, b.x),
@ -244,6 +255,7 @@ inline V2 min(V2 a, V2 b) {
};
}
//Vektor mit den groessten Werten 2er Vektoren
inline V2 max(V2 a, V2 b) {
return {
max(a.x, b.x),
@ -251,21 +263,34 @@ inline V2 max(V2 a, V2 b) {
};
}
//kleinster Vektor Wert
inline float min(V2 a) {
return min(a.x, a.y);
}
//groesster Vektor Wert
inline float max(V2 a) {
return max(a.x, a.y);
}
inline V2 lerp(V2 a, V2 t, V2 b) {
//Lerp mit 2 Vektoren
inline V2 lerp(V2 a, V2 b, V2 t) {
return V2{
lerp(a.x, t.x, b.x),
lerp(a.y, t.y, b.y),
lerp(a.x, b.x, t.x),
lerp(a.y, b.y, t.y),
};
}
//
V2 ilerp(V2 a, V2 b, V2 v) {
return (v - a) / (b - a);
}
//
V2 remap(V2 in_a, V2 in_b, V2 out_a, V2 out_b, V2 v) {
V2 t = ilerp(in_a, in_b, v);
return lerp(out_a, out_b, t);
}
//-----------------------------------------------
//Vektorberechnung 3-dim
@ -321,7 +346,6 @@ inline V3 operator -(V3 a) {
};
}
//Addition 2er 2-dim Vektoren
inline V3 operator +(V3 a, V3 b) {
return {