Moved hydra to its own namespace

This commit is contained in:
2023-08-05 21:00:37 -07:00
parent 6cb2c06bea
commit 9c1de3d017
27 changed files with 110 additions and 138 deletions

View File

@@ -31,15 +31,14 @@
// Axis aligned bounding box (AABB)
#ifndef KRAKEN_AABB_H
#define KRAKEN_AABB_H
#pragma once
#include <functional> // for hash<>
#include "vector2.h"
#include "vector3.h"
namespace kraken {
namespace hydra {
class Matrix4;
@@ -84,23 +83,20 @@ public:
float longest_radius() const;
Vector3 nearestPoint(const Vector3& v) const;
};
static_assert(std::is_pod<AABB>::value, "kraken::AABB must be a POD type.");
static_assert(std::is_pod<AABB>::value, "hydra::AABB must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::AABB>
struct hash<hydra::AABB>
{
public:
size_t operator()(const kraken::AABB& s) const
size_t operator()(const hydra::AABB& s) const
{
size_t h1 = hash<kraken::Vector3>()(s.min);
size_t h2 = hash<kraken::Vector3>()(s.max);
size_t h1 = hash<hydra::Vector3>()(s.min);
size_t h2 = hash<hydra::Vector3>()(s.max);
return h1 ^ (h2 << 1);
}
};
} // namespace std
#endif /* defined(KRAKEN_AABB_H) */

View File

@@ -29,14 +29,13 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAKEN_HITINFO_H
#define KRAKEN_HITINFO_H
#pragma once
#include "vector3.h"
class KRNode;
namespace kraken {
namespace hydra {
class HitInfo
{
@@ -61,6 +60,5 @@ private:
float m_distance;
};
} // namespace kraken
} // namespace hydra
#endif

View File

@@ -29,8 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAKEN_HYDRA_H
#define KRAKEN_HYDRA_H
#pragma once
#include "scalar.h"
#include "vector2.h"
@@ -45,5 +44,3 @@
#include "aabb.h"
#include "triangle3.h"
#include "hitinfo.h"
#endif // KRAKEN_HYDRA_H

View File

@@ -31,10 +31,9 @@
#include "vector2.h"
#ifndef KRAKEN_MATRIX2_H
#define KRAKEN_MATRIX2_H
#pragma once
namespace kraken {
namespace hydra {
class Matrix2
{
@@ -89,22 +88,20 @@ public:
static Matrix2 Scaling(const Vector2& v);
static Matrix2 Identity();
};
static_assert(std::is_pod<Matrix2>::value, "kraken::Matrix2 must be a POD type.");
static_assert(std::is_pod<Matrix2>::value, "hydra::Matrix2 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Matrix2>
struct hash<hydra::Matrix2>
{
public:
size_t operator()(const kraken::Matrix2& s) const
size_t operator()(const hydra::Matrix2& s) const
{
size_t h1 = hash<kraken::Vector2>()(s.axis_x);
size_t h2 = hash<kraken::Vector2>()(s.axis_y);
size_t h1 = hash<hydra::Vector2>()(s.axis_x);
size_t h2 = hash<hydra::Vector2>()(s.axis_y);
return h1 ^ (h2 << 1);
}
};
} // namespace std
#endif // KRAKEN_MATRIX2_H

View File

@@ -32,10 +32,9 @@
#include "vector2.h"
#include "vector3.h"
#ifndef KRAKEN_MATRIX2X3_H
#define KRAKEN_MATRIX2X3_H
#pragma once
namespace kraken {
namespace hydra {
class Matrix2x3
{
@@ -91,23 +90,22 @@ public:
static Matrix2x3 Scaling(const Vector2& v);
static Matrix2x3 Identity();
};
static_assert(std::is_pod<Matrix2x3>::value, "kraken::Matrix2x3 must be a POD type.");
static_assert(std::is_pod<Matrix2x3>::value, "hydra::Matrix2x3 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Matrix2x3>
struct hash<hydra::Matrix2x3>
{
public:
size_t operator()(const kraken::Matrix2x3& s) const
size_t operator()(const hydra::Matrix2x3& s) const
{
size_t h1 = hash<kraken::Vector2>()(s.axis_x);
size_t h2 = hash<kraken::Vector2>()(s.axis_y);
size_t h3 = hash<kraken::Vector2>()(s.transform);
size_t h1 = hash<hydra::Vector2>()(s.axis_x);
size_t h2 = hash<hydra::Vector2>()(s.axis_y);
size_t h3 = hash<hydra::Vector2>()(s.transform);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};
} // namespace std
#endif // KRAKEN_MATRIX2X3_H

View File

@@ -33,10 +33,9 @@
#include "vector3.h"
#include "vector4.h"
#ifndef KRAKEN_MATRIX4_H
#define KRAKEN_MATRIX4_H
#pragma once
namespace kraken {
namespace hydra {
enum class AXIS
{
@@ -114,24 +113,22 @@ public:
static Matrix4 Scaling(const Vector3& v);
static Matrix4 Identity();
};
static_assert(std::is_pod<Matrix4>::value, "kraken::Matrix4 must be a POD type.");
static_assert(std::is_pod<Matrix4>::value, "hydra::Matrix4 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Matrix4>
struct hash<hydra::Matrix4>
{
public:
size_t operator()(const kraken::Matrix4& s) const
size_t operator()(const hydra::Matrix4& s) const
{
size_t h1 = hash<kraken::Vector4>()(s.axis_x);
size_t h2 = hash<kraken::Vector4>()(s.axis_y);
size_t h3 = hash<kraken::Vector4>()(s.axis_z);
size_t h4 = hash<kraken::Vector4>()(s.transform);
size_t h1 = hash<hydra::Vector4>()(s.axis_x);
size_t h2 = hash<hydra::Vector4>()(s.axis_y);
size_t h3 = hash<hydra::Vector4>()(s.axis_z);
size_t h4 = hash<hydra::Vector4>()(s.transform);
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
}
};
} // namespace std
#endif // KRAKEN_MATRIX4_H

View File

@@ -29,12 +29,11 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAKEN_QUATERNION_H
#define KRAKEN_QUATERNION_H
#pragma once
#include "vector3.h"
namespace kraken {
namespace hydra {
class Quaternion
{
@@ -99,16 +98,16 @@ public:
static Quaternion Slerp(const Quaternion& a, const Quaternion& b, float t);
static float Dot(const Quaternion& v1, const Quaternion& v2);
};
static_assert(std::is_pod<Quaternion>::value, "kraken::Quaternion must be a POD type.");
static_assert(std::is_pod<Quaternion>::value, "hydra::Quaternion must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Quaternion>
struct hash<hydra::Quaternion>
{
public:
size_t operator()(const kraken::Quaternion& s) const
size_t operator()(const hydra::Quaternion& s) const
{
size_t h1 = hash<float>()(s.c[0]);
size_t h2 = hash<float>()(s.c[1]);
@@ -118,5 +117,3 @@ public:
}
};
} // namespace std
#endif // KRAKEN_QUATERNION_H

View File

@@ -29,14 +29,12 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAKEN_SCALAR_H
#define KRAKEN_SCALAR_H
#pragma once
namespace kraken {
namespace hydra {
float SmoothStep(float a, float b, float t);
float Lerp(float a, float b, float t);
}; // namespace kraken
}; // namespace hydra
#endif // KRAKEN_SCALAR_H

View File

@@ -29,12 +29,11 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAKEN_TRIANGLE3_H
#define KRAKEN_TRIANGLE3_H
#pragma once
#include "vector3.h"
namespace kraken {
namespace hydra {
class Triangle3
{
@@ -59,23 +58,21 @@ public:
bool containsPoint(const Vector3& p) const;
Vector3 closestPointOnTriangle(const Vector3& p) const;
};
static_assert(std::is_pod<Triangle3>::value, "kraken::Triangle3 must be a POD type.");
static_assert(std::is_pod<Triangle3>::value, "hydra::Triangle3 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Triangle3>
struct hash<hydra::Triangle3>
{
public:
size_t operator()(const kraken::Triangle3& s) const
size_t operator()(const hydra::Triangle3& s) const
{
size_t h1 = hash<kraken::Vector3>()(s.vert[0]);
size_t h2 = hash<kraken::Vector3>()(s.vert[1]);
size_t h3 = hash<kraken::Vector3>()(s.vert[2]);
size_t h1 = hash<hydra::Vector3>()(s.vert[0]);
size_t h2 = hash<hydra::Vector3>()(s.vert[1]);
size_t h3 = hash<hydra::Vector3>()(s.vert[2]);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};
} // namespace std
#endif // KRAKEN_TRIANGLE3_H

View File

@@ -29,14 +29,13 @@
// or implied, of Kearwood Gilbert.
//
#ifndef KRAKEN_VECTOR2_H
#define KRAKEN_VECTOR2_H
#pragma once
#include <functional> // for hash<>
#include <limits> // for std::numeric_limits<>
#include <math.h> // for sqrtf
namespace kraken {
namespace hydra {
class Vector2
{
@@ -105,16 +104,16 @@ public:
static Vector2 Zero();
static Vector2 One();
};
static_assert(std::is_pod<Vector2>::value, "kraken::Vector2 must be a POD type.");
static_assert(std::is_pod<Vector2>::value, "hydra::Vector2 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Vector2>
struct hash<hydra::Vector2>
{
public:
size_t operator()(const kraken::Vector2& s) const
size_t operator()(const hydra::Vector2& s) const
{
size_t h1 = hash<float>()(s.x);
size_t h2 = hash<float>()(s.y);
@@ -122,5 +121,3 @@ public:
}
};
} // namespace std
#endif // KRAKEN_VECTOR2_H

View File

@@ -35,7 +35,7 @@
#include <limits> // for std::numeric_limits<>
#include <math.h> // for sqrtf
namespace kraken {
namespace hydra {
class Vector2i
{
@@ -105,16 +105,16 @@ public:
static Vector2i Zero();
static Vector2i One();
}; // class Vector2i
static_assert(std::is_pod<Vector2i>::value, "kraken::Vector2i must be a POD type.");
static_assert(std::is_pod<Vector2i>::value, "hydra::Vector2i must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Vector2i>
struct hash<hydra::Vector2i>
{
public:
size_t operator()(const kraken::Vector2i& s) const
size_t operator()(const hydra::Vector2i& s) const
{
size_t h1 = hash<int>()(s.x);
size_t h2 = hash<int>()(s.y);

View File

@@ -36,7 +36,7 @@
#include "vector2.h"
#include "vector4.h"
namespace kraken {
namespace hydra {
class Vector3
{
@@ -136,16 +136,16 @@ public:
static Vector3 Slerp(const Vector3& v1, const Vector3& v2, float d);
static void OrthoNormalize(Vector3& normal, Vector3& tangent); // Gram-Schmidt Orthonormalization
};
static_assert(std::is_pod<Vector3>::value, "kraken::Vector3 must be a POD type.");
static_assert(std::is_pod<Vector3>::value, "hydra::Vector3 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Vector3>
struct hash<hydra::Vector3>
{
public:
size_t operator()(const kraken::Vector3& s) const
size_t operator()(const hydra::Vector3& s) const
{
size_t h1 = hash<float>()(s.x);
size_t h2 = hash<float>()(s.y);

View File

@@ -35,7 +35,7 @@
#include "vector2i.h"
namespace kraken {
namespace hydra {
class Vector3i
{
@@ -125,16 +125,16 @@ public:
static Vector3i Right();
static Vector3i Scale(const Vector3i& v1, const Vector3i& v2);
};
static_assert(std::is_pod<Vector3i>::value, "kraken::Vector3i must be a POD type.");
static_assert(std::is_pod<Vector3i>::value, "hydra::Vector3i must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Vector3i>
struct hash<hydra::Vector3i>
{
public:
size_t operator()(const kraken::Vector3i& s) const
size_t operator()(const hydra::Vector3i& s) const
{
size_t h1 = hash<int>()(s.x);
size_t h2 = hash<int>()(s.y);

View File

@@ -33,7 +33,7 @@
#include <functional> // for hash<>
namespace kraken {
namespace hydra {
class Vector3;
@@ -109,16 +109,16 @@ public:
static Vector4 Slerp(const Vector4& v1, const Vector4& v2, float d);
static void OrthoNormalize(Vector4& normal, Vector4& tangent); // Gram-Schmidt Orthonormalization
};
static_assert(std::is_pod<Vector4>::value, "kraken::Vector4 must be a POD type.");
static_assert(std::is_pod<Vector4>::value, "hydra::Vector4 must be a POD type.");
} // namespace kraken
} // namespace hydra
namespace std {
template<>
struct hash<kraken::Vector4>
struct hash<hydra::Vector4>
{
public:
size_t operator()(const kraken::Vector4& s) const
size_t operator()(const hydra::Vector4& s) const
{
size_t h1 = hash<float>()(s.x);
size_t h2 = hash<float>()(s.y);

View File

@@ -33,7 +33,7 @@
#include "assert.h"
#include "krhelpers.h"
namespace kraken {
namespace hydra {
void AABB::init()
{
@@ -371,5 +371,5 @@ Vector3 AABB::nearestPoint(const Vector3& v) const
return Vector3::Create(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z));
}
} // namespace kraken
} // namespace hydra

View File

@@ -31,7 +31,7 @@
#include "../include/hydra.h"
namespace kraken {
namespace hydra {
HitInfo::HitInfo()
{
@@ -96,5 +96,5 @@ HitInfo& HitInfo::operator =(const HitInfo& b)
return *this;
}
} // namespace kraken
} // namespace hydra

View File

@@ -33,7 +33,7 @@
#include <string.h>
namespace kraken {
namespace hydra {
void Matrix2::init()
{
@@ -216,5 +216,5 @@ Matrix2 Matrix2::Identity()
return m;
}
} // namespace kraken
} // namespace hydra

View File

@@ -33,7 +33,7 @@
#include <string.h>
namespace kraken {
namespace hydra {
void Matrix2x3::init()
{
@@ -245,5 +245,5 @@ Matrix2x3 Matrix2x3::Identity()
return m;
}
} // namespace kraken
} // namespace hydra

View File

@@ -33,7 +33,7 @@
#include <string.h>
namespace kraken {
namespace hydra {
void Matrix4::init()
{
@@ -484,5 +484,5 @@ Matrix4 Matrix4::Identity()
return m;
}
} // namespace kraken
} // namespace hydra

View File

@@ -33,7 +33,7 @@
#include "krhelpers.h"
namespace kraken {
namespace hydra {
void Quaternion::init()
{
@@ -458,4 +458,4 @@ Quaternion Quaternion::Slerp(const Quaternion& a, const Quaternion& b, float t)
return (c * sinf((1.0f - t) * halftheta) + b * sinf(t * halftheta)) / sinf(halftheta);
}
} // namespace kraken
} // namespace hydra

View File

@@ -31,7 +31,7 @@
#include "../include/hydra.h"
namespace kraken {
namespace hydra {
float SmoothStep(float a, float b, float t)
{
@@ -44,4 +44,4 @@ float Lerp(float a, float b, float t)
return (a + (b - a) * t);
}
} // namespace kraken
} // namespace hydra

View File

@@ -31,7 +31,7 @@
#include "../include/hydra.h"
using namespace kraken;
using namespace hydra;
namespace {
bool _intersectSphere(const Vector3& start, const Vector3& dir, const Vector3& sphere_center, float sphere_radius, float& distance)
@@ -96,7 +96,7 @@ Vector3 _closestPointOnLine(const Vector3& a, const Vector3& b, const Vector3& p
}
} // anonymous namespace
namespace kraken {
namespace hydra {
void Triangle3::init(const Vector3& v1, const Vector3& v2, const Vector3& v3)
{
@@ -350,4 +350,4 @@ bool Triangle3::containsPoint(const Vector3& p) const
return (r + t <= 1);
}
} // namespace kraken
} // namespace hydra

View File

@@ -32,7 +32,7 @@
#include "../include/hydra.h"
#include "krhelpers.h"
namespace kraken {
namespace hydra {
void Vector2::init()
{
@@ -299,4 +299,4 @@ Vector2 Vector2::Max(const Vector2& v1, const Vector2& v2)
return Vector2::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y));
}
} // namepsace kraken
} // namepsace hydra

View File

@@ -32,7 +32,7 @@
#include "../include/hydra.h"
#include "krhelpers.h"
namespace kraken {
namespace hydra {
void Vector2i::init()
{
@@ -293,4 +293,4 @@ Vector2i Vector2i::Max(const Vector2i& v1, const Vector2i& v2)
return Vector2i::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y));
}
} // namepsace kraken
} // namepsace hydra

View File

@@ -32,7 +32,7 @@
#include "../include/hydra.h"
#include "krhelpers.h"
namespace kraken {
namespace hydra {
//default constructor
void Vector3::init()
@@ -502,5 +502,5 @@ bool Vector3::operator <(const Vector3& b) const
}
}
} // namespace kraken
} // namespace hydra

View File

@@ -32,7 +32,7 @@
#include "../include/hydra.h"
#include "krhelpers.h"
namespace kraken {
namespace hydra {
//default constructor
void Vector3i::init()
@@ -417,4 +417,4 @@ bool Vector3i::operator <(const Vector3i& b) const
}
}
} // namespace kraken
} // namespace hydra

View File

@@ -32,7 +32,7 @@
#include "../include/hydra.h"
#include "krhelpers.h"
namespace kraken {
namespace hydra {
//default constructor
void Vector4::init()
@@ -379,4 +379,4 @@ bool Vector4::operator <(const Vector4& b) const
return false;
}
} // namespace kraken
} // namespace hydra