Formatted EVERYTHING
This commit is contained in:
+39
-71
@@ -1,23 +1,20 @@
|
||||
#pragma once
|
||||
#include "Vector.h"
|
||||
#include "Matrix.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "Graphics/DebugVertex.h"
|
||||
namespace Seele
|
||||
{
|
||||
struct BoundingSphere
|
||||
{
|
||||
#include "Matrix.h"
|
||||
#include "Vector.h"
|
||||
|
||||
namespace Seele {
|
||||
struct BoundingSphere {
|
||||
Vector center;
|
||||
float radius;
|
||||
};
|
||||
struct AABB
|
||||
{
|
||||
struct AABB {
|
||||
Vector min = Vector(std::numeric_limits<float>::max());
|
||||
float pad0; // So that it can be used directly in shaders
|
||||
Vector max = Vector(std::numeric_limits<float>::lowest());// cause of reasons
|
||||
float pad0; // So that it can be used directly in shaders
|
||||
Vector max = Vector(std::numeric_limits<float>::lowest()); // cause of reasons
|
||||
float pad1;
|
||||
BoundingSphere toSphere() const
|
||||
{
|
||||
BoundingSphere toSphere() const {
|
||||
Vector center = (min + max) / 2.f;
|
||||
StaticArray<Vector, 8> corners;
|
||||
corners[0] = Vector(min.x, min.y, min.z);
|
||||
@@ -29,8 +26,7 @@ struct AABB
|
||||
corners[6] = Vector(max.x, max.y, min.z);
|
||||
corners[7] = Vector(max.x, max.y, max.z);
|
||||
float radius = 0;
|
||||
for (const auto& corner : corners)
|
||||
{
|
||||
for (const auto& corner : corners) {
|
||||
radius = std::max<float>(radius, glm::length(center - corner));
|
||||
}
|
||||
return BoundingSphere{
|
||||
@@ -38,17 +34,16 @@ struct AABB
|
||||
.radius = radius,
|
||||
};
|
||||
}
|
||||
void visualize(Array<DebugVertex>& vertices) const
|
||||
{
|
||||
void visualize(Array<DebugVertex>& vertices) const {
|
||||
StaticArray<DebugVertex, 8> corners;
|
||||
corners[0] = DebugVertex { .position = Vector(min.x, min.y, min.z), .color = Vector(0, 1, 0) };
|
||||
corners[1] = DebugVertex { .position = Vector(min.x, min.y, max.z), .color = Vector(0, 1, 0) };
|
||||
corners[2] = DebugVertex { .position = Vector(min.x, max.y, min.z), .color = Vector(0, 1, 0) };
|
||||
corners[3] = DebugVertex { .position = Vector(min.x, max.y, max.z), .color = Vector(0, 1, 0) };
|
||||
corners[4] = DebugVertex { .position = Vector(max.x, min.y, min.z), .color = Vector(0, 1, 0) };
|
||||
corners[5] = DebugVertex { .position = Vector(max.x, min.y, max.z), .color = Vector(0, 1, 0) };
|
||||
corners[6] = DebugVertex { .position = Vector(max.x, max.y, min.z), .color = Vector(0, 1, 0) };
|
||||
corners[7] = DebugVertex { .position = Vector(max.x, max.y, max.z), .color = Vector(0, 1, 0) };
|
||||
corners[0] = DebugVertex{.position = Vector(min.x, min.y, min.z), .color = Vector(0, 1, 0)};
|
||||
corners[1] = DebugVertex{.position = Vector(min.x, min.y, max.z), .color = Vector(0, 1, 0)};
|
||||
corners[2] = DebugVertex{.position = Vector(min.x, max.y, min.z), .color = Vector(0, 1, 0)};
|
||||
corners[3] = DebugVertex{.position = Vector(min.x, max.y, max.z), .color = Vector(0, 1, 0)};
|
||||
corners[4] = DebugVertex{.position = Vector(max.x, min.y, min.z), .color = Vector(0, 1, 0)};
|
||||
corners[5] = DebugVertex{.position = Vector(max.x, min.y, max.z), .color = Vector(0, 1, 0)};
|
||||
corners[6] = DebugVertex{.position = Vector(max.x, max.y, min.z), .color = Vector(0, 1, 0)};
|
||||
corners[7] = DebugVertex{.position = Vector(max.x, max.y, max.z), .color = Vector(0, 1, 0)};
|
||||
|
||||
vertices.add(corners[0]);
|
||||
vertices.add(corners[1]);
|
||||
@@ -61,7 +56,7 @@ struct AABB
|
||||
|
||||
vertices.add(corners[0]);
|
||||
vertices.add(corners[2]);
|
||||
|
||||
|
||||
vertices.add(corners[0]);
|
||||
vertices.add(corners[4]);
|
||||
|
||||
@@ -73,7 +68,7 @@ struct AABB
|
||||
|
||||
vertices.add(corners[3]);
|
||||
vertices.add(corners[7]);
|
||||
|
||||
|
||||
vertices.add(corners[4]);
|
||||
vertices.add(corners[5]);
|
||||
|
||||
@@ -86,51 +81,35 @@ struct AABB
|
||||
vertices.add(corners[4]);
|
||||
vertices.add(corners[6]);
|
||||
}
|
||||
float surfaceArea() const
|
||||
{
|
||||
float surfaceArea() const {
|
||||
Vector d = max - min;
|
||||
return 2.0f * (d.x * d.y + d.y * d.z + d.z * d.x);
|
||||
}
|
||||
bool intersects(const AABB& other) const
|
||||
{
|
||||
if (min.x > other.max.x
|
||||
|| max.x < other.min.x)
|
||||
{
|
||||
bool intersects(const AABB& other) const {
|
||||
if (min.x > other.max.x || max.x < other.min.x) {
|
||||
return false;
|
||||
}
|
||||
if (min.y > other.max.y
|
||||
|| max.y < other.min.y)
|
||||
{
|
||||
if (min.y > other.max.y || max.y < other.min.y) {
|
||||
return false;
|
||||
}
|
||||
if (min.z > other.max.z
|
||||
|| max.z < other.min.z)
|
||||
{
|
||||
if (min.z > other.max.z || max.z < other.min.z) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool contains(const AABB& other) const
|
||||
{
|
||||
if (min.x > other.min.x
|
||||
|| max.x < other.max.x)
|
||||
{
|
||||
bool contains(const AABB& other) const {
|
||||
if (min.x > other.min.x || max.x < other.max.x) {
|
||||
return false;
|
||||
}
|
||||
if (min.y > other.min.y
|
||||
|| max.y < other.max.y)
|
||||
{
|
||||
if (min.y > other.min.y || max.y < other.max.y) {
|
||||
return false;
|
||||
}
|
||||
if (min.z > other.min.z
|
||||
|| max.z < other.max.z)
|
||||
{
|
||||
if (min.z > other.min.z || max.z < other.max.z) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
AABB getTransformedBox(const Matrix4& matrix) const
|
||||
{
|
||||
AABB getTransformedBox(const Matrix4& matrix) const {
|
||||
StaticArray<Vector, 8> corners;
|
||||
corners[0] = Vector(min.x, min.y, min.z);
|
||||
corners[1] = Vector(min.x, min.y, max.z);
|
||||
@@ -142,40 +121,29 @@ struct AABB
|
||||
corners[7] = Vector(max.x, max.y, max.z);
|
||||
Vector tmin = Vector(std::numeric_limits<float>::max());
|
||||
Vector tmax = Vector(std::numeric_limits<float>::lowest());
|
||||
for(int i = 0; i < 8; ++i)
|
||||
{
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
Vector transformed = matrix * Vector4(corners[i], 1.0f);
|
||||
tmin = Vector(std::min(tmin.x, transformed.x), std::min(tmin.y, transformed.y), std::min(tmin.z, transformed.z));
|
||||
tmax = Vector(std::max(tmax.x, transformed.x), std::max(tmax.y, transformed.y), std::max(tmax.z, transformed.z));
|
||||
}
|
||||
return AABB {
|
||||
return AABB{
|
||||
.min = tmin,
|
||||
.max = tmax,
|
||||
};
|
||||
}
|
||||
void adjust(const Vector vertex)
|
||||
{
|
||||
void adjust(const Vector vertex) {
|
||||
min.x = std::min(min.x, vertex.x);
|
||||
min.y = std::min(min.y, vertex.y);
|
||||
min.z = std::min(min.z, vertex.z);
|
||||
|
||||
|
||||
max.x = std::max(max.x, vertex.x);
|
||||
max.y = std::max(max.y, vertex.y);
|
||||
max.z = std::max(max.z, vertex.z);
|
||||
}
|
||||
AABB combine(const AABB& other) const
|
||||
{
|
||||
return AABB {
|
||||
.min = Vector(
|
||||
std::min(min.x, other.min.x),
|
||||
std::min(min.y, other.min.y),
|
||||
std::min(min.z, other.min.z)
|
||||
),
|
||||
.max = Vector (
|
||||
std::max(max.x, other.max.x),
|
||||
std::max(max.y, other.max.y),
|
||||
std::max(max.z, other.max.z)
|
||||
),
|
||||
AABB combine(const AABB& other) const {
|
||||
return AABB{
|
||||
.min = Vector(std::min(min.x, other.min.x), std::min(min.y, other.min.y), std::min(min.z, other.min.z)),
|
||||
.max = Vector(std::max(max.x, other.max.x), std::max(max.y, other.max.y), std::max(max.z, other.max.z)),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
+15
-21
@@ -1,28 +1,22 @@
|
||||
#pragma once
|
||||
#include "Vector.h"
|
||||
#include "Matrix.h"
|
||||
#include "EngineTypes.h"
|
||||
#include "Matrix.h"
|
||||
#include "Vector.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct Rect
|
||||
{
|
||||
bool isEmpty() const
|
||||
{
|
||||
return size.x == 0 || size.y == 0;
|
||||
}
|
||||
Vector2 size;
|
||||
Vector2 offset;
|
||||
|
||||
namespace Seele {
|
||||
struct Rect {
|
||||
bool isEmpty() const { return size.x == 0 || size.y == 0; }
|
||||
Vector2 size;
|
||||
Vector2 offset;
|
||||
};
|
||||
//Unsigned int
|
||||
struct URect
|
||||
{
|
||||
UVector2 size = UVector2(0);
|
||||
UVector2 offset = UVector2(0);
|
||||
// Unsigned int
|
||||
struct URect {
|
||||
UVector2 size = UVector2(0);
|
||||
UVector2 offset = UVector2(0);
|
||||
};
|
||||
struct Rect3D
|
||||
{
|
||||
Vector size = Vector(0);
|
||||
Vector offset = Vector(0);
|
||||
struct Rect3D {
|
||||
Vector size = Vector(0);
|
||||
Vector offset = Vector(0);
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -3,8 +3,7 @@
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
namespace Seele
|
||||
{
|
||||
namespace Seele {
|
||||
typedef glm::mat2 Matrix2;
|
||||
typedef glm::mat3 Matrix3;
|
||||
typedef glm::mat4 Matrix4;
|
||||
|
||||
+36
-103
@@ -1,50 +1,30 @@
|
||||
#include "Transform.h"
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include "Transform.h"
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Math;
|
||||
|
||||
Transform::Transform()
|
||||
: position(Vector4(0, 0, 0, 0)), rotation(Quaternion(1, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform() : position(Vector4(0, 0, 0, 0)), rotation(Quaternion(1, 0, 0, 0)), scale(Vector4(1, 1, 1, 0)) {}
|
||||
|
||||
Transform::Transform(Transform &&other)
|
||||
: position(other.position), rotation(other.rotation), scale(other.scale)
|
||||
{
|
||||
Transform::Transform(Transform&& other) : position(other.position), rotation(other.rotation), scale(other.scale) {
|
||||
other.position = Vector4(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(1, 0, 0, 0);
|
||||
other.scale = Vector4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
Transform::Transform(const Transform &other)
|
||||
: position(other.position), rotation(other.rotation), scale(other.scale)
|
||||
{
|
||||
}
|
||||
Transform::Transform(const Transform& other) : position(other.position), rotation(other.rotation), scale(other.scale) {}
|
||||
|
||||
Transform::Transform(Vector position)
|
||||
: position(Vector4(position, 0)), rotation(Quaternion(1, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform(Vector position) : position(Vector4(position, 0)), rotation(Quaternion(1, 0, 0, 0)), scale(Vector4(1, 1, 1, 0)) {}
|
||||
Transform::Transform(Vector position, Quaternion rotation)
|
||||
: position(Vector4(position, 0)), rotation(rotation), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
: position(Vector4(position, 0)), rotation(rotation), scale(Vector4(1, 1, 1, 0)) {}
|
||||
Transform::Transform(Vector position, Quaternion rotation, Vector scale)
|
||||
: position(Vector4(position, 0)), rotation(rotation), scale(Vector4(scale, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform(Quaternion rotation, Vector scale)
|
||||
: position(Vector4(0, 0, 0, 0)), rotation(rotation), scale(Vector4(scale, 0))
|
||||
{
|
||||
}
|
||||
Transform::~Transform()
|
||||
{
|
||||
}
|
||||
Matrix4 Transform::toMatrix() const
|
||||
{
|
||||
: position(Vector4(position, 0)), rotation(rotation), scale(Vector4(scale, 0)) {}
|
||||
Transform::Transform(Quaternion rotation, Vector scale) : position(Vector4(0, 0, 0, 0)), rotation(rotation), scale(Vector4(scale, 0)) {}
|
||||
Transform::~Transform() {}
|
||||
Matrix4 Transform::toMatrix() const {
|
||||
// TODO: actual calculations, SIMD
|
||||
Matrix4 result = Matrix4(1);
|
||||
result = glm::scale(result, Vector(scale));
|
||||
@@ -55,98 +35,55 @@ Matrix4 Transform::toMatrix() const
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector Transform::transformPosition(const Vector &v) const
|
||||
{
|
||||
return Vector(glm::toMat4(rotation) * Vector4(v, 1));
|
||||
}
|
||||
Vector Transform::transformPosition(const Vector& v) const { return Vector(glm::toMat4(rotation) * Vector4(v, 1)); }
|
||||
|
||||
Vector Transform::getPosition() const
|
||||
{
|
||||
return Vector(position);
|
||||
}
|
||||
Vector Transform::getPosition() const { return Vector(position); }
|
||||
|
||||
Quaternion Transform::getRotation() const
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
Quaternion Transform::getRotation() const { return rotation; }
|
||||
|
||||
Vector Transform::getScale() const
|
||||
{
|
||||
return Vector(scale);
|
||||
}
|
||||
Vector Transform::getScale() const { return Vector(scale); }
|
||||
|
||||
void Transform::setPosition(Vector pos)
|
||||
{
|
||||
position = Vector4(pos, 0);
|
||||
}
|
||||
void Transform::setPosition(Vector pos) { position = Vector4(pos, 0); }
|
||||
|
||||
void Transform::setRotation(Quaternion quat)
|
||||
{
|
||||
rotation = quat;
|
||||
}
|
||||
void Transform::setRotation(Quaternion quat) { rotation = quat; }
|
||||
|
||||
void Transform::setScale(Vector s)
|
||||
{
|
||||
scale = Vector4(s, 0);
|
||||
}
|
||||
void Transform::setScale(Vector s) { scale = Vector4(s, 0); }
|
||||
|
||||
Vector Transform::getForward() const
|
||||
{
|
||||
return glm::normalize(Vector(0, 0, 1) * rotation);
|
||||
}
|
||||
Vector Transform::getForward() const { return glm::normalize(Vector(0, 0, 1) * rotation); }
|
||||
|
||||
Vector Transform::getRight() const
|
||||
{
|
||||
return glm::normalize(Vector(1, 0, 0) * rotation);
|
||||
}
|
||||
Vector Transform::getRight() const { return glm::normalize(Vector(1, 0, 0) * rotation); }
|
||||
|
||||
Vector Transform::getUp() const
|
||||
{
|
||||
return glm::normalize(Vector(0, 1, 0) * rotation);
|
||||
}
|
||||
Vector Transform::getUp() const { return glm::normalize(Vector(0, 1, 0) * rotation); }
|
||||
|
||||
bool Transform::equals(const Transform &other, float tolerance)
|
||||
{
|
||||
if (abs(position - other.position).length() > tolerance)
|
||||
{
|
||||
bool Transform::equals(const Transform& other, float tolerance) {
|
||||
if (abs(position - other.position).length() > tolerance) {
|
||||
return false;
|
||||
}
|
||||
if ((abs(rotation.x - other.rotation.x) <= tolerance
|
||||
&& abs(rotation.y - other.rotation.y) <= tolerance
|
||||
&& abs(rotation.z - other.rotation.z) <= tolerance
|
||||
&& abs(rotation.w - other.rotation.w) <= tolerance)
|
||||
|| (abs(rotation.x + other.rotation.x) <= tolerance
|
||||
&& abs(rotation.y + other.rotation.y) <= tolerance
|
||||
&& abs(rotation.z + other.rotation.z) <= tolerance
|
||||
&& abs(rotation.w + other.rotation.w) <= tolerance))
|
||||
{
|
||||
if ((abs(rotation.x - other.rotation.x) <= tolerance && abs(rotation.y - other.rotation.y) <= tolerance &&
|
||||
abs(rotation.z - other.rotation.z) <= tolerance && abs(rotation.w - other.rotation.w) <= tolerance) ||
|
||||
(abs(rotation.x + other.rotation.x) <= tolerance && abs(rotation.y + other.rotation.y) <= tolerance &&
|
||||
abs(rotation.z + other.rotation.z) <= tolerance && abs(rotation.w + other.rotation.w) <= tolerance)) {
|
||||
return false;
|
||||
}
|
||||
if (abs(scale - other.scale).length() > tolerance)
|
||||
{
|
||||
if (abs(scale - other.scale).length() > tolerance) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Transform::multiply(Transform *outTransform, const Transform *a, const Transform *b)
|
||||
{
|
||||
void Transform::multiply(Transform* outTransform, const Transform* a, const Transform* b) {
|
||||
outTransform->rotation = b->rotation * a->rotation;
|
||||
outTransform->position = b->rotation * (b->scale * a->position) + b->position;
|
||||
outTransform->scale = b->scale * a->scale;
|
||||
}
|
||||
void Transform::add(Transform *outTransform, const Transform *a, const Transform *b)
|
||||
{
|
||||
void Transform::add(Transform* outTransform, const Transform* a, const Transform* b) {
|
||||
outTransform->position = a->position + b->position;
|
||||
outTransform->rotation = a->rotation + b->rotation;
|
||||
outTransform->scale = a->scale + b->scale;
|
||||
}
|
||||
|
||||
|
||||
Transform &Transform::operator=(const Transform &other)
|
||||
{
|
||||
if(&other != this)
|
||||
{
|
||||
Transform& Transform::operator=(const Transform& other) {
|
||||
if (&other != this) {
|
||||
position = other.position;
|
||||
rotation = other.rotation;
|
||||
scale = other.scale;
|
||||
@@ -154,10 +91,8 @@ Transform &Transform::operator=(const Transform &other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Transform &Transform::operator=(Transform &&other)
|
||||
{
|
||||
if(&other != this)
|
||||
{
|
||||
Transform& Transform::operator=(Transform&& other) {
|
||||
if (&other != this) {
|
||||
position = other.position;
|
||||
rotation = other.rotation;
|
||||
scale = other.scale;
|
||||
@@ -168,15 +103,13 @@ Transform &Transform::operator=(Transform &&other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Transform Transform::operator+(const Transform & other) const
|
||||
{
|
||||
Transform Transform::operator+(const Transform& other) const {
|
||||
Transform outTransform;
|
||||
add(&outTransform, this, &other);
|
||||
return outTransform;
|
||||
}
|
||||
|
||||
Transform Transform::operator*(const Transform &other) const
|
||||
{
|
||||
Transform Transform::operator*(const Transform& other) const {
|
||||
Transform outTransform;
|
||||
multiply(&outTransform, this, &other);
|
||||
return outTransform;
|
||||
|
||||
+16
-18
@@ -1,24 +1,22 @@
|
||||
#pragma once
|
||||
#include "Math/Vector.h"
|
||||
#include "Math/Matrix.h"
|
||||
#include "Math/Vector.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
class Transform
|
||||
{
|
||||
public:
|
||||
|
||||
namespace Seele {
|
||||
namespace Math {
|
||||
class Transform {
|
||||
public:
|
||||
Transform();
|
||||
Transform(const Transform &other);
|
||||
Transform(Transform &&other);
|
||||
Transform(const Transform& other);
|
||||
Transform(Transform&& other);
|
||||
explicit Transform(Vector position);
|
||||
Transform(Vector position, Quaternion rotation);
|
||||
Transform(Vector position, Quaternion rotation, Vector scale);
|
||||
Transform(Quaternion rotation, Vector scale);
|
||||
~Transform();
|
||||
Matrix4 toMatrix() const;
|
||||
Vector transformPosition(const Vector &v) const;
|
||||
Vector transformPosition(const Vector& v) const;
|
||||
|
||||
Vector getPosition() const;
|
||||
Quaternion getRotation() const;
|
||||
@@ -32,16 +30,16 @@ public:
|
||||
Vector getRight() const;
|
||||
Vector getUp() const;
|
||||
|
||||
bool equals(const Transform &other, float tolerance = 0.000000001f);
|
||||
static void multiply(Transform *outTransform, const Transform *a, const Transform *b);
|
||||
static void add(Transform *outTransform, const Transform *a, const Transform *b);
|
||||
bool equals(const Transform& other, float tolerance = 0.000000001f);
|
||||
static void multiply(Transform* outTransform, const Transform* a, const Transform* b);
|
||||
static void add(Transform* outTransform, const Transform* a, const Transform* b);
|
||||
|
||||
Transform &operator=(const Transform &other);
|
||||
Transform &operator=(Transform &&other);
|
||||
Transform& operator=(const Transform& other);
|
||||
Transform& operator=(Transform&& other);
|
||||
Transform operator+(const Transform& other) const;
|
||||
Transform operator*(const Transform &other) const;
|
||||
Transform operator*(const Transform& other) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
Vector4 position;
|
||||
Quaternion rotation;
|
||||
Vector4 scale;
|
||||
|
||||
+13
-20
@@ -1,19 +1,16 @@
|
||||
#include "Vector.h"
|
||||
#include <regex>
|
||||
#include <fmt/core.h>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "Serialization/ArchiveBuffer.h"
|
||||
#include <fmt/core.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
void to_json(nlohmann::json& j, const Vector& vec)
|
||||
{
|
||||
j = nlohmann::json{fmt::format("({}, {}, {})", vec.x, vec.y, vec.z)};
|
||||
}
|
||||
void to_json(nlohmann::json& j, const Vector& vec) { j = nlohmann::json{fmt::format("({}, {}, {})", vec.x, vec.y, vec.z)}; }
|
||||
|
||||
void from_json(const nlohmann::json& j, Vector& vec)
|
||||
{
|
||||
void from_json(const nlohmann::json& j, Vector& vec) {
|
||||
std::string str;
|
||||
j.get_to(str);
|
||||
auto newEnd = std::remove(str.begin(), str.end(), ' ');
|
||||
@@ -28,29 +25,25 @@ void from_json(const nlohmann::json& j, Vector& vec)
|
||||
vec.z = std::stof(temp);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector2& vector)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector2& vector) {
|
||||
stream << "(" << vector.x << ", " << vector.y << ")";
|
||||
return stream;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector& vector)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector& vector) {
|
||||
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
|
||||
return stream;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector4& vector)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector4& vector) {
|
||||
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ", " << vector.w << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
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
|
||||
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*\\)");
|
||||
std::cmatch base_match;
|
||||
std::regex_match(str, base_match, pattern);
|
||||
//match 0 is the whole expression
|
||||
// match 0 is the whole expression
|
||||
float x = std::stof(base_match[1].str());
|
||||
float y = std::stof(base_match[2].str());
|
||||
float z = std::stof(base_match[3].str());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#ifdef WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4201)
|
||||
#pragma warning(disable : 4201)
|
||||
#endif
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
@@ -13,8 +13,7 @@
|
||||
#endif
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Seele {
|
||||
typedef glm::vec2 Vector2;
|
||||
typedef glm::vec3 Vector;
|
||||
typedef glm::vec4 Vector4;
|
||||
|
||||
Reference in New Issue
Block a user