Daniele Bartolini 11 anos atrás
pai
commit
a712f04b1b

+ 4 - 86
engine/core/math/math_utils.h

@@ -65,20 +65,6 @@ inline T min(const T& a, const T& b)
 	return a < b ? a : b;
 }
 
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T min(const T& a, const T& b, const T& c)
-{
-	return math::min(math::min(a, b), math::min(a, c));
-}
-
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T min(const T& a, const T& b, const T& c, const T& d)
-{
-	return math::min(math::min(a, b, c), math::min(a, b, d), math::min(a, c, d));
-}
-
 //-----------------------------------------------------------------------------
 template <typename T>
 inline T max(const T& a, const T& b)
@@ -88,56 +74,10 @@ inline T max(const T& a, const T& b)
 
 //-----------------------------------------------------------------------------
 template <typename T>
-inline T max(const T& a, const T& b, const T& c)
-{
-	return math::max(math::max(a, b), math::max(a, c));
-}
-
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T max(const T& a, const T& b, const T& c, const T& d)
-{
-	return math::max(math::max(a, b, c), math::max(a, b, d), math::max(a, c, d));
-}
-
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T avg(const T& a, const T& b)
-{
-	return (a + b) * 0.5;
-}
-
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T avg(const T& a, const T& b, const T& c)
-{
-	return (a + b + c) * float(1.0 / 3.0);
-}
-
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T avg(const T& a, const T& b, const T& c, const T& d)
-{
-	return (a + b + c + d) * float(1.0 / 4.0);
-}
-
-//-----------------------------------------------------------------------------
-template <typename T>
-inline T clamp_to_range(const T& min, const T& max, const T& value)
+inline T clamp(const T& min, const T& max, const T& val)
 {
 	CE_ASSERT(min < max, "Min must be < max");
-
-	if (value > max)
-	{
-		return max;
-	}
-
-	if (value < min)
-	{
-		return min;
-	}
-
-	return value;
+	return val > max ? max : val < min ? min : val;
 }
 
 //-----------------------------------------------------------------------------
@@ -150,13 +90,13 @@ inline void swap(T& a, T& b)
 }
 
 //-----------------------------------------------------------------------------
-inline float deg_to_rad(float deg)
+inline float to_rad(float deg)
 {
 	return deg * float(PI / 180.0);
 }
 
 //-----------------------------------------------------------------------------
-inline float rad_to_deg(float rad)
+inline float to_deg(float rad)
 {
 	return rad * float(180.0 / PI);
 }
@@ -253,28 +193,6 @@ inline float fmod(float n, float d)
 	return ::fmod(n, d);
 }
 
-//-----------------------------------------------------------------------------
-inline bool solve_quadratic_equation(float a, float b, float c, float& x1, float& x2)
-{
-	float delta = (b * b) - (4.0f * a * c);
-
-	// If the equation has no float solutions
-	if (delta < 0.0)
-	{
-		return false;
-	}
-
-	x1 = (-b + sqrt(delta)) / (2.0f * a);
-	x2 = (-b - sqrt(delta)) / (2.0f * a);
-
-	if (x2 > x1)
-	{
-		swap(x1, x2);
-	}
-
-	return true;
-}
-
 /// Returns the linear interpolated value between @a p0 and @a p1 at time @a t
 template <typename T>
 inline T linear(const T& p0, const T& p1, float t)

+ 6 - 6
engine/lua/lua_math.cpp

@@ -32,18 +32,18 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-static int math_deg_to_rad(lua_State* L)
+static int math_to_rad(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::deg_to_rad(stack.get_float(1)));
+	stack.push_float(math::to_rad(stack.get_float(1)));
 	return 1;
 }
 
 //-----------------------------------------------------------------------------
-static int math_rad_to_deg(lua_State* L)
+static int math_to_deg(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::rad_to_deg(stack.get_float(1)));
+	stack.push_float(math::to_deg(stack.get_float(1)));
 	return 1;
 }
 
@@ -162,8 +162,8 @@ static int math_fmod(lua_State* L)
 //-----------------------------------------------------------------------------
 void load_math(LuaEnvironment& env)
 {
-	env.load_module_function("Math", "deg_to_rad", math_deg_to_rad);
-	env.load_module_function("Math", "rad_to_deg", math_rad_to_deg);
+	env.load_module_function("Math", "to_rad",     math_to_rad);
+	env.load_module_function("Math", "to_deg",     math_to_deg);
 	env.load_module_function("Math", "next_pow_2", math_next_pow_2);
 	env.load_module_function("Math", "is_pow_2",   math_is_pow_2);
 	env.load_module_function("Math", "ceil",       math_ceil);

+ 2 - 2
engine/renderers/debug_line.cpp

@@ -177,8 +177,8 @@ void DebugLine::add_sphere(const Color4& color, const Vector3& center, const flo
 
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	{
-		const float rad0 = math::deg_to_rad((float) deg);
-		const float rad1 = math::deg_to_rad((float) deg + deg_step);
+		const float rad0 = math::to_rad((float) deg);
+		const float rad1 = math::to_rad((float) deg + deg_step);
 
 		// XZ plane
 		const Vector3 start0(math::cos(rad0) * radius, 0, -math::sin(rad0) * radius);