59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <float.h>
|
|
#include <math.h>
|
|
|
|
|
|
|
|
typedef struct vec2 { float x, y; } vec2;
|
|
typedef struct vec2i { int x, y; } vec2i;
|
|
|
|
static const vec2 vec2_zero = { 0, 0 };
|
|
static const vec2 vec2_one = { 1, 1 };
|
|
static const vec2 vec2_unitx = { 1, 0 };
|
|
static const vec2 vec2_unity = { 0, 1 };
|
|
static const vec2 vec2_max = { FLT_MAX, FLT_MAX };
|
|
static const vec2 vec2_min = { -FLT_MAX, -FLT_MAX };
|
|
static const vec2i vec2i_zero = { 0, 0 };
|
|
static const vec2i vec2i_one = { 1, 1 };
|
|
|
|
// vec2 operators
|
|
vec2 operator+(vec2 const &v);
|
|
vec2 operator-(vec2 const &v);
|
|
vec2 operator+(vec2 const &a, vec2 const &b);
|
|
vec2 operator-(vec2 const &a, vec2 const &b);
|
|
vec2 operator*(vec2 const &a, float const &b);
|
|
vec2 operator/(vec2 const &a, float const &b);
|
|
bool operator<(vec2 const &a, vec2 const &b);
|
|
bool operator>(vec2 const &a, vec2 const &b);
|
|
bool operator==(vec2 const &a, vec2 const &b);
|
|
|
|
// vec2i operators
|
|
bool operator<(vec2i const &a, vec2i const &b);
|
|
bool operator>(vec2i const &a, vec2i const &b);
|
|
|
|
// vec2 functions
|
|
float dot(vec2 const &a, vec2 const &b);
|
|
float norm2(vec2 const &v);
|
|
float norm(vec2 const &v);
|
|
vec2 normalize(vec2 const &v);
|
|
vec2 min2(vec2 const &a, vec2 const &b);
|
|
vec2 max2(vec2 const &a, vec2 const &b);
|
|
vec2 polar_to_vec2(float const angle, float const len);
|
|
float vec2_angle(vec2 const v);
|
|
|
|
// vec2i functions
|
|
vec2 v2i_to_v2(vec2i const v);
|
|
|
|
// Angle functions
|
|
float normalize_angle(float const angle);
|
|
float normalize_angle_diff(float const diff);
|
|
float angle_to_heading(float const angle);
|
|
|
|
// Random generation functions
|
|
int rand_int(int const min, int const max);
|
|
float rand_float(float const min, float const max);
|
|
float rand_angle();
|
|
vec2i rand_v2i(vec2i const min, vec2i const max);
|
|
vec2 rand_v2(vec2 const min, vec2 const max);
|