Improved vectors in math.h and adjusted todo acordingly, also fixed a bug in the CMakeList
This commit is contained in:
@@ -40,6 +40,12 @@ file(GLOB_RECURSE SourceFiles
|
||||
)
|
||||
|
||||
add_executable(${BuildDIR}/${EXEName} ${SourceFiles})
|
||||
|
||||
set_target_properties(${BuildDIR}/${EXEName} PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_EXTENSIONS OFF
|
||||
)
|
||||
|
||||
target_link_libraries(${BuildDIR}/${EXEName}
|
||||
SDL2
|
||||
SDL2_image
|
||||
|
||||
6
TODO.txt
6
TODO.txt
@@ -10,6 +10,12 @@ x -> complete
|
||||
**TODO**
|
||||
[-] Comment the code
|
||||
[?] Overload operators in the logger and support for streams
|
||||
[?] Vector classes (2d, 3d, 4d)
|
||||
[x] Operators for each
|
||||
[x] Scalar addition, subtraction, addition and division
|
||||
[x] Dot product
|
||||
[x] Cross product (3d)
|
||||
[ ] Other functions for max, min, magnitude, unitvec all that
|
||||
[ ] Entity system
|
||||
[ ] Entity manager
|
||||
[ ] Ability to make entities and manage textures between them
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include "../math.h"
|
||||
|
||||
#include "../resourcemanager/resourcemanager.h"
|
||||
|
||||
@@ -15,5 +15,5 @@ public:
|
||||
private:
|
||||
std::string textureRef;
|
||||
std::string textureSource;
|
||||
Vec2 textureDimensions;
|
||||
Vec2<int> textureDimensions;
|
||||
};
|
||||
|
||||
@@ -11,32 +11,210 @@ inline float ToDegree(const float Radian) {
|
||||
return (Radian * RAD2DEG);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct Vec4 {
|
||||
int x, y, z, w;
|
||||
Vec4(int x, int y, int z, int w) : x(x), y(y), z(z), w(w) {}
|
||||
};
|
||||
|
||||
struct Vec4f {
|
||||
float x, y, z, w;
|
||||
Vec4f(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
|
||||
T x, y, z, w;
|
||||
template<class P>
|
||||
Vec4(P x, P y, P z, P w) : x(x), y(y), z(z), w(w) {}
|
||||
template<class P>
|
||||
Vec4(P all) : x(all), y(all), z(all), w(all) {}
|
||||
Vec4() : x(0), y(0), z(0), w(0) {}
|
||||
inline Vec4& dot(const Vec3<T>& v) {
|
||||
return (x * v.x + y * v.y + z * v.z + w * v.w);
|
||||
}
|
||||
inline const Vec4& operator+() {
|
||||
return *this;
|
||||
}
|
||||
inline Vec4& operator-() {
|
||||
return Vec4<T>(-x, -y, -z, -w);
|
||||
}
|
||||
inline Vec4& operator+(const Vec4<T>& v) {
|
||||
return new Vec4(x + v.x, y + v.y, z + v.z, w + v.w);
|
||||
}
|
||||
inline Vec4& operator-(const Vec4<T>& v) {
|
||||
return new Vec4(x - v.x, y - v.y, z - v.z, w - v.w);
|
||||
}
|
||||
inline Vec4& operator*(const Vec4<T>& v) {
|
||||
return new Vec4(x * v.x, y * v.y, z * v.z, w * v.w);
|
||||
}
|
||||
inline Vec4& operator/(const Vec4<T>& v) {
|
||||
return new Vec4(x / v.x, y / v.y, z / v.z, w / v.w);
|
||||
}
|
||||
inline Vec4& operator+=(const Vec4<T>& v) {
|
||||
x+=v.x; y+=v.y; z+=v.z; w+=v.w;
|
||||
return *this;
|
||||
}
|
||||
inline Vec4& operator-=(const Vec4<T>& v) {
|
||||
x-=v.x; y-=v.y; z-=v.z; w-=v.w;
|
||||
return *this;
|
||||
}
|
||||
inline Vec4& operator*=(const Vec4<T>& v) {
|
||||
x*=v.x; y*=v.y; z*=v.z; w*=v.w;
|
||||
return *this;
|
||||
}
|
||||
inline Vec4& operator/=(const Vec4<T>& v) {
|
||||
x/=v.x; y/=v.y; z/=v.z; w/=v.w;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec4& operator+=(P s) {
|
||||
x+=s; y+=s; z+=s; w+=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec4& operator-=(P s) {
|
||||
x-=s; y-=s; z-=s; w-=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec4& operator*=(P s) {
|
||||
x*=s; y*=s; z*=s; w*=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec4& operator/=(P s) {
|
||||
x/=s; y/=s; z/=s; w/=s;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct Vec3 {
|
||||
int x, y, z;
|
||||
Vec3(int x, int y, int z) : x(x), y(y), z(z) {}
|
||||
};
|
||||
|
||||
struct Vec3f {
|
||||
float x, y, z;
|
||||
Vec3f(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
T x, y, z;
|
||||
template<class P>
|
||||
Vec3(P x, P y, P z) : x(x), y(y), z(z) {}
|
||||
template<class P>
|
||||
Vec3(P all) : x(all), y(all), z(all) {}
|
||||
Vec3() : x(0), y(0), z(0) {}
|
||||
inline Vec3& cross(const Vec3<T>& v) {
|
||||
return new Vec3(
|
||||
(y * v.z - z * v.y),
|
||||
(x * v.z - z * v.x),
|
||||
(x * v.y - y * v.x)
|
||||
);
|
||||
}
|
||||
inline Vec3& dot(const Vec3<T>& v) {
|
||||
return (x * v.x + y * v.y + z * v.z);
|
||||
}
|
||||
inline const Vec3& operator+() {
|
||||
return *this;
|
||||
}
|
||||
inline Vec3& operator-() {
|
||||
return Vec3<T>(-x, -y, -z);
|
||||
}
|
||||
inline Vec3& operator+(const Vec3<T>& v) {
|
||||
return new Vec3(x + v.x, y + v.y, z + v.z);
|
||||
}
|
||||
inline Vec3& operator-(const Vec3<T>& v) {
|
||||
return new Vec3(x - v.x, y - v.y, z - v.z);
|
||||
}
|
||||
inline Vec3& operator*(const Vec3<T>& v) {
|
||||
return new Vec3(x * v.x, y * v.y, z * v.z);
|
||||
}
|
||||
inline Vec3& operator/(const Vec3<T>& v) {
|
||||
return new Vec3(x / v.x, y / v.y, z / v.z);
|
||||
}
|
||||
inline Vec3& operator+=(const Vec3<T>& v) {
|
||||
x+=v.x; y+=v.y; z+=v.z;
|
||||
return *this;
|
||||
}
|
||||
inline Vec3& operator-=(const Vec3<T>& v) {
|
||||
x-=v.x; y-=v.y; z-=v.z;
|
||||
return *this;
|
||||
}
|
||||
inline Vec3& operator*=(const Vec3<T>& v) {
|
||||
x*=v.x; y*=v.y; z*=v.z;
|
||||
return *this;
|
||||
}
|
||||
inline Vec3& operator/=(const Vec3<T>& v) {
|
||||
x/=v.x; y/=v.y; z/=v.z;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec3& operator+=(P s) {
|
||||
x+=s; y+=s; z+=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec3& operator-=(P s) {
|
||||
x-=s; y-=s; z-=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec3& operator*=(P s) {
|
||||
x*=s; y*=s; z*=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec3& operator/=(P s) {
|
||||
x/=s; y/=s; z/=s;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct Vec2 {
|
||||
int x, y;
|
||||
Vec2(int x, int y) : x(x), y(y) {}
|
||||
};
|
||||
|
||||
struct Vec2f {
|
||||
float x, y;
|
||||
Vec2f(float x, float y) : x(x), y(y) {}
|
||||
T x, y;
|
||||
template<class P>
|
||||
Vec2(P x, P y) : x(x), y(y) {}
|
||||
template<class P>
|
||||
Vec2(P all) : x(all), y(all) {}
|
||||
Vec2() : x(0), y(0) {}
|
||||
inline const Vec2& operator+() {
|
||||
return *this;
|
||||
}
|
||||
inline Vec2& dot(const Vec3<T>& v) {
|
||||
return (x * v.x + y * v.y);
|
||||
}
|
||||
inline Vec2& operator-() {
|
||||
return Vec3<T>(-x, -y);
|
||||
}
|
||||
inline Vec2& operator+(const Vec2<T>& v) {
|
||||
return new Vec2(x + v.x, y + v.y);
|
||||
}
|
||||
inline Vec2& operator-(const Vec2<T>& v) {
|
||||
return new Vec2(x - v.x, y - v.y);
|
||||
}
|
||||
inline Vec2& operator*(const Vec2<T>& v) {
|
||||
return new Vec2(x * v.x, y * v.y);
|
||||
}
|
||||
inline Vec2& operator/(const Vec2<T>& v) {
|
||||
return new Vec2(x / v.x, y / v.y);
|
||||
}
|
||||
inline Vec2& operator+=(const Vec2<T>& v) {
|
||||
x+=v.x; y+=v.y;
|
||||
return *this;
|
||||
}
|
||||
inline Vec2& operator-=(const Vec2<T>& v) {
|
||||
x-=v.x; y-=v.y;
|
||||
return *this;
|
||||
}
|
||||
inline Vec2& operator*=(const Vec2<T>& v) {
|
||||
x*=v.x; y*=v.y;
|
||||
return *this;
|
||||
}
|
||||
inline Vec2& operator/=(const Vec2<T>& v) {
|
||||
x/=v.x; y/=v.y;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec2& operator+=(P s) {
|
||||
x+=s; y+=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec2& operator-=(P s) {
|
||||
x-=s; y-=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec2& operator*=(P s) {
|
||||
x*=s; y*=s;
|
||||
return *this;
|
||||
}
|
||||
template<class P>
|
||||
inline Vec2& operator/=(P s) {
|
||||
x/=s; y/=s;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ bool Rect::Contains(Rect* rect) {
|
||||
return (rect->x >= x && rect->Right() <= (x + w) && rect->y >= y && rect->Bottom() <= (y + h));
|
||||
}
|
||||
|
||||
bool Rect::Contains(Vec2* point) {
|
||||
bool Rect::Contains(Vec2<int>* point) {
|
||||
return (point->x >= x && point->x <= (x + w) && point->y >= y && point->y <= (y + h));
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ bool Rect::Contains(int x, int y, int w, int h) {
|
||||
return Contains(&tempRect);
|
||||
}
|
||||
|
||||
Vec2* Rect::Position() {
|
||||
Vec2* res = new Vec2(x, y);
|
||||
Vec2<int>* Rect::Position() {
|
||||
Vec2<int>* res = new Vec2<int>(x, y);
|
||||
return res;
|
||||
}
|
||||
|
||||
Vec2* Rect::Center() {
|
||||
Vec2* res = new Vec2(x + (w / 2), y + (h / 2));
|
||||
Vec2<int>* Rect::Center() {
|
||||
Vec2<int>* res = new Vec2<int>(x + (w / 2), y + (h / 2));
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -142,17 +142,17 @@ void Rect::SetRect(int x, int y, int w, int h) {
|
||||
this->rect->h = h;
|
||||
}
|
||||
|
||||
void Rect::SetSize(Vec2* size) {
|
||||
void Rect::SetSize(Vec2<int>* size) {
|
||||
this->x = size->x;
|
||||
this->y = size->y;
|
||||
}
|
||||
|
||||
void Rect::SetPos(Vec2* pos) {
|
||||
void Rect::SetPos(Vec2<int>* pos) {
|
||||
this->w = pos->x;
|
||||
this->h = pos->y;
|
||||
}
|
||||
|
||||
void Rect::Translate(Vec2* offset) {
|
||||
void Rect::Translate(Vec2<int>* offset) {
|
||||
this->x += offset->x;
|
||||
this->y += offset->y;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ public:
|
||||
// bool Intersects(int x, int y, int w, int h);
|
||||
|
||||
bool Contains(Rect* rect);
|
||||
bool Contains(Vec2* point);
|
||||
bool Contains(Vec2<int>* point);
|
||||
bool Contains(int x, int y, int w, int h);
|
||||
|
||||
Vec2* Position();
|
||||
Vec2* Center();
|
||||
Vec2<int>* Position();
|
||||
Vec2<int>* Center();
|
||||
int CenterX();
|
||||
int CenterY();
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
int Right();
|
||||
int Top();
|
||||
int Bottom();
|
||||
int Perimiter();
|
||||
int Perimiter();
|
||||
int Area();
|
||||
|
||||
int GetX();
|
||||
@@ -56,9 +56,9 @@ public:
|
||||
int GetH();
|
||||
|
||||
void SetRect(int x, int y, int w, int h);
|
||||
void SetSize(Vec2* size);
|
||||
void SetPos(Vec2* pos);
|
||||
void Translate(Vec2* offset);
|
||||
void SetSize(Vec2<int>* size);
|
||||
void SetPos(Vec2<int>* pos);
|
||||
void Translate(Vec2<int>* offset);
|
||||
void TranslateX(int x);
|
||||
void TranslateY(int y);
|
||||
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include <logger.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// Logger.Log() << "Okay, this is epic" << 1234;
|
||||
|
||||
Game game;
|
||||
game.renderer.createWindow("Crumpet Engine", 600, 400, SCREEN_MODE_VSYNC);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user