/s/KRAABB/AABB/g
Cleanup, new hash<> functions
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
// Axis aligned bounding box
|
||||
// Axis aligned bounding box (AABB)
|
||||
|
||||
#ifndef KRAABB_H
|
||||
#define KRAABB_H
|
||||
#ifndef KRAKEN_AABB_H
|
||||
#define KRAKEN_AABB_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
@@ -20,12 +20,15 @@ namespace kraken {
|
||||
|
||||
class Matrix4;
|
||||
|
||||
class KRAABB {
|
||||
class AABB {
|
||||
public:
|
||||
KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint);
|
||||
KRAABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix);
|
||||
KRAABB();
|
||||
~KRAABB();
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
|
||||
AABB(const Vector3 &minPoint, const Vector3 &maxPoint);
|
||||
AABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix);
|
||||
AABB();
|
||||
~AABB();
|
||||
|
||||
void scale(const Vector3 &s);
|
||||
void scale(float s);
|
||||
@@ -33,28 +36,25 @@ public:
|
||||
Vector3 center() const;
|
||||
Vector3 size() const;
|
||||
float volume() const;
|
||||
bool intersects(const KRAABB& b) const;
|
||||
bool contains(const KRAABB &b) const;
|
||||
bool intersects(const AABB& b) const;
|
||||
bool contains(const AABB &b) const;
|
||||
bool contains(const Vector3 &v) const;
|
||||
|
||||
bool intersectsLine(const Vector3 &v1, const Vector3 &v2) const;
|
||||
bool intersectsRay(const Vector3 &v1, const Vector3 &dir) const;
|
||||
bool intersectsSphere(const Vector3 ¢er, float radius) const;
|
||||
void encapsulate(const KRAABB & b);
|
||||
void encapsulate(const AABB & b);
|
||||
|
||||
KRAABB& operator =(const KRAABB& b);
|
||||
bool operator ==(const KRAABB& b) const;
|
||||
bool operator !=(const KRAABB& b) const;
|
||||
AABB& operator =(const AABB& b);
|
||||
bool operator ==(const AABB& b) const;
|
||||
bool operator !=(const AABB& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const KRAABB& b) const;
|
||||
bool operator <(const KRAABB& b) const;
|
||||
bool operator >(const AABB& b) const;
|
||||
bool operator <(const AABB& b) const;
|
||||
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
|
||||
static KRAABB Infinite();
|
||||
static KRAABB Zero();
|
||||
static AABB Infinite();
|
||||
static AABB Zero();
|
||||
|
||||
float longest_radius() const;
|
||||
Vector3 nearestPoint(const Vector3 & v) const;
|
||||
@@ -64,9 +64,9 @@ public:
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::KRAABB> {
|
||||
struct hash<kraken::AABB> {
|
||||
public:
|
||||
size_t operator()(const kraken::KRAABB &s) const
|
||||
size_t operator()(const kraken::AABB &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::Vector3>()(s.min);
|
||||
size_t h2 = hash<kraken::Vector3>()(s.max);
|
||||
@@ -76,4 +76,4 @@ namespace std {
|
||||
} // namespace std
|
||||
|
||||
|
||||
#endif /* defined(KRAABB_H) */
|
||||
#endif /* defined(KRAKEN_AABB_H) */
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "vector4.h"
|
||||
#include "matrix4.h"
|
||||
#include "quaternion.h"
|
||||
#include "KRAABB.h"
|
||||
#include "aabb.h"
|
||||
#include "triangle3.h"
|
||||
|
||||
#endif // KRAKEN_H
|
||||
|
||||
@@ -48,15 +48,21 @@ class Quaternion;
|
||||
|
||||
class Matrix4 {
|
||||
public:
|
||||
|
||||
float c[16]; // Matrix components, in column-major order
|
||||
|
||||
union {
|
||||
struct {
|
||||
Vector4 axis_x, axis_y, axis_z, transform;
|
||||
};
|
||||
// Matrix components, in column-major order
|
||||
float c[16];
|
||||
};
|
||||
|
||||
// Default constructor - Creates an identity matrix
|
||||
Matrix4();
|
||||
|
||||
Matrix4(float *pMat);
|
||||
|
||||
Matrix4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans);
|
||||
Matrix4(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform);
|
||||
|
||||
// Destructor
|
||||
~Matrix4();
|
||||
@@ -112,4 +118,19 @@ public:
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Matrix4> {
|
||||
public:
|
||||
size_t operator()(const kraken::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);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_MATRIX4_H
|
||||
|
||||
@@ -38,6 +38,13 @@ namespace kraken {
|
||||
|
||||
class Quaternion {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float w, x, y, z;
|
||||
};
|
||||
float c[4];
|
||||
};
|
||||
|
||||
Quaternion();
|
||||
Quaternion(float w, float x, float y, float z);
|
||||
Quaternion(const Quaternion& p);
|
||||
@@ -81,10 +88,23 @@ public:
|
||||
static Quaternion Lerp(const Quaternion &a, const Quaternion &b, float t);
|
||||
static Quaternion Slerp(const Quaternion &a, const Quaternion &b, float t);
|
||||
static float Dot(const Quaternion &v1, const Quaternion &v2);
|
||||
private:
|
||||
float m_val[4];
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Quaternion> {
|
||||
public:
|
||||
size_t operator()(const kraken::Quaternion &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.c[0]);
|
||||
size_t h2 = hash<float>()(s.c[1]);
|
||||
size_t h3 = hash<float>()(s.c[2]);
|
||||
size_t h4 = hash<float>()(s.c[3]);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_QUATERNION_H
|
||||
|
||||
Reference in New Issue
Block a user