tyrav2 init

This commit is contained in:
h4570
2022-07-17 10:21:35 +02:00
parent 44c1ee4fe8
commit c8b22ff331
249 changed files with 18187 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "math/vec2.hpp"
namespace Tyra {
Vec2::Vec2(const float& t_x, const float& t_y) {
x = t_x;
y = t_y;
}
Vec2::Vec2(const Vec2& v) {
x = v.x;
y = v.y;
}
Vec2::Vec2() {
x = 0;
y = 0;
}
Vec2::~Vec2() {}
void Vec2::set(const float& t_x, const float& t_y) {
x = t_x;
y = t_y;
}
void Vec2::set(const Vec2& v) {
x = v.x;
y = v.y;
}
void Vec2::rotate(const float& t_angle, const float& t_x, const float& t_y) {
float s = Math::sin(t_angle);
float c = Math::cos(t_angle);
x -= t_x;
y -= t_y;
float xnew = x * c - y * s;
float ynew = x * s + y * c;
x = xnew + t_x;
y = ynew + t_y;
}
void Vec2::print() const {
auto text = getPrint(nullptr);
printf("%s\n", text.c_str());
}
void Vec2::print(const char* name) const {
auto text = getPrint(name);
printf("%s\n", text.c_str());
}
std::string Vec2::getPrint(const char* name) const {
std::stringstream res;
if (name) {
res << name << "(";
} else {
res << "Vec2(";
}
res << std::fixed << std::setprecision(4);
res << x << ", " << y << ")";
return res.str();
}
} // namespace Tyra