1
0
Fork 0

Cleanup Vector3 constructors and Abs

This commit is contained in:
peterbell10 2017-08-28 12:48:02 +01:00
parent a5869b3c09
commit 3687ef397c
3 changed files with 20 additions and 39 deletions

View File

@ -2995,7 +2995,7 @@ static int tolua_cLineBlockTracer_FirstSolidHitTrace(lua_State * tolua_S)
Vector3d hitCoords;
Vector3i hitBlockCoords;
eBlockFace hitBlockFace;
auto isHit = cLineBlockTracer::FirstSolidHitTrace(*world, start, end, hitCoords, hitBlockCoords, hitBlockFace);
auto isHit = cLineBlockTracer::FirstSolidHitTrace(*world, *start, *end, hitCoords, hitBlockCoords, hitBlockFace);
L.Push(isHit);
if (!isHit)
{
@ -3093,7 +3093,7 @@ static int tolua_cLineBlockTracer_LineOfSightTrace(lua_State * tolua_S)
}
int lineOfSight = cLineBlockTracer::losAirWater;
L.GetStackValue(idx + 7, lineOfSight);
L.Push(cLineBlockTracer::LineOfSightTrace(*world, start, end, lineOfSight));
L.Push(cLineBlockTracer::LineOfSightTrace(*world, *start, *end, lineOfSight));
return 1;
}
@ -3532,7 +3532,7 @@ static int tolua_cBoundingBox_CalcLineIntersection(lua_State * a_LuaState)
bool res;
if (L.GetStackValues(2, min, max, pt1, pt2)) // Try the static signature first
{
res = cBoundingBox::CalcLineIntersection(min, max, pt1, pt2, lineCoeff, blockFace);
res = cBoundingBox::CalcLineIntersection(*min, *max, *pt1, *pt2, lineCoeff, blockFace);
}
else
{
@ -3543,7 +3543,7 @@ static int tolua_cBoundingBox_CalcLineIntersection(lua_State * a_LuaState)
tolua_error(a_LuaState, "Invalid function params. Expected either bbox:CalcLineIntersection(pt1, pt2) or cBoundingBox:CalcLineIntersection(min, max, pt1, pt2).", nullptr);
return 0;
}
res = bbox->CalcLineIntersection(pt1, pt2, lineCoeff, blockFace);
res = bbox->CalcLineIntersection(*pt1, *pt2, lineCoeff, blockFace);
}
L.Push(res);
if (res)

View File

@ -81,7 +81,7 @@ protected:
{
Vector3d Intersection = LineStart + m_Projectile->GetSpeed() * LineCoeff; // Point where projectile goes into the hit block
if (cPluginManager::Get()->CallHookProjectileHitBlock(*m_Projectile, a_BlockX, a_BlockY, a_BlockZ, Face, &Intersection))
if (cPluginManager::Get()->CallHookProjectileHitBlock(*m_Projectile, a_BlockX, a_BlockY, a_BlockZ, Face, Intersection))
{
return false;
}

View File

@ -21,18 +21,17 @@ public:
inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {}
// Hardcoded copy constructors (tolua++ does not support function templates .. yet)
Vector3(const Vector3<float> & a_Rhs) : x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
Vector3(const Vector3<double> & a_Rhs) : x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
Vector3(const Vector3<int> & a_Rhs) : x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
#if 0 // Hardcoded copy constructors (tolua++ does not support function templates .. yet)
Vector3(const Vector3<float> & a_Rhs);
Vector3(const Vector3<double> & a_Rhs);
Vector3(const Vector3<int> & a_Rhs);
#endif
// tolua_end
template <typename _T>
Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {}
template <typename _T>
Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {}
// Conversion constructors where U is not the same as T leaving the copy-constructor implicitly generated
template <typename U, typename = typename std::enable_if<!std::is_same<U, T>::value>::type>
Vector3(const Vector3<U> & a_Rhs): x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
// tolua_begin
inline void Set(T a_x, T a_y, T a_z)
@ -111,9 +110,9 @@ public:
/** Updates each coord to its absolute value */
inline void Abs()
{
x = (x < 0) ? -x : x;
y = (y < 0) ? -y : y;
z = (z < 0) ? -z : z;
x = std::abs(x);
y = std::abs(y);
z = std::abs(z);
}
/** Clamps each coord into the specified range. */
@ -152,7 +151,7 @@ public:
inline bool EqualsEps(const Vector3<T> & a_Rhs, T a_Eps) const
{
return (Abs(x - a_Rhs.x) < a_Eps) && (Abs(y - a_Rhs.y) < a_Eps) && (Abs(z - a_Rhs.z) < a_Eps);
return (std::abs(x - a_Rhs.x) < a_Eps) && (std::abs(y - a_Rhs.y) < a_Eps) && (std::abs(z - a_Rhs.z) < a_Eps);
}
inline void Move(T a_X, T a_Y, T a_Z)
@ -229,14 +228,6 @@ public:
z *= a_v;
}
inline Vector3<T> & operator = (const Vector3<T> & a_Rhs)
{
x = a_Rhs.x;
y = a_Rhs.y;
z = a_Rhs.z;
return *this;
}
// tolua_begin
inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const
@ -305,7 +296,7 @@ public:
*/
inline double LineCoeffToXYPlane(const Vector3<T> & a_OtherEnd, T a_Z) const
{
if (Abs(z - a_OtherEnd.z) < EPS)
if (std::abs(z - a_OtherEnd.z) < EPS)
{
return NO_INTERSECTION;
}
@ -320,7 +311,7 @@ public:
*/
inline double LineCoeffToXZPlane(const Vector3<T> & a_OtherEnd, T a_Y) const
{
if (Abs(y - a_OtherEnd.y) < EPS)
if (std::abs(y - a_OtherEnd.y) < EPS)
{
return NO_INTERSECTION;
}
@ -335,7 +326,7 @@ public:
*/
inline double LineCoeffToYZPlane(const Vector3<T> & a_OtherEnd, T a_X) const
{
if (Abs(x - a_OtherEnd.x) < EPS)
if (std::abs(x - a_OtherEnd.x) < EPS)
{
return NO_INTERSECTION;
}
@ -364,16 +355,6 @@ public:
/** Return value of LineCoeffToPlane() if the line is parallel to the plane. */
static const double NO_INTERSECTION;
protected:
/** Returns the absolute value of the given argument.
Templatized because the standard library differentiates between abs() and fabs(). */
static T Abs(T a_Value)
{
return (a_Value < 0) ? -a_Value : a_Value;
}
};
// tolua_end