This commit is contained in:
Doyle Thai 2017-04-09 16:35:54 +10:00
parent 33bba1aa52
commit 2600485dea
2 changed files with 52 additions and 0 deletions

24
dqnt.h
View File

@ -49,6 +49,11 @@ typedef float f32;
#define DQNT_SQUARED(x) ((x) * (x)) #define DQNT_SQUARED(x) ((x) * (x))
#define DQNT_SQRT(x) (sqrtf(x)) #define DQNT_SQRT(x) (sqrtf(x))
////////////////////////////////////////////////////////////////////////////////
// Math
////////////////////////////////////////////////////////////////////////////////
DQNT_FILE_SCOPE f32 dqnt_lerp(f32 a, f32 t, f32 b);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Vec2 // Vec2
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -214,7 +219,26 @@ DQNT_FILE_SCOPE i32 dqnt_rnd_pcg_range(DqntRandPCGState *pcg, i32 min, i32 max)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
////////////////////////////////////////////////////////////////////////////////
// Math
////////////////////////////////////////////////////////////////////////////////
DQNT_FILE_SCOPE f32 dqnt_lerp(f32 a, f32 t, f32 b)
{
/*
Linear blend between two values. We having a starting point "a", and
the distance to "b" is defined as (b - a). Then we can say
a + t(b - a)
As our linear blend fn. We start from "a" and choosing a t from 0->1
will vary the value of (b - a) towards b. If we expand this, this
becomes
a + (t * b) - (a * t) == (1 - t)a + t*b
*/
f32 result = a + (b - a) * t;
return result;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Vec2 // Vec2

View File

@ -293,6 +293,29 @@ void dqnt_random_test() {
printf("dqnt_random_test(): Completed successfully\n"); printf("dqnt_random_test(): Completed successfully\n");
} }
void dqnt_math_test()
{
{ // Lerp
{
f32 start = 10;
f32 t = 0.5f;
f32 end = 20;
DQNT_ASSERT(dqnt_lerp(start, t, end) == 15);
}
{
f32 start = 10;
f32 t = 2.0f;
f32 end = 20;
DQNT_ASSERT(dqnt_lerp(start, t, end) == 30);
}
printf("dqnt_math_test(): lerp: Completed successfully\n");
}
printf("dqnt_math_test(): Completed successfully\n");
}
void dqnt_vec_test() void dqnt_vec_test()
{ {
{ // V2 { // V2
@ -438,7 +461,12 @@ int main(void)
{ {
dqnt_strings_test(); dqnt_strings_test();
dqnt_random_test(); dqnt_random_test();
dqnt_math_test();
dqnt_vec_test(); dqnt_vec_test();
dqnt_other_test(); dqnt_other_test();
printf("\nPress Any Key to Exit\n");
getchar();
return 0; return 0;
} }