mirror of https://github.com/AxioDL/zeus.git
Various fixes and implementations
This commit is contained in:
parent
7af2c491da
commit
ac98ebf428
|
@ -47,7 +47,7 @@ add_library(zeus
|
|||
include/zeus/CFrustum.hpp
|
||||
include/zeus/CAABox.hpp
|
||||
include/zeus/COBBox.hpp
|
||||
include/zeus/CLine.hpp
|
||||
include/zeus/CLineSeg.hpp
|
||||
include/zeus/CSphere.hpp
|
||||
include/zeus/CUnitVector.hpp
|
||||
include/zeus/CMRay.hpp)
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
#define CAABOX_HPP
|
||||
|
||||
#include "zeus/CVector3f.hpp"
|
||||
#include "CUnitVector.hpp"
|
||||
#include "zeus/CTransform.hpp"
|
||||
#include "zeus/CPlane.hpp"
|
||||
#include "CLine.hpp"
|
||||
#include "CSphere.hpp"
|
||||
#include "zeus/CLineSeg.hpp"
|
||||
#include "zeus/CSphere.hpp"
|
||||
#include "zeus/Math.hpp"
|
||||
#if ZE_ATHENA_TYPES
|
||||
#include <athena/IStreamReader.hpp>
|
||||
|
@ -155,49 +154,49 @@ public:
|
|||
|
||||
CVector3f volume() const {return (m_max - m_min) * 0.5f;}
|
||||
|
||||
inline CLine getEdge(EBoxEdgeId id)
|
||||
inline CLineSeg getEdge(EBoxEdgeId id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case EBoxEdgeId::UnknownEdge0:
|
||||
return CLine({m_min.x, m_min.y, m_min.z},
|
||||
CUnitVector3f({m_min.x, m_min.y, m_max.z}));
|
||||
return CLineSeg({m_min.x, m_min.y, m_min.z},
|
||||
{m_min.x, m_min.y, m_max.z});
|
||||
case EBoxEdgeId::UnknownEdge1:
|
||||
return CLine({m_max.x, m_min.y, m_min.z},
|
||||
CUnitVector3f({m_min.x, m_min.y, m_min.z}));
|
||||
return CLineSeg({m_max.x, m_min.y, m_min.z},
|
||||
{m_min.x, m_min.y, m_min.z});
|
||||
case EBoxEdgeId::UnknownEdge2:
|
||||
return CLine({m_max.x, m_min.y, m_max.z},
|
||||
CUnitVector3f({m_max.x, m_min.y, m_max.z}));
|
||||
return CLineSeg({m_max.x, m_min.y, m_max.z},
|
||||
{m_max.x, m_min.y, m_max.z});
|
||||
case EBoxEdgeId::UnknownEdge3:
|
||||
return CLine({m_min.x, m_min.y, m_max.z},
|
||||
CUnitVector3f({m_max.x, m_min.y, m_max.z}));
|
||||
return CLineSeg({m_min.x, m_min.y, m_max.z},
|
||||
{m_max.x, m_min.y, m_max.z});
|
||||
case EBoxEdgeId::UnknownEdge4:
|
||||
return CLine({m_max.x, m_max.y, m_min.z},
|
||||
CUnitVector3f({m_max.x, m_max.y, m_max.z}));
|
||||
return CLineSeg({m_max.x, m_max.y, m_min.z},
|
||||
{m_max.x, m_max.y, m_max.z});
|
||||
case EBoxEdgeId::UnknownEdge5:
|
||||
return CLine({m_min.x, m_max.y, m_min.z},
|
||||
CUnitVector3f({m_max.x, m_max.y, m_min.z}));
|
||||
return CLineSeg({m_min.x, m_max.y, m_min.z},
|
||||
{m_max.x, m_max.y, m_min.z});
|
||||
case EBoxEdgeId::UnknownEdge6:
|
||||
return CLine({m_min.x, m_max.y, m_max.z},
|
||||
CUnitVector3f({m_min.x, m_max.y, m_min.z}));
|
||||
return CLineSeg({m_min.x, m_max.y, m_max.z},
|
||||
{m_min.x, m_max.y, m_min.z});
|
||||
case EBoxEdgeId::UnknownEdge7:
|
||||
return CLine({m_max.x, m_max.y, m_max.z},
|
||||
CUnitVector3f({m_min.x, m_max.y, m_max.z}));
|
||||
return CLineSeg({m_max.x, m_max.y, m_max.z},
|
||||
{m_min.x, m_max.y, m_max.z});
|
||||
case EBoxEdgeId::UnknownEdge8:
|
||||
return CLine({m_min.x, m_max.y, m_max.z},
|
||||
CUnitVector3f({m_min.x, m_min.y, m_max.z}));
|
||||
return CLineSeg({m_min.x, m_max.y, m_max.z},
|
||||
{m_min.x, m_min.y, m_max.z});
|
||||
case EBoxEdgeId::UnknownEdge9:
|
||||
return CLine({m_min.x, m_max.y, m_min.z},
|
||||
CUnitVector3f({m_min.x, m_min.y, m_min.z}));
|
||||
return CLineSeg({m_min.x, m_max.y, m_min.z},
|
||||
{m_min.x, m_min.y, m_min.z});
|
||||
case EBoxEdgeId::UnknownEdge10:
|
||||
return CLine({m_max.x, m_max.y, m_min.z},
|
||||
CUnitVector3f({m_max.x, m_min.y, m_min.z}));
|
||||
return CLineSeg({m_max.x, m_max.y, m_min.z},
|
||||
{m_max.x, m_min.y, m_min.z});
|
||||
case EBoxEdgeId::UnknownEdge11:
|
||||
return CLine({m_max.x, m_max.y, m_max.z},
|
||||
CUnitVector3f({m_max.x, m_min.y, m_max.z}));
|
||||
return CLineSeg({m_max.x, m_max.y, m_max.z},
|
||||
{m_max.x, m_min.y, m_max.z});
|
||||
default:
|
||||
return CLine({m_min.x, m_min.y, m_min.z},
|
||||
CUnitVector3f({m_min.x, m_min.y, m_max.z}));
|
||||
return CLineSeg({m_min.x, m_min.y, m_min.z},
|
||||
{m_min.x, m_min.y, m_max.z});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef CLINE_HPP
|
||||
#define CLINE_HPP
|
||||
|
||||
#include "Global.hpp"
|
||||
#include "zeus/CVector3f.hpp"
|
||||
#include "CUnitVector.hpp"
|
||||
|
||||
namespace zeus
|
||||
{
|
||||
class alignas(16) CLine
|
||||
{
|
||||
public:
|
||||
CLine(const CVector3f& a, const CUnitVector3f& b)
|
||||
{
|
||||
CVector3f ab = (b - a).normalized();
|
||||
|
||||
start = a;
|
||||
if (ab.x != 0.0f || ab.y != 0.0f || ab.z != 0.0f)
|
||||
normal = ab;
|
||||
|
||||
end = b;
|
||||
}
|
||||
|
||||
|
||||
CVector3f start;
|
||||
CVector3f normal;
|
||||
CUnitVector3f end;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef CLINE_HPP
|
||||
#define CLINE_HPP
|
||||
|
||||
#include "Global.hpp"
|
||||
#include "zeus/CVector3f.hpp"
|
||||
|
||||
namespace zeus
|
||||
{
|
||||
class CLineSeg
|
||||
{
|
||||
public:
|
||||
CLineSeg(const CVector3f& start, const CVector3f& end)
|
||||
: start(start),
|
||||
end(end)
|
||||
{
|
||||
CVector3f tmp = (end - start).normalized();
|
||||
if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
|
||||
normal = tmp.normalized();
|
||||
else
|
||||
normal = CVector3f::skZero;
|
||||
|
||||
}
|
||||
|
||||
CVector3f normal;
|
||||
CVector3f start;
|
||||
CVector3f end;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -11,6 +11,21 @@ class alignas(16) COBBox
|
|||
{
|
||||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
#if ZE_ATHENA_TYPES
|
||||
void readBig(athena::io::IStreamReader& in)
|
||||
{
|
||||
m_transform.read34RowMajor(in);
|
||||
m_extents.readBig(in);
|
||||
}
|
||||
static COBBox ReadBig(athena::io::IStreamReader& in)
|
||||
{
|
||||
COBBox out;
|
||||
out.readBig(in);
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
CTransform m_transform;
|
||||
CVector3f m_extents;
|
||||
|
||||
|
@ -23,6 +38,11 @@ public:
|
|||
m_transform.m_origin = aabb.center();
|
||||
}
|
||||
|
||||
COBBox(const CTransform& xf, const CVector3f& point)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CAABox calculateAABox(const CTransform& transform = CTransform())
|
||||
{
|
||||
CAABox ret = CAABox::skInvertedBox;
|
||||
|
@ -58,6 +78,13 @@ public:
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static COBBox FromAABox(const CAABox& box, const CTransform& xf)
|
||||
{
|
||||
const CVector3f extents = xf.toMatrix4f().transposed().vec[1].toVec3f() - box.center();
|
||||
const CTransform newXf = CTransform::Translate(box.center()) * xf;
|
||||
return COBBox(newXf, extents);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -329,20 +329,21 @@ public:
|
|||
}
|
||||
static CVector2f slerp(const CVector2f& a, const CVector2f& b, float t);
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{
|
||||
const float epsilon = 1.1920929e-7f;
|
||||
if (std::fabs(x) >= epsilon || std::fabs(y) >= epsilon)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isNormalized() const
|
||||
{ return !canBeNormalized(); }
|
||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{ return !isNormalized(); }
|
||||
|
||||
inline bool isZero() const
|
||||
{ return magSquared() <= 1.1920929e-7f; }
|
||||
|
||||
inline bool isEqu(const CVector2f& other, float epsilon=1.1920929e-7f)
|
||||
{
|
||||
const CVector2f diffVec = other - *this;
|
||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon);
|
||||
}
|
||||
|
||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
||||
|
||||
|
|
|
@ -269,6 +269,7 @@ public:
|
|||
return (x * rhs.x) + (y * rhs.y) + (z * rhs.z);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline float magSquared() const
|
||||
{
|
||||
#if __SSE__
|
||||
|
@ -287,6 +288,7 @@ public:
|
|||
return x*x + y*y + z*z;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline float magnitude() const
|
||||
{ return sqrtF(magSquared()); }
|
||||
|
||||
|
@ -316,18 +318,12 @@ public:
|
|||
static inline CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t)
|
||||
{ return lerp(a, b, t).normalized(); }
|
||||
static CVector3f slerp(const CVector3f& a, const CVector3f& b, float t);
|
||||
//static CVector3f slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle);
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{
|
||||
const float epsilon = 1.1920929e-7f;
|
||||
if (std::fabs(x) >= epsilon || std::fabs(y) >= epsilon || std::fabs(z) >= epsilon)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isNormalized() const
|
||||
{ return !canBeNormalized(); }
|
||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{ return !isNormalized(); }
|
||||
|
||||
inline bool isZero() const
|
||||
{ return magSquared() <= 1.1920929e-7f; }
|
||||
|
@ -355,7 +351,7 @@ public:
|
|||
|
||||
inline bool isEqu(const CVector3f& other, float epsilon=1.1920929e-7f)
|
||||
{
|
||||
CVector3f diffVec = other - *this;
|
||||
const CVector3f diffVec = other - *this;
|
||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon);
|
||||
}
|
||||
|
||||
|
@ -409,6 +405,11 @@ static inline CVector3f operator/(float lhs, const CVector3f& rhs)
|
|||
}
|
||||
|
||||
extern const CVector3f kUpVec;
|
||||
extern const CVector3f kDownVec;
|
||||
extern const CVector3f kRightVec;
|
||||
extern const CVector3f kLeftVec;
|
||||
extern const CVector3f kForwardVec;
|
||||
extern const CVector3f kBackVec;
|
||||
extern const CVector3f kRadToDegVec;
|
||||
extern const CVector3f kDegToRadVec;
|
||||
inline CVector3f radToDeg(const CVector3f& rad) {return rad * kRadToDegVec;}
|
||||
|
|
|
@ -357,16 +357,17 @@ public:
|
|||
return lerp(a, b, t).normalized();
|
||||
}
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{
|
||||
const float epsilon = 1.1920929e-7f;
|
||||
if (std::fabs(x) >= epsilon || std::fabs(y) >= epsilon || std::fabs(z) >= epsilon || std::fabs(w) >= epsilon)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isNormalized() const
|
||||
{ return !canBeNormalized(); }
|
||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{ return !isNormalized(); }
|
||||
|
||||
inline bool isEqu(const CVector4f& other, float epsilon=1.1920929e-7f)
|
||||
{
|
||||
const CVector4f diffVec = other - *this;
|
||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon && diffVec.w <= epsilon);
|
||||
}
|
||||
|
||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "zeus/CUnitVector.hpp"
|
||||
#include "zeus/CRectangle.hpp"
|
||||
#include "zeus/CPlane.hpp"
|
||||
#include "zeus/CLine.hpp"
|
||||
#include "zeus/CLineSeg.hpp"
|
||||
#include "zeus/CAABox.hpp"
|
||||
#include "zeus/COBBox.hpp"
|
||||
#include "zeus/CSphere.hpp"
|
||||
|
|
|
@ -6,11 +6,16 @@
|
|||
|
||||
namespace zeus
|
||||
{
|
||||
const CVector3f CVector3f::skOne = CVector3f(1.0);
|
||||
const CVector3f CVector3f::skNegOne = CVector3f(-1.0);
|
||||
const CVector3f CVector3f::skOne = CVector3f(1.f);
|
||||
const CVector3f CVector3f::skNegOne = CVector3f(-1.f);
|
||||
const CVector3f CVector3f::skZero;
|
||||
|
||||
const CVector3f kUpVec(0.0, 0.0, 1.0);
|
||||
const CVector3f kUpVec(0.f, 0.f, 1.f);
|
||||
const CVector3f kDownVec(0.f, 0.f, -1.f);
|
||||
const CVector3f kForwardVec(0.f, 1.f, 0.f);
|
||||
const CVector3f kBackVec(0.f, -1.f, 0.f);
|
||||
const CVector3f kRightVec(1.f, 0.f, 0.f);
|
||||
const CVector3f kLeftVector(-1.f, 0.f, 0.f);
|
||||
const CVector3f kRadToDegVec(180.0f / M_PIF);
|
||||
const CVector3f kDegToRadVec(M_PIF / 180.0f);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ int main()
|
|||
zeus::detectCPU();
|
||||
assert(!CAABox({100, 100, 100}, {100, 100, 100}).invalid());
|
||||
assert(CAABox().invalid());
|
||||
CVector3f vec{320, 632162.f, 800.f};
|
||||
CVector3f vec{320.f, 1.f, 0.66568f};
|
||||
assert(vec.canBeNormalized());
|
||||
assert(!vec.isZero());
|
||||
assert(CVector3f().isZero());
|
||||
|
@ -55,7 +55,7 @@ int main()
|
|||
std::cout << " Test 1 " << ( aabb.intersects(s1) ? "succeeded" : "failed" ) << std::endl;
|
||||
std::cout << " Test 2 " << ( aabb.intersects(s2) ? "succeeded" : "failed" ) << std::endl;
|
||||
std::cout << " Test 3 " << ( aabb.intersects(s3) ? "succeeded" : "failed" ) << std::endl;
|
||||
CLine line({-89.120926f, 59.328712f, 3.265882f}, CUnitVector3f({-90.120926f, 59.328712f, 3.265882f}));
|
||||
CLineSeg line({-89.120926f, 59.328712f, 3.265882f}, {-90.120926f, 59.328712f, 3.265882f});
|
||||
|
||||
CColor ctest1;
|
||||
ctest1.fromHSV(0, 255/255.f, .5);
|
||||
|
|
Loading…
Reference in New Issue