Daniele Bartolini преди 10 години
родител
ревизия
65558cf48f
променени са 4 файла, в които са добавени 15 реда и са изтрити 8 реда
  1. 9 2
      src/core/math/math_utils.h
  2. 1 1
      src/core/math/matrix4x4.h
  3. 1 1
      src/resource/unit_compiler.cpp
  4. 4 4
      src/world/debug_line.cpp

+ 9 - 2
src/core/math/math_utils.h

@@ -17,6 +17,7 @@ const f32 PI_TWO        = PI * 2.0f;
 const f32 PI_HALF       = PI * 0.5f;
 const f32 FLOAT_EPSILON = 1.0e-7f;
 
+/// Returns whether @a a and @a b are equal according to @a epsilon.
 inline bool fequal(f32 a, f32 b, f32 epsilon = FLOAT_EPSILON)
 {
 	return b <= (a + epsilon)
@@ -24,32 +25,38 @@ inline bool fequal(f32 a, f32 b, f32 epsilon = FLOAT_EPSILON)
 		;
 }
 
+/// Returns the minimum of @a a and @a b.
 inline f32 fmin(f32 a, f32 b)
 {
 	return a < b ? a : b;
 }
 
+/// Returns the maximum of @a a and @a b.
 inline f32 fmax(f32 a, f32 b)
 {
 	return a < b ? b : a;
 }
 
+/// Clamps @a val to @a min and @a max.
 inline f32 fclamp(f32 min, f32 max, f32 val)
 {
 	return fmin(fmax(min, val), max);
 }
 
+/// Returns the fractional part of @a a.
 inline f32 ffract(f32 a)
 {
 	return a - floorf(a);
 }
 
-inline f32 to_rad(f32 deg)
+/// Returns @a deg in radians.
+inline f32 frad(f32 deg)
 {
 	return deg * PI / 180.0f;
 }
 
-inline f32 to_deg(f32 rad)
+/// Returns @a rad in degrees.
+inline f32 fdeg(f32 rad)
 {
 	return rad * 180.0f / PI;
 }

+ 1 - 1
src/core/math/matrix4x4.h

@@ -263,7 +263,7 @@ inline Matrix4x4 operator*(Matrix4x4 a, const Matrix4x4& b)
 /// Sets the matrix @a m to perspective.
 inline void perspective(Matrix4x4& m, f32 fovy, f32 aspect, f32 near, f32 far)
 {
-	const f32 height = 1.0f / tanf(to_rad(fovy) * 0.5f);
+	const f32 height = 1.0f / tanf(frad(fovy) * 0.5f);
 	const f32 width = height * 1.0f / aspect;
 	const f32 aa = far / (far - near);
 	const f32 bb = -near * aa;

+ 1 - 1
src/resource/unit_compiler.cpp

@@ -167,7 +167,7 @@ static Buffer compile_light(const char* json, CompileOptions& opts)
 	ld.color      = sjson::parse_vector3(obj["color"]);
 
 	// FIXME: remove conversion to radians
-	ld.spot_angle = to_rad(ld.spot_angle);
+	ld.spot_angle = frad(ld.spot_angle);
 
 	Buffer buf(default_allocator());
 	array::push(buf, (char*)&ld, sizeof(ld));

+ 4 - 4
src/world/debug_line.cpp

@@ -67,8 +67,8 @@ void DebugLine::add_circle(const Vector3& center, f32 radius, const Vector3& nor
 	f32 deg0 = 0.0f;
 	for (u32 ss = 0; ss < segments; ++ss, deg0 += incr)
 	{
-		const f32 rad0 = to_rad(deg0);
-		const f32 rad1 = to_rad(deg0 + incr);
+		const f32 rad0 = frad(deg0);
+		const f32 rad1 = frad(deg0 + incr);
 
 		const Vector3 from0 = right*cos(-rad0) + cross(dir, right)*sin(-rad0) + dir*dot(dir, right)*(1.0f-cos(-rad0));
 		const Vector3 from1 = right*cos(-rad1) + cross(dir, right)*sin(-rad1) + dir*dot(dir, right)*(1.0f-cos(-rad1));
@@ -94,8 +94,8 @@ void DebugLine::add_cone(const Vector3& from, const Vector3& to, f32 radius, con
 	f32 deg0 = 0.0f;
 	for (u32 ss = 0; ss < segments; ++ss, deg0 += incr)
 	{
-		const f32 rad0 = to_rad(deg0);
-		const f32 rad1 = to_rad(deg0 + incr);
+		const f32 rad0 = frad(deg0);
+		const f32 rad1 = frad(deg0 + incr);
 
 		const Vector3 from0 = right*cos(-rad0) + cross(dir, right)*sin(-rad0) + dir*dot(dir, right)*(1.0f-cos(-rad0));
 		const Vector3 from1 = right*cos(-rad1) + cross(dir, right)*sin(-rad1) + dir*dot(dir, right)*(1.0f-cos(-rad1));