82 lines
1.1 KiB
C
82 lines
1.1 KiB
C
#ifndef HANDMADE_MATH_H
|
|
#define HANDMADE_MATH_H
|
|
|
|
/* TODO: Make these static. */
|
|
struct v2 {
|
|
float x, y;
|
|
float e[2];
|
|
};
|
|
|
|
struct v2 V2(float x, float y)
|
|
{
|
|
struct v2 result;
|
|
|
|
result.x = x;
|
|
result.y = y;
|
|
|
|
return result;
|
|
}
|
|
|
|
struct v2 V2Multiply(float a, struct v2 b)
|
|
{
|
|
struct v2 result;
|
|
|
|
result.x = a * b.x;
|
|
result.y = a * b.y;
|
|
|
|
return result;
|
|
}
|
|
|
|
struct v2 V2Unary(struct v2 a)
|
|
{
|
|
struct v2 result;
|
|
|
|
result.x = -a.x;
|
|
result.y = -a.y;
|
|
|
|
return result;
|
|
}
|
|
|
|
struct v2 V2Add(struct v2 a, struct v2 b)
|
|
{
|
|
struct v2 result;
|
|
|
|
result.x = a.x + b.x;
|
|
result.y = a.y + b.y;
|
|
|
|
return result;
|
|
}
|
|
|
|
struct v2 V2Subtract(struct v2 a, struct v2 b)
|
|
{
|
|
struct v2 result;
|
|
|
|
result.x = a.x - b.x;
|
|
result.y = a.y - b.y;
|
|
|
|
return result;
|
|
}
|
|
|
|
float Square(float a)
|
|
{
|
|
float result;
|
|
|
|
result = a * a;
|
|
|
|
return result;
|
|
}
|
|
|
|
float InnerProduct(struct v2 a, struct v2 b)
|
|
{
|
|
float result = a.x*b.x + a.y*b.y;
|
|
return result;
|
|
}
|
|
|
|
float LengthSq(struct v2 a)
|
|
{
|
|
float result = InnerProduct(a, a);
|
|
return result;
|
|
}
|
|
|
|
#endif
|