aboutsummaryrefslogtreecommitdiff
#include "vector2f.h"
#include <SDL2/SDL.h>

vec2_t vec2_create(GLfloat x, GLfloat y)
{
    vec2_t a = {x, y};
    return a;
}

vec2_t vec2_add(const vec2_t* a, const vec2_t* b)
{
    vec2_t c;
    c.x = a->x + b->x;
    c.y = a->y + b->y;
    return c;
}

vec2_t vec2_sub(const vec2_t* a, const vec2_t* b)
{
    vec2_t c;
    c.x = a->x - b->x;
    c.y = a->y - b->y;
    return c;
}

vec2_t vec2_scalar_mul(const vec2_t* a, GLfloat scalar)
{
    vec2_t c;
    c.x = a->x * scalar;
    c.y = a->y * scalar;
    return c;
}

GLfloat vec2_dot_mul(const vec2_t* a, const vec2_t* b)
{
    return ( (a->x * b->x) + (a->y * b->y) );
}


vec2_t vec2_cross_mul(const vec2_t* a, const vec2_t* b)
{
    vec2_t c;
    c.x = (a->x * b->y) - (a->y * b->x);
    c.y = (a->y * b->x) - (a->x * b->y);
    return c;
}

GLfloat vec2_length(vec2_t* a)
{
    return SDL_sqrtf(SDL_pow(a->x, 2.0f) + SDL_pow(a->y, 2.0f) );
}

vec2_t vec2_normalize(vec2_t* a)
{
    vec2_t b;
    GLfloat length = vec2_length(a);
    b.x = a->x / length;
    b.y = a->y / length;
    return b;
}