2015-04-19 20:39:16 +00:00
|
|
|
#ifndef CPLANE_HPP
|
|
|
|
#define CPLANE_HPP
|
|
|
|
|
|
|
|
#include "Global.hpp"
|
|
|
|
#include "CVector3f.hpp"
|
2015-10-08 00:21:38 +00:00
|
|
|
#include "Math.hpp"
|
2015-04-19 20:39:16 +00:00
|
|
|
|
2015-10-08 00:21:38 +00:00
|
|
|
namespace Zeus
|
|
|
|
{
|
2015-04-19 20:39:16 +00:00
|
|
|
class ZE_ALIGN(16) CPlane
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
|
|
|
|
2015-04-19 23:15:32 +00:00
|
|
|
inline CPlane() {}
|
2015-04-19 20:39:16 +00:00
|
|
|
CPlane(float a, float b, float c, float d) : a(a), b(b), c(c), d(d) {}
|
2015-08-25 22:04:15 +00:00
|
|
|
CPlane(const CVector3f& a, const CVector3f& b, const CVector3f& c)
|
|
|
|
{
|
|
|
|
CVector3f ab = b - a;
|
|
|
|
CVector3f ac = c - a;
|
|
|
|
vec = ab.cross(ac).normalized();
|
|
|
|
d = -a.dot(vec);
|
|
|
|
}
|
|
|
|
|
2015-04-19 20:39:16 +00:00
|
|
|
CPlane(const CVector3f& point, float displacement)
|
|
|
|
{
|
|
|
|
#if __SSE__
|
|
|
|
mVec128 = point.mVec128;
|
|
|
|
#else
|
|
|
|
a = point[0]; b = point[1]; c = point[2];
|
|
|
|
#endif
|
|
|
|
d = displacement;
|
|
|
|
}
|
2015-10-08 00:21:38 +00:00
|
|
|
|
|
|
|
float clipLineSegment(const CVector3f& a, const CVector3f& b)
|
|
|
|
{
|
|
|
|
float mag = ((b.z - a.z) * (((b.x - a.x) * ((b.y - a.y) * vec.y)) + vec.x)) + vec.z;
|
|
|
|
float dis = (-(vec.y - d)) / mag;
|
|
|
|
return Math::clamp(0.0f, dis, 1.0f);
|
|
|
|
}
|
2015-04-19 20:39:16 +00:00
|
|
|
|
2015-04-19 23:15:32 +00:00
|
|
|
inline void normalize()
|
|
|
|
{
|
|
|
|
float nd = d;
|
2015-10-08 00:21:38 +00:00
|
|
|
float mag = vec.magnitude();
|
2015-04-19 23:15:32 +00:00
|
|
|
assert(mag != 0.0f);
|
|
|
|
mag = 1.0 / mag;
|
|
|
|
vec *= mag;
|
|
|
|
d = nd * mag;
|
|
|
|
}
|
|
|
|
|
2015-04-19 20:39:16 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
float a, b, c, d;
|
|
|
|
};
|
|
|
|
float p[4];
|
2015-04-19 23:15:32 +00:00
|
|
|
CVector3f vec;
|
2015-04-19 20:39:16 +00:00
|
|
|
#ifdef __SSE__
|
|
|
|
__m128 mVec128;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
};
|
2015-10-08 00:21:38 +00:00
|
|
|
}
|
2015-04-19 20:39:16 +00:00
|
|
|
|
|
|
|
#endif // CPLANE_HPP
|