2020-09-10 17:58:12 +02:00
|
|
|
#include "vec.h"
|
|
|
|
|
2020-09-14 10:33:01 +02:00
|
|
|
void vec_cpy(Vec *destination, Vec source)
|
2020-09-12 10:08:01 +02:00
|
|
|
{
|
2020-09-14 10:33:01 +02:00
|
|
|
destination->x = source.x;
|
|
|
|
destination->y = source.y;
|
2020-09-12 10:08:01 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 17:58:12 +02:00
|
|
|
void vec_add(Vec *vector, Vec force)
|
|
|
|
{
|
2020-09-12 09:54:53 +02:00
|
|
|
vector->x += force.x;
|
|
|
|
vector->y += force.y;
|
2020-09-10 17:58:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void vec_sub(Vec *vector, Vec force)
|
|
|
|
{
|
2020-09-12 09:54:53 +02:00
|
|
|
vector->x -= force.x;
|
|
|
|
vector->y -= force.y;
|
2020-09-10 17:58:12 +02:00
|
|
|
}
|
2020-09-12 10:08:01 +02:00
|
|
|
|
|
|
|
void vec_mul(Vec *vector, float scale)
|
|
|
|
{
|
|
|
|
vector->x *= scale;
|
|
|
|
vector->y *= scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vec_div(Vec *vector, float scale)
|
|
|
|
{
|
|
|
|
vector->x /= scale;
|
|
|
|
vector->y /= scale;
|
|
|
|
}
|
2020-09-14 10:33:01 +02:00
|
|
|
|
|
|
|
void vec_lerp(Vec *from, Vec to, float scale)
|
|
|
|
{
|
2020-09-16 11:20:48 +02:00
|
|
|
/* from * (1 - scale) + temp * scale */
|
|
|
|
Vec temp;
|
2020-09-14 10:33:01 +02:00
|
|
|
vec_cpy(&temp, to);
|
2020-09-16 11:20:48 +02:00
|
|
|
/* from * (1 - scale) */
|
|
|
|
vec_mul(from, 1 - scale);
|
|
|
|
/* temp * scale */
|
2020-09-14 10:33:01 +02:00
|
|
|
vec_mul(&temp, scale);
|
2020-09-16 11:20:48 +02:00
|
|
|
/* add */
|
2020-09-14 10:33:01 +02:00
|
|
|
vec_add(from, temp);
|
|
|
|
}
|