Added epsilon to Vector, Quaternion & Color equality compare.
Fixed slight camera stuttering when rotating in NinjaSnowWar.
This commit is contained in:
parent
8cc3b18944
commit
c928ee04f3
@ -437,7 +437,7 @@ void UpdateCamera()
|
||||
|
||||
Vector3 pos = playerNode.position;
|
||||
Quaternion dir;
|
||||
dir = dir * Quaternion(playerControls.yaw, Vector3(0, 1, 0));
|
||||
dir = dir * Quaternion(playerNode.rotation.yaw, Vector3(0, 1, 0));
|
||||
dir = dir * Quaternion(playerControls.pitch, Vector3(1, 0, 0));
|
||||
|
||||
Vector3 aimPoint = pos + Vector3(0, 100, 0);
|
||||
|
@ -502,7 +502,7 @@ static void RegisterProcessUtils(asIScriptEngine* engine)
|
||||
engine->RegisterGlobalFunction("void OpenConsoleWindow()", asFUNCTION(OpenConsoleWindow), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("String GetConsoleInput()", asFUNCTION(GetConsoleInput), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("Array<String>@ get_arguments()", asFUNCTION(GetArgumentsToArray), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("uint get_numCpuCores()", asFUNCTION(GetNumCPUCores), asCALL_CDECL); /// \todo Move somewhere else
|
||||
engine->RegisterGlobalFunction("uint get_numCpuCores()", asFUNCTION(GetNumCPUCores), asCALL_CDECL);
|
||||
}
|
||||
|
||||
static void ConstructAttributeInfo(AttributeInfo* ptr)
|
||||
|
@ -67,6 +67,7 @@ static void RegisterMathFunctions(asIScriptEngine* engine)
|
||||
engine->RegisterGlobalProperty("const float M_INFINITY", (void*)&M_INFINITY);
|
||||
engine->RegisterGlobalProperty("const float M_EPSILON", (void*)&M_EPSILON);
|
||||
|
||||
engine->RegisterGlobalFunction("bool Equals(float, float)", asFUNCTION(Equals), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("float Sin(float)", asFUNCTION(Sin), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("float Cos(float)", asFUNCTION(Cos), asCALL_CDECL);
|
||||
engine->RegisterGlobalFunction("float Tan(float)", asFUNCTION(Tan), asCALL_CDECL);
|
||||
|
@ -75,9 +75,9 @@ public:
|
||||
}
|
||||
|
||||
/// Test for equality with another color
|
||||
bool operator == (const Color& rhs) const { return ((r_ == rhs.r_) && (g_ == rhs.g_) && (b_ == rhs.b_) && (a_ == rhs.a_)); }
|
||||
bool operator == (const Color& rhs) const { return Equals(r_, rhs.r_) && Equals(g_, rhs.g_) && Equals(b_, rhs.b_) && Equals(a_, rhs.a_); }
|
||||
/// Test for inequality with another color
|
||||
bool operator != (const Color& rhs) const { return ((r_ != rhs.r_) || (g_ != rhs.g_) || (b_ != rhs.b_) || (a_ != rhs.a_)); }
|
||||
bool operator != (const Color& rhs) const { return (!Equals(r_, rhs.r_)) || (!Equals(g_, rhs.g_)) || (!Equals(b_, rhs.b_)) || (!Equals(a_, rhs.a_)); }
|
||||
/// Multiply with a scalar
|
||||
Color operator * (float rhs) const { return Color(r_ * rhs, g_ * rhs, b_ * rhs, a_ * rhs); }
|
||||
/// Add a color
|
||||
|
@ -97,6 +97,12 @@ inline float Clamp(float value, float min, float max)
|
||||
return value;
|
||||
}
|
||||
|
||||
/// Check whether two floating point values are equal within accuracy
|
||||
inline bool Equals(float lhs, float rhs)
|
||||
{
|
||||
return (lhs + M_EPSILON >= rhs) && (lhs - M_EPSILON <= rhs);
|
||||
}
|
||||
|
||||
/// Return the smaller of two integers
|
||||
inline int Min(int lhs, int rhs)
|
||||
{
|
||||
|
@ -97,9 +97,9 @@ public:
|
||||
}
|
||||
|
||||
/// Test for equality with another quaternion
|
||||
bool operator == (const Quaternion& rhs) const { return (w_ == rhs.w_) && (x_ == rhs.x_) && (y_ == rhs.y_) && (z_ == rhs.z_); }
|
||||
bool operator == (const Quaternion& rhs) const { return Equals(w_, rhs.w_) && Equals(x_, rhs.x_) && Equals(y_, rhs.y_) && Equals(z_, rhs.z_); }
|
||||
/// Test for inequality with another quaternion
|
||||
bool operator != (const Quaternion& rhs) const { return (w_ != rhs.w_) || (x_ != rhs.x_) || (y_ != rhs.y_) || (z_ != rhs.z_); }
|
||||
bool operator != (const Quaternion& rhs) const { return (!Equals(w_, rhs.w_)) || (!Equals(x_, rhs.x_)) || (!Equals(y_, rhs.y_)) || (!Equals(z_, rhs.z_)); }
|
||||
/// Multiply with a scalar
|
||||
Quaternion operator * (float rhs) const { return Quaternion(w_ * rhs, x_ * rhs, y_ * rhs, z_ * rhs); }
|
||||
/// Return negation
|
||||
|
@ -65,9 +65,9 @@ public:
|
||||
}
|
||||
|
||||
/// Test for equality with another vector
|
||||
bool operator == (const Vector2& rhs) const { return (x_ == rhs.x_) && (y_ == rhs.y_); }
|
||||
bool operator == (const Vector2& rhs) const { return Equals(x_, rhs.x_) && Equals(y_, rhs.y_); }
|
||||
/// Test for inequality with another vector
|
||||
bool operator != (const Vector2& rhs) const { return (x_ != rhs.x_) || (y_ != rhs.y_); }
|
||||
bool operator != (const Vector2& rhs) const { return (!Equals(x_, rhs.x_)) || (!Equals(y_, rhs.y_)); }
|
||||
/// Add a vector
|
||||
Vector2 operator + (const Vector2& rhs) const { return Vector2(x_ + rhs.x_, y_ + rhs.y_); }
|
||||
/// Return negation
|
||||
|
@ -77,9 +77,9 @@ public:
|
||||
}
|
||||
|
||||
/// Test for equality with another vector
|
||||
bool operator == (const Vector3& rhs) const { return (x_ == rhs.x_) && (y_ == rhs.y_) && (z_ == rhs.z_); }
|
||||
bool operator == (const Vector3& rhs) const { return Equals(x_, rhs.x_) && Equals(y_, rhs.y_) && Equals(z_, rhs.z_); }
|
||||
/// Test for inequality with another vector
|
||||
bool operator != (const Vector3& rhs) const { return (x_ != rhs.x_) || (y_ != rhs.y_) || (z_ != rhs.z_); }
|
||||
bool operator != (const Vector3& rhs) const { return (!Equals(x_, rhs.x_)) || (!Equals(y_, rhs.y_)) || (!Equals(z_, rhs.z_)); }
|
||||
/// Add a vector
|
||||
Vector3 operator + (const Vector3& rhs) const { return Vector3(x_ + rhs.x_, y_ + rhs.y_, z_ + rhs.z_); }
|
||||
/// Return negation
|
||||
|
@ -82,9 +82,9 @@ public:
|
||||
}
|
||||
|
||||
/// Test for equality with another vector
|
||||
bool operator == (const Vector4& rhs) const { return (x_ == rhs.x_) && (y_ == rhs.y_) && (z_ == rhs.z_) && (w_ == rhs.w_); }
|
||||
bool operator == (const Vector4& rhs) const { return Equals(x_, rhs.x_) && Equals(y_, rhs.y_) && Equals(z_, rhs.z_) && Equals(w_, rhs.w_); }
|
||||
/// Test for inequality with another vector
|
||||
bool operator != (const Vector4& rhs) const { return (x_ != rhs.x_) || (y_ != rhs.y_) || (z_ != rhs.z_) || (w_ != rhs.w_); }
|
||||
bool operator != (const Vector4& rhs) const { return (!Equals(x_, rhs.x_)) || (!Equals(y_, rhs.y_)) || (!Equals(z_, rhs.z_)) || (!Equals(w_, rhs.w_)); }
|
||||
/// Add a vector
|
||||
Vector4 operator + (const Vector4& rhs) const { return Vector4(x_ + rhs.x_, y_ + rhs.y_, z_ + rhs.z_, w_ + rhs.w_); }
|
||||
/// Return negation
|
||||
|
Loading…
Reference in New Issue
Block a user