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

View File

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

View File

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