Various fixes

This commit is contained in:
Jack Andersen 2017-12-17 13:05:05 -10:00
parent b438e30060
commit f5f38ac827
3 changed files with 51 additions and 76 deletions

View File

@ -20,18 +20,18 @@ public:
enum class EBoxEdgeId enum class EBoxEdgeId
{ {
UnknownEdge0, Z0,
UnknownEdge1, X0,
UnknownEdge2, Z1,
UnknownEdge3, X1,
UnknownEdge4, Z2,
UnknownEdge5, X2,
UnknownEdge6, Z3,
UnknownEdge7, X3,
UnknownEdge8, Y0,
UnknownEdge9, Y1,
UnknownEdge10, Y2,
UnknownEdge11 Y3
}; };
enum class EBoxFaceID enum class EBoxFaceID
@ -154,44 +154,23 @@ public:
inline bool insidePlane(const CPlane& plane) const inline bool insidePlane(const CPlane& plane) const
{ {
CVector3f vmin, vmax; CVector3f vmax;
/* X axis */ /* X axis */
if (plane.a >= 0) if (plane.a >= 0)
{
vmin[0] = min[0];
vmax[0] = max[0]; vmax[0] = max[0];
}
else else
{
vmin[0] = max[0];
vmax[0] = min[0]; vmax[0] = min[0];
}
/* Y axis */ /* Y axis */
if (plane.b >= 0) if (plane.b >= 0)
{
vmin[1] = min[1];
vmax[1] = max[1]; vmax[1] = max[1];
}
else else
{
vmin[1] = max[1];
vmax[1] = min[1]; vmax[1] = min[1];
}
/* Z axis */ /* Z axis */
if (plane.c >= 0) if (plane.c >= 0)
{
vmin[2] = min[2];
vmax[2] = max[2]; vmax[2] = max[2];
}
else else
{
vmin[2] = max[2];
vmax[2] = min[2]; vmax[2] = min[2];
} return plane.vec.dot(vmax) + plane.d >= 0.f;
float dadot = plane.vec.dot(vmax);
if (dadot + plane.d < 0)
return false;
return true;
} }
CVector3f center() const { return (min + max) * 0.5f; } CVector3f center() const { return (min + max) * 0.5f; }
@ -204,32 +183,30 @@ public:
{ {
switch (id) switch (id)
{ {
case EBoxEdgeId::UnknownEdge0: case EBoxEdgeId::Z0:
return CLineSeg({min.x, min.y, min.z}, {min.x, min.y, max.z}); return CLineSeg({min.x, min.y, max.z}, {min.x, min.y, min.z});
case EBoxEdgeId::UnknownEdge1: case EBoxEdgeId::X0:
return CLineSeg({max.x, min.y, min.z}, {min.x, min.y, min.z}); return CLineSeg({min.x, min.y, min.z}, {max.x, min.y, min.z});
case EBoxEdgeId::UnknownEdge2: case EBoxEdgeId::Z1:
return CLineSeg({max.x, min.y, max.z}, {max.x, min.y, max.z}); return CLineSeg({max.x, min.y, min.z}, {max.x, min.y, max.z});
case EBoxEdgeId::UnknownEdge3: case EBoxEdgeId::X1:
return CLineSeg({min.x, min.y, max.z}, {max.x, min.y, max.z}); return CLineSeg({max.x, min.y, max.z}, {min.x, min.y, max.z});
case EBoxEdgeId::UnknownEdge4: case EBoxEdgeId::Z2:
return CLineSeg({max.x, max.y, min.z}, {max.x, max.y, max.z}); return CLineSeg({max.x, max.y, max.z}, {max.x, max.y, min.z});
case EBoxEdgeId::UnknownEdge5: case EBoxEdgeId::X2:
return CLineSeg({min.x, max.y, min.z}, {max.x, max.y, min.z}); return CLineSeg({max.x, max.y, min.z}, {min.x, max.y, min.z});
case EBoxEdgeId::UnknownEdge6: case EBoxEdgeId::Z3:
return CLineSeg({min.x, max.y, max.z}, {min.x, max.y, min.z}); return CLineSeg({min.x, max.y, min.z}, {min.x, max.y, max.z});
case EBoxEdgeId::UnknownEdge7: case EBoxEdgeId::X3:
return CLineSeg({max.x, max.y, max.z}, {min.x, max.y, max.z}); return CLineSeg({min.x, max.y, max.z}, {max.x, max.y, max.z});
case EBoxEdgeId::UnknownEdge8: case EBoxEdgeId::Y0:
return CLineSeg({min.x, max.y, max.z}, {min.x, min.y, max.z}); return CLineSeg({min.x, min.y, max.z}, {min.x, max.y, max.z});
case EBoxEdgeId::UnknownEdge9: case EBoxEdgeId::Y1:
return CLineSeg({min.x, max.y, min.z}, {min.x, min.y, min.z}); return CLineSeg({min.x, min.y, min.z}, {min.x, max.y, min.z});
case EBoxEdgeId::UnknownEdge10: case EBoxEdgeId::Y2:
return CLineSeg({max.x, max.y, min.z}, {max.x, min.y, min.z}); return CLineSeg({max.x, min.y, min.z}, {max.x, max.y, min.z});
case EBoxEdgeId::UnknownEdge11: case EBoxEdgeId::Y3:
return CLineSeg({max.x, max.y, max.z}, {max.x, min.y, max.z}); return CLineSeg({max.x, min.y, max.z}, {max.x, max.y, max.z});
default:
return CLineSeg({min.x, min.y, min.z}, {min.x, min.y, max.z});
} }
} }

View File

@ -9,18 +9,18 @@ namespace zeus
class CLineSeg class CLineSeg
{ {
public: public:
CLineSeg(const CVector3f& start, const CVector3f& end) : start(start), end(end) CLineSeg(const CVector3f& start, const CVector3f& end) : x0_start(start), x18_end(end)
{ {
CVector3f tmp = (end - start).normalized(); CVector3f tmp = (end - start).normalized();
if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0) if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
dir = tmp.normalized(); xc_dir = tmp.normalized();
else else
dir = CVector3f::skZero; xc_dir = CVector3f::skZero;
} }
CVector3f dir; CVector3f x0_start;
CVector3f start; CVector3f xc_dir;
CVector3f end; CVector3f x18_end;
}; };
} }

View File

@ -119,7 +119,7 @@ public:
CVector3d asNormalized() CVector3d asNormalized()
{ {
double mag = magnitude(); double mag = magnitude();
mag /= 1.0; mag = 1.0 / mag;
return {x * mag, y * mag, z * mag}; return {x * mag, y * mag, z * mag};
} }
@ -148,8 +148,6 @@ public:
const __m128d tmpVec128[2] = {_mm_add_pd(mVec128[0], rhs.mVec128[0]), const __m128d tmpVec128[2] = {_mm_add_pd(mVec128[0], rhs.mVec128[0]),
_mm_add_pd(mVec128[1], rhs.mVec128[1])}; _mm_add_pd(mVec128[1], rhs.mVec128[1])};
return CVector3d(tmpVec128); return CVector3d(tmpVec128);
#elif __GEKKO_PS__
return CVector3d(__mm_gekko_add_pd(mVec128, rhs.mVec128));
#else #else
return CVector3d(x + rhs.x, y + rhs.y, z + rhs.z); return CVector3d(x + rhs.x, y + rhs.y, z + rhs.z);
#endif #endif
@ -157,8 +155,8 @@ public:
inline CVector3d operator-(const CVector3d& rhs) const inline CVector3d operator-(const CVector3d& rhs) const
{ {
#if __SSE__ #if __SSE__
const __m128d tmpVec128[2] = {_mm_add_pd(mVec128[0], rhs.mVec128[0]), const __m128d tmpVec128[2] = {_mm_sub_pd(mVec128[0], rhs.mVec128[0]),
_mm_add_pd(mVec128[1], rhs.mVec128[1])}; _mm_sub_pd(mVec128[1], rhs.mVec128[1])};
return CVector3d(tmpVec128); return CVector3d(tmpVec128);
#else #else
return CVector3d(x - rhs.x, y - rhs.y, z - rhs.z); return CVector3d(x - rhs.x, y - rhs.y, z - rhs.z);
@ -167,8 +165,8 @@ public:
inline CVector3d operator*(const CVector3d& rhs) const inline CVector3d operator*(const CVector3d& rhs) const
{ {
#if __SSE__ #if __SSE__
const __m128d tmpVec128[2] = {_mm_add_pd(mVec128[0], rhs.mVec128[0]), const __m128d tmpVec128[2] = {_mm_mul_pd(mVec128[0], rhs.mVec128[0]),
_mm_add_pd(mVec128[1], rhs.mVec128[1])}; _mm_mul_pd(mVec128[1], rhs.mVec128[1])};
return CVector3d(tmpVec128); return CVector3d(tmpVec128);
#else #else
return CVector3d(x * rhs.x, y * rhs.y, z * rhs.z); return CVector3d(x * rhs.x, y * rhs.y, z * rhs.z);
@ -177,8 +175,8 @@ public:
inline CVector3d operator/(const CVector3d& rhs) const inline CVector3d operator/(const CVector3d& rhs) const
{ {
#if __SSE__ #if __SSE__
const __m128d tmpVec128[2] = {_mm_add_pd(mVec128[0], rhs.mVec128[0]), const __m128d tmpVec128[2] = {_mm_div_pd(mVec128[0], rhs.mVec128[0]),
_mm_add_pd(mVec128[1], rhs.mVec128[1])}; _mm_div_pd(mVec128[1], rhs.mVec128[1])};
return CVector3d(tmpVec128); return CVector3d(tmpVec128);
#else #else
return CVector3d(x / rhs.x, y / rhs.y, z / rhs.z); return CVector3d(x / rhs.x, y / rhs.y, z / rhs.z);