forked from kdx/jtmm2-old
64 lines
1.0 KiB
C
64 lines
1.0 KiB
C
#include <gint/display.h>
|
|
|
|
#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, int scale)
|
|
{
|
|
vector->x *= scale;
|
|
vector->y *= scale;
|
|
}
|
|
|
|
void vec_mulf(Vec *vector, float scale)
|
|
{
|
|
vector->x *= scale;
|
|
vector->y *= scale;
|
|
}
|
|
|
|
void vec_div(Vec *vector, int scale)
|
|
{
|
|
vector->x /= scale;
|
|
vector->y /= scale;
|
|
}
|
|
|
|
void vec_divf(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_mulf(from, 1 - scale);
|
|
/* temp * scale */
|
|
vec_mulf(&temp, scale);
|
|
/* add */
|
|
vec_add(from, temp);
|
|
}
|
|
|
|
void vec_drect(Vec top_left, Vec bottom_right, int color)
|
|
{
|
|
drect(top_left.x, top_left.y, bottom_right.x, bottom_right.y, color);
|
|
}
|