overhauled physics engine

This commit is contained in:
Dynamitos
2023-01-21 18:43:21 +01:00
parent 3c7346cf7b
commit 2208ab438a
164 changed files with 22606 additions and 928 deletions
-3
View File
@@ -5,8 +5,6 @@
namespace Seele
{
namespace Math
{
struct Rect
{
Rect()
@@ -60,5 +58,4 @@ inline constexpr T align(const T ptr, int64_t alignment)
{
return (T)(((uint64_t)ptr + alignment - 1) & ~(alignment - 1));
}
} // namespace Math
} // namespace Seele
-3
View File
@@ -5,10 +5,7 @@
#include <glm/mat4x4.hpp>
namespace Seele
{
namespace Math
{
typedef glm::mat2 Matrix2;
typedef glm::mat3 Matrix3;
typedef glm::mat4 Matrix4;
} // namespace Math
} // namespace Seele
+3 -3
View File
@@ -145,17 +145,17 @@ Vector Transform::getScale() const
return Vector(scale);
}
void Transform::setPosition(Math::Vector pos)
void Transform::setPosition(Vector pos)
{
position = Vector4(pos, 0);
}
void Transform::setRotation(Math::Quaternion quat)
void Transform::setRotation(Quaternion quat)
{
rotation = quat;
}
void Transform::setScale(Math::Vector s)
void Transform::setScale(Vector s)
{
scale = Vector4(s, 0);
}
+3 -3
View File
@@ -26,9 +26,9 @@ public:
Quaternion getRotation() const;
Vector getScale() const;
void setPosition(Math::Vector pos);
void setRotation(Math::Quaternion quat);
void setScale(Math::Vector scale);
void setPosition(Vector pos);
void setRotation(Quaternion quat);
void setScale(Vector scale);
Vector getForward() const;
Vector getRight() const;
+25 -2
View File
@@ -1,7 +1,30 @@
#include "Vector.h"
#include <regex>
#include <format>
#include <nlohmann/json.hpp>
using namespace Seele::Math;
using namespace Seele;
void to_json(nlohmann::json& j, const Vector& vec)
{
j = nlohmann::json{std::format("({}, {}, {})", vec.x, vec.y, vec.z)};
}
void from_json(const nlohmann::json& j, Vector& vec)
{
std::string str;
j.get_to(str);
auto newEnd = std::remove(str.begin(), str.end(), ' ');
str.erase(newEnd);
std::stringstream stream(str);
std::string temp;
std::getline(stream, temp, ',');
vec.x = std::stof(temp);
std::getline(stream, temp, ',');
vec.y = std::stof(temp);
std::getline(stream, temp, ',');
vec.z = std::stof(temp);
}
std::ostream& operator<<(std::ostream& stream, const Vector2& vector)
{
@@ -19,7 +42,7 @@ std::ostream& operator<<(std::ostream& stream, const Vector4& vector)
return stream;
}
Vector Seele::Math::parseVector(const char* str)
Vector Seele::parseVector(const char* str)
{
//regex pattern consisting of 'float3(xComp, yComp, zComp)', more also matches for invalid floats, but that will throw later
std::regex pattern("float3\\(\\s*([0-9.]+f?)\\s*,\\s*([0-9.]+f?)\\s*,\\s*([0-9.]+f?)\\s*\\)");
+6 -7
View File
@@ -7,10 +7,9 @@
#include <glm/gtc/quaternion.hpp>
#pragma warning(pop)
#include <nlohmann/json_fwd.hpp>
namespace Seele
{
namespace Math
{
typedef glm::vec2 Vector2;
typedef glm::vec3 Vector;
typedef glm::vec4 Vector4;
@@ -96,10 +95,10 @@ static inline Vector toRotator(const Quaternion &other)
}
return rotatorFromQuat;
}
} // namespace Math
void to_json(nlohmann::json& j, const Vector& vec);
void from_json(nlohmann::json& j, Vector& vec);
} // namespace Seele
std::ostream& operator<<(std::ostream& stream, const Seele::Math::Vector2& vector);
std::ostream& operator<<(std::ostream& stream, const Seele::Math::Vector& vector);
std::ostream& operator<<(std::ostream& stream, const Seele::Math::Vector4& vector);
std::ostream& operator<<(std::ostream& stream, const Seele::Vector2& vector);
std::ostream& operator<<(std::ostream& stream, const Seele::Vector& vector);
std::ostream& operator<<(std::ostream& stream, const Seele::Vector4& vector);