bootleg-game-engine/include/vector.h

58 lines
1.1 KiB
C
Raw Permalink Normal View History

2024-09-13 11:12:31 +00:00
// prevent multiple inclusion
2024-09-06 09:34:29 +00:00
#pragma once
2024-09-13 11:12:31 +00:00
// class for 2D float vector
2024-09-06 09:34:29 +00:00
class float_vec2
{
2024-09-13 11:12:31 +00:00
// public members
2024-09-06 09:34:29 +00:00
public:
2024-09-13 11:12:31 +00:00
// x and y coordinates
2024-09-06 09:34:29 +00:00
float x, y;
2024-09-13 11:12:31 +00:00
// operator functions
2024-09-06 09:34:29 +00:00
float_vec2 operator+(float_vec2 vec)
{
return { x + vec.x, y + vec.y };
}
float_vec2 operator*(float v)
{
return { x * v, y * v };
}
float_vec2 operator*(float_vec2 vec)
{
return { x * vec.x, y * vec.y };
}
float_vec2 operator-(float_vec2 vec)
{
return { x - vec.x, y - vec.y };
}
float_vec2 operator-(float v)
{
return { x - v, y - v };
}
};
2024-09-13 11:12:31 +00:00
// class for 2D integer vector
2024-09-06 09:34:29 +00:00
class int_vec2
{
2024-09-13 11:12:31 +00:00
// public members
2024-09-06 09:34:29 +00:00
public:
2024-09-13 11:12:31 +00:00
// x and y coordinates
2024-09-06 09:34:29 +00:00
int x, y;
2024-09-13 11:12:31 +00:00
// operator functions
2024-09-06 09:34:29 +00:00
int_vec2 operator+(int_vec2 vec)
{
return { x + vec.x, y + vec.y };
}
int_vec2 operator*(int v)
{
return { x * v, y * v };
}
int_vec2 operator*(int_vec2 vec)
{
return { x * vec.x, y * vec.y };
}
int_vec2 operator-(int_vec2 vec)
{
return { x - vec.x, y - vec.y };
}
};