Adding nlohmanns json library
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Vector.h"
|
||||
#include "Matrix.h"
|
||||
#include "EngineTypes.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -24,6 +25,28 @@ struct Rect
|
||||
Vector2 size;
|
||||
Vector2 offset;
|
||||
};
|
||||
//Unsigned int
|
||||
struct URect
|
||||
{
|
||||
URect()
|
||||
: size(0, 0), offset(0, 0)
|
||||
{
|
||||
}
|
||||
URect(uint32 sizeX, uint32 sizeY, uint32 offsetX, uint32 offsetY)
|
||||
: size(sizeX, sizeY), offset(offsetX, offsetY)
|
||||
{
|
||||
}
|
||||
URect(UVector2 size, UVector2 offset)
|
||||
: size(size), offset(offset)
|
||||
{
|
||||
}
|
||||
bool isEmpty() const
|
||||
{
|
||||
return size.x == 0 || size.y == 0;
|
||||
}
|
||||
UVector2 size;
|
||||
UVector2 offset;
|
||||
};
|
||||
struct Rect3D
|
||||
{
|
||||
Vector size;
|
||||
|
||||
@@ -7,6 +7,19 @@ Transform::Transform()
|
||||
{
|
||||
}
|
||||
|
||||
Transform::Transform(Transform &&other)
|
||||
: position(other.position), rotation(other.rotation), scale(scale)
|
||||
{
|
||||
other.position = Vector4(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(0, 0, 0, 0);
|
||||
other.scale = Vector4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
Transform::Transform(const Transform &other)
|
||||
: position(other.position), rotation(other.rotation), scale(scale)
|
||||
{
|
||||
}
|
||||
|
||||
Transform::Transform(Vector position)
|
||||
: position(Vector4(position, 0)), rotation(Quaternion(0, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
@@ -26,12 +39,61 @@ Transform::Transform(Quaternion rotation, Vector scale)
|
||||
Transform::~Transform()
|
||||
{
|
||||
}
|
||||
Vector Transform::inverseTransformPosition(const Vector& v) const
|
||||
Vector Transform::inverseTransformPosition(const Vector &v) const
|
||||
{
|
||||
return (unrotateVector(rotation, v - Vector(position))) * getSafeScaleReciprocal(scale);
|
||||
}
|
||||
Matrix4 Transform::toMatrix()
|
||||
{
|
||||
Matrix4 mat;
|
||||
|
||||
Vector Transform::getSafeScaleReciprocal(const Vector4& inScale, float tolerance)
|
||||
mat[3][0] = position.x;
|
||||
mat[3][1] = position.y;
|
||||
mat[3][2] = position.z;
|
||||
|
||||
const float x2 = rotation.x + rotation.x;
|
||||
const float y2 = rotation.y + rotation.y;
|
||||
const float z2 = rotation.z + rotation.z;
|
||||
{
|
||||
const float xx2 = rotation.x * x2;
|
||||
const float yy2 = rotation.y * y2;
|
||||
const float zz2 = rotation.z * z2;
|
||||
|
||||
mat[0][0] = (1.0f - (yy2 + zz2)) * scale.x;
|
||||
mat[1][1] = (1.0f - (xx2 + zz2)) * scale.y;
|
||||
mat[2][2] = (1.0f - (xx2 + yy2)) * scale.z;
|
||||
}
|
||||
|
||||
{
|
||||
const float yz2 = rotation.y * z2;
|
||||
const float wx2 = rotation.w * x2;
|
||||
|
||||
mat[2][1] = (yz2 - wx2) * scale.z;
|
||||
mat[1][2] = (yz2 + wx2) * scale.y;
|
||||
}
|
||||
{
|
||||
const float xy2 = rotation.x * y2;
|
||||
const float wz2 = rotation.w * z2;
|
||||
|
||||
mat[1][0] = (xy2 - wz2) * scale.y;
|
||||
mat[0][1] = (xy2 + wz2) * scale.x;
|
||||
}
|
||||
{
|
||||
const float xz2 = rotation.x * z2;
|
||||
const float wy2 = rotation.w * y2;
|
||||
|
||||
mat[2][0] = (xz2 + wy2) * scale.z;
|
||||
mat[0][2] = (xz2 - wy2) * scale.x;
|
||||
}
|
||||
|
||||
mat[0][3] = 0.0f;
|
||||
mat[1][3] = 0.0f;
|
||||
mat[2][3] = 0.0f;
|
||||
mat[3][3] = 1.0f;
|
||||
|
||||
return mat;
|
||||
}
|
||||
Vector Transform::getSafeScaleReciprocal(const Vector4 &inScale, float tolerance)
|
||||
{
|
||||
Vector safeReciprocalScale;
|
||||
if (abs(inScale.x) <= tolerance)
|
||||
@@ -61,24 +123,67 @@ Vector Transform::getSafeScaleReciprocal(const Vector4& inScale, float tolerance
|
||||
return safeReciprocalScale;
|
||||
}
|
||||
|
||||
inline Vector Transform::getPosition() const
|
||||
Vector Transform::getPosition() const
|
||||
{
|
||||
return Vector(position);
|
||||
}
|
||||
|
||||
inline Quaternion Transform::getRotation() const
|
||||
Quaternion Transform::getRotation() const
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
inline Vector Transform::getScale() const
|
||||
Vector Transform::getScale() const
|
||||
{
|
||||
return Vector(scale);
|
||||
}
|
||||
|
||||
inline void Transform::multiply(Transform* outTransform, const Transform* a, const Transform* b)
|
||||
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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (abs(scale - other.scale).length() > tolerance)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Transform::multiply(Transform *outTransform, const Transform *a, const Transform *b)
|
||||
{
|
||||
outTransform->rotation = b->rotation * a->rotation;
|
||||
outTransform->position = b->position * (b->scale * a->position) + b->position;
|
||||
outTransform->scale = b->scale * a->scale;
|
||||
}
|
||||
|
||||
Transform &Transform::operator=(const Transform &other)
|
||||
{
|
||||
position = other.position;
|
||||
rotation = other.rotation;
|
||||
scale = other.scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Transform &Transform::operator=(Transform &&other)
|
||||
{
|
||||
position = other.position;
|
||||
rotation = other.rotation;
|
||||
scale = other.scale;
|
||||
other.position = Vector4(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(0, 0, 0, 0);
|
||||
other.scale = Vector4(0, 0, 0, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Transform &Transform::operator*(const Transform &other) const
|
||||
{
|
||||
Transform outTransform;
|
||||
multiply(&outTransform, this, &other);
|
||||
return outTransform;
|
||||
}
|
||||
|
||||
+13
-11
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Vector.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -7,26 +8,27 @@ class Transform
|
||||
{
|
||||
public:
|
||||
Transform();
|
||||
Transform(const Transform &other);
|
||||
Transform(Transform &&other);
|
||||
Transform(Vector position);
|
||||
Transform(Vector position, Quaternion rotation);
|
||||
Transform(Vector position, Quaternion rotation, Vector scale);
|
||||
Transform(Quaternion rotation, Vector scale);
|
||||
~Transform();
|
||||
Vector inverseTransformPosition(const Vector &v) const;
|
||||
static Vector getSafeScaleReciprocal(const Vector4 &inScale, float tolerance = 0.00001f);
|
||||
Matrix4 toMatrix();
|
||||
static Vector getSafeScaleReciprocal(const Vector4 &inScale, float tolerance = 0.000000001f);
|
||||
|
||||
inline Vector getPosition() const;
|
||||
inline Quaternion getRotation() const;
|
||||
inline Vector getScale() const;
|
||||
Vector getPosition() const;
|
||||
Quaternion getRotation() const;
|
||||
Vector getScale() const;
|
||||
|
||||
inline static void multiply(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);
|
||||
|
||||
Transform& operator*(const Transform& other) const
|
||||
{
|
||||
Transform outTransform;
|
||||
multiply(&outTransform, this, &other);
|
||||
return outTransform;
|
||||
}
|
||||
Transform &operator=(const Transform &other);
|
||||
Transform &operator=(Transform &&other);
|
||||
Transform &operator*(const Transform &other) const;
|
||||
|
||||
private:
|
||||
Vector4 position;
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
#pragma warning(disable : 4201)
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#pragma warning(default : 4201)
|
||||
namespace Seele
|
||||
{
|
||||
typedef glm::vec2 Vector2;
|
||||
@@ -21,7 +24,7 @@ typedef glm::quat Quaternion;
|
||||
|
||||
static inline float square(float x)
|
||||
{
|
||||
return x * x;
|
||||
return x * x;
|
||||
}
|
||||
|
||||
static inline Vector unrotateVector(Quaternion quaternion, Vector v)
|
||||
@@ -32,10 +35,9 @@ static inline Vector unrotateVector(Quaternion quaternion, Vector v)
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline bool equalsQuaternion(const Quaternion& right, const Quaternion& left, float tolerance)
|
||||
static inline bool equalsQuaternion(const Quaternion &right, const Quaternion &left, float tolerance)
|
||||
{
|
||||
return (abs(right.x - left.x) <= tolerance && abs(right.y - left.y) <= tolerance && abs(right.z - left.z) <= tolerance && abs(right.w - left.w) <= tolerance)
|
||||
|| (abs(right.x + left.x) <= tolerance && abs(right.y + left.y) <= tolerance && abs(right.z + left.z) <= tolerance && abs(right.w + left.w) <= tolerance);
|
||||
return (abs(right.x - left.x) <= tolerance && abs(right.y - left.y) <= tolerance && abs(right.z - left.z) <= tolerance && abs(right.w - left.w) <= tolerance) || (abs(right.x + left.x) <= tolerance && abs(right.y + left.y) <= tolerance && abs(right.z + left.z) <= tolerance && abs(right.w + left.w) <= tolerance);
|
||||
}
|
||||
|
||||
static inline float clampRotatorAxis(float angle)
|
||||
@@ -58,7 +60,7 @@ static inline float normalizeRotatorAxis(float angle)
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline Quaternion toQuaternion(const Vector& other)
|
||||
static inline Quaternion toQuaternion(const Vector &other)
|
||||
{
|
||||
Quaternion result;
|
||||
const float DEG_TO_RAD = glm::pi<float>() / (180.f);
|
||||
@@ -71,7 +73,7 @@ static inline Quaternion toQuaternion(const Vector& other)
|
||||
const float SP = sin(PitchNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float SY = sin(YawNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float SR = sin(RollNoWinding * RADS_DIVIDED_BY_2);
|
||||
|
||||
|
||||
const float CP = cos(PitchNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float CY = cos(YawNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float CR = cos(RollNoWinding * RADS_DIVIDED_BY_2);
|
||||
@@ -83,12 +85,12 @@ static inline Quaternion toQuaternion(const Vector& other)
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline Vector toRotator(const Quaternion& other)
|
||||
static inline Vector toRotator(const Quaternion &other)
|
||||
{
|
||||
const float singularityTest = other.z * other.x - other.w * other.y;
|
||||
const float yawY = 2.f * (other.w * other.z + other.x * other.y);
|
||||
const float yawX = (1.f - 2.f * (square(other.y) + square(other.z)));
|
||||
|
||||
|
||||
const float SINGULARITY_THRESHOLD = 0.4999995f;
|
||||
const float RAD_TO_DEG = (180.f) / glm::pi<float>();
|
||||
Vector rotatorFromQuat;
|
||||
|
||||
Reference in New Issue
Block a user