forked from kdx/jtmm2-old
45 lines
723 B
C
45 lines
723 B
C
#include "vec.h"
|
|
|
|
void vec_cpy(Vec *destination, Vec source)
|
|
{
|
|
destination->x = source.x;
|
|
destination->y = source.y;
|
|
}
|
|
|
|
void vec_add(Vec *vector, Vec force)
|
|
{
|
|
vector->x += force.x;
|
|
vector->y += force.y;
|
|
}
|
|
|
|
void vec_sub(Vec *vector, Vec force)
|
|
{
|
|
vector->x -= force.x;
|
|
vector->y -= force.y;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void vec_lerp(Vec *from, Vec to, float scale)
|
|
{
|
|
/* from * (1 - scale) + temp * scale */
|
|
Vec temp;
|
|
vec_cpy(&temp, to);
|
|
/* from * (1 - scale) */
|
|
vec_mul(from, 1 - scale);
|
|
/* temp * scale */
|
|
vec_mul(&temp, scale);
|
|
/* add */
|
|
vec_add(from, temp);
|
|
}
|