ソースを参照

Remove math namespace

Daniele Bartolini 11 年 前
コミット
5bf8af7f08

+ 1 - 1
engine/console_server.cpp

@@ -333,7 +333,7 @@ void ConsoleServer::processs_filesystem(TCPSocket client, const char* msg)
 
 		// Encode data to base64
 		size_t dummy;
-		char* bytes_encoded = math::base64_encode((unsigned char*) bytes, (size_t) file_size.to_int(), &dummy);
+		char* bytes_encoded = base64_encode((unsigned char*) bytes, (size_t) file_size.to_int(), &dummy);
 
 		// Send data
 		TempAllocator4096 alloc;

+ 1 - 1
engine/core/filesystem/disk_file.cpp

@@ -107,7 +107,7 @@ bool DiskFile::copy_to(File& file, size_t size)
 	while (tot_read_bytes < size)
 	{
 		size_t read_bytes;
-		size_t expected_read_bytes = math::min(size - tot_read_bytes, chunksize);
+		size_t expected_read_bytes = min(size - tot_read_bytes, chunksize);
 
 		read_bytes = _file.read(buff, expected_read_bytes);
 

+ 1 - 1
engine/core/filesystem/network_file.cpp

@@ -96,7 +96,7 @@ void NetworkFile::read(void* buffer, size_t size)
 	// root.key("data").to_string(data_base64);
 
 	// size_t out_len = 0;
-	// unsigned char* data = math::base64_decode(data_base64.c_str(), data_base64.length(), &out_len);
+	// unsigned char* data = base64_decode(data_base64.c_str(), data_base64.length(), &out_len);
 	// memcpy(buffer, data, sizeof(unsigned char) * out_len);
 	// default_allocator().deallocate(data);
 }

+ 8 - 8
engine/core/math/frustum.h

@@ -96,14 +96,14 @@ namespace frustum
 
 		switch (index)
 		{
-			case 0: return math::plane_3_intersection(side[4], side[0], side[2], ip);
-			case 1: return math::plane_3_intersection(side[4], side[1], side[2], ip);
-			case 2: return math::plane_3_intersection(side[4], side[1], side[3], ip);
-			case 3: return math::plane_3_intersection(side[4], side[0], side[3], ip);
-			case 4: return math::plane_3_intersection(side[5], side[0], side[2], ip);
-			case 5: return math::plane_3_intersection(side[5], side[1], side[2], ip);
-			case 6: return math::plane_3_intersection(side[5], side[1], side[3], ip);
-			case 7: return math::plane_3_intersection(side[5], side[0], side[3], ip);
+			case 0: return plane_3_intersection(side[4], side[0], side[2], ip);
+			case 1: return plane_3_intersection(side[4], side[1], side[2], ip);
+			case 2: return plane_3_intersection(side[4], side[1], side[3], ip);
+			case 3: return plane_3_intersection(side[4], side[0], side[3], ip);
+			case 4: return plane_3_intersection(side[5], side[0], side[2], ip);
+			case 5: return plane_3_intersection(side[5], side[1], side[2], ip);
+			case 6: return plane_3_intersection(side[5], side[1], side[3], ip);
+			case 7: return plane_3_intersection(side[5], side[0], side[3], ip);
 			default: break;
 		}
 

+ 2 - 2
engine/core/math/intersection.cpp

@@ -61,7 +61,7 @@ namespace math
 			return -1.0f;
 		}
 
-		return b - math::sqrt(det);
+		return b - sqrt(det);
 	}
 
 	// http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/
@@ -171,7 +171,7 @@ namespace math
 
 		float den = -vector3::dot(vector3::cross(n1, n2), n3);
 
-		if (math::equals(den, (float)0.0))
+		if (equals(den, (float)0.0))
 		{
 			return false;
 		}

+ 17 - 18
engine/core/math/intersection.h

@@ -31,22 +31,21 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace math
-{
-	/// Returns the distance along ray (from, dir) to intersection point with plane @a p
-	/// or -1.0 if no intersection.
-	float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plane& p);
-
-	/// Returns the distance along ray (from, dir) to intersection point with sphere @a s
-	/// or -1.0 if no intersection.
-	float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sphere& s);
-
-	/// Returns the distance along ray (from, dir) to intersection point with @a obb
-	/// or -1.0 if no intersection.
-	float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB& obb);
-
-	bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip);
-	bool frustum_sphere_intersection(const Frustum& f, const Sphere& s);
-	bool frustum_box_intersection(const Frustum& f, const AABB& b);
-} // namespace math
+
+/// Returns the distance along ray (from, dir) to intersection point with plane @a p
+/// or -1.0 if no intersection.
+float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plane& p);
+
+/// Returns the distance along ray (from, dir) to intersection point with sphere @a s
+/// or -1.0 if no intersection.
+float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sphere& s);
+
+/// Returns the distance along ray (from, dir) to intersection point with @a obb
+/// or -1.0 if no intersection.
+float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB& obb);
+
+bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip);
+bool frustum_sphere_intersection(const Frustum& f, const Sphere& s);
+bool frustum_box_intersection(const Frustum& f, const AABB& b);
+
 } // namespace crown

+ 2 - 10
engine/core/math/math_utils.h

@@ -33,13 +33,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/// Math utilities.
-///
-/// @ingroup Math
-namespace math
-{
-
-// Constants
 const float PI = 3.1415926535897932f;
 const float TWO_PI = PI * 2.0f;
 const float HALF_PI = PI * 0.5f;
@@ -182,8 +175,8 @@ inline T linear(const T& p0, const T& p1, float t)
 template <typename T>
 inline T cosine(const T& p0, const T& p1, float t)
 {
-	float f = t * math::PI;
-	float g = (1.0 - math::cos(f)) * 0.5;
+	float f = t * PI;
+	float g = (1.0 - cos(f)) * 0.5;
 
 	return p0 + (g * (p1 - p0));
 }
@@ -231,5 +224,4 @@ inline T catmull_rom(const T& p0, const T& p1, const T& p2, const T& p3, float t
 	return tmp * 0.5;
 }
 
-} // namespace math
 } // namespace crown

+ 1 - 1
engine/core/math/matrix3x3.h

@@ -247,7 +247,7 @@ namespace matrix3x3
 			index = 3;
 		}
 
-		const float biggest = math::sqrt(max + 1.0f) * 0.5f;
+		const float biggest = sqrt(max + 1.0f) * 0.5f;
 		const float mult = 0.25f / biggest;
 
 		Quaternion tmp;

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

@@ -195,7 +195,7 @@ namespace matrix4x4
 {
 	inline void set_perspective(Matrix4x4& m, float fovy, float aspect, float near, float far)
 	{
-		const float height = 1.0f / math::tan(fovy * ((float) math::PI / 180.0f) * 0.5f);
+		const float height = 1.0f / tan(fovy * ((float) PI / 180.0f) * 0.5f);
 		const float width = height * 1.0f / aspect;
 		const float aa = far / (far - near);
 		const float bb = -near * aa;

+ 1 - 1
engine/core/math/plane.h

@@ -58,7 +58,7 @@ namespace plane
 	{
 		float len = vector3::length(p.n);
 
-		if (math::equals(len, (float) 0.0))
+		if (equals(len, (float) 0.0))
 		{
 			return p;
 		}

+ 9 - 9
engine/core/math/quaternion.h

@@ -93,7 +93,7 @@ namespace quaternion
 
 	inline float length(const Quaternion& q)
 	{
-		return math::sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
+		return sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
 	}
 
 	inline Quaternion& normalize(Quaternion& q)
@@ -118,13 +118,13 @@ namespace quaternion
 
 	inline Quaternion power(const Quaternion& q, float exp)
 	{
-		if (math::abs(q.w) < 0.9999)
+		if (abs(q.w) < 0.9999)
 		{
 			Quaternion tmp;
-			float alpha = math::acos(q.w); // alpha = theta/2
+			float alpha = acos(q.w); // alpha = theta/2
 			float new_alpha = alpha * exp;
-			tmp.w = math::cos(new_alpha);
-			float mult = math::sin(new_alpha) / math::sin(alpha);
+			tmp.w = cos(new_alpha);
+			float mult = sin(new_alpha) / sin(alpha);
 			tmp.x = q.x * mult;
 			tmp.y = q.y * mult;
 			tmp.z = q.z * mult;
@@ -149,10 +149,10 @@ inline Quaternion::Quaternion(float nx, float ny, float nz, float nw)
 }
 
 inline Quaternion::Quaternion(const Vector3& axis, float angle)
-	: x(axis.x * math::sin(angle * 0.5f))
-	, y(axis.y * math::sin(angle * 0.5f))
-	, z(axis.z * math::sin(angle * 0.5f))
-	, w(math::cos(angle * 0.5f))
+	: x(axis.x * sin(angle * 0.5f))
+	, y(axis.y * sin(angle * 0.5f))
+	, z(axis.z * sin(angle * 0.5f))
+	, w(cos(angle * 0.5f))
 {
 }
 

+ 3 - 3
engine/core/math/sphere.h

@@ -51,7 +51,7 @@ namespace sphere
 {
 	inline float volume(const Sphere& s)
 	{
-		return float(4.0 / 3.0 * math::PI) * s.r*s.r*s.r;
+		return float(4.0 / 3.0 * PI) * s.r*s.r*s.r;
 	}
 
 	inline void add_points(Sphere& s, uint32_t num, const Vector3* points)
@@ -60,7 +60,7 @@ namespace sphere
 		{
 			const float dist = vector3::squared_length(points[i] - s.c);
 			if (dist >= s.r*s.r)
-				s.r = math::sqrt(dist);
+				s.r = sqrt(dist);
 		}
 	}
 
@@ -73,7 +73,7 @@ namespace sphere
 			if (dist < (spheres[i].r + s.r) * (spheres[i].r + s.r))
 			{
 				if (spheres[i].r * spheres[i].r > s.r * s.r)
-					s.r = math::sqrt(dist + spheres[i].r * spheres[i].r);
+					s.r = sqrt(dist + spheres[i].r * spheres[i].r);
 			}
 		}
 	}

+ 3 - 3
engine/core/math/vector2.h

@@ -127,7 +127,7 @@ inline Vector2 operator/(Vector2 a, float k)
 
 inline bool operator==(const Vector2& a, const Vector2& b)
 {
-	return math::equals(a.x, b.x) && math::equals(a.y, b.y);
+	return equals(a.x, b.x) && equals(a.y, b.y);
 }
 
 namespace vector2
@@ -140,7 +140,7 @@ namespace vector2
 
 	inline float length(const Vector2& a)
 	{
-		return math::sqrt(a.x * a.x + a.y * a.y);
+		return sqrt(a.x * a.x + a.y * a.y);
 	}
 
 	inline float squared_length(const Vector2& a)
@@ -173,7 +173,7 @@ namespace vector2
 
 	inline float angle(const Vector2& a, const Vector2& b)
 	{
-		return math::acos(dot(a, b) / (length(a) * length(b)));
+		return acos(dot(a, b) / (length(a) * length(b)));
 	}
 
 	inline float* to_float_ptr(Vector2& a)

+ 3 - 3
engine/core/math/vector3.h

@@ -137,7 +137,7 @@ inline Vector3 operator/(Vector3 a, float k)
 
 inline bool operator==(const Vector3& a, const Vector3& b)
 {
-	return math::equals(a.x, b.x) && math::equals(a.y, b.y) && math::equals(a.z, b.z);
+	return equals(a.x, b.x) && equals(a.y, b.y) && equals(a.z, b.z);
 }
 
 namespace vector3
@@ -154,7 +154,7 @@ namespace vector3
 
 	inline float length(const Vector3& a)
 	{
-		return math::sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
+		return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
 	}
 
 	inline float squared_length(const Vector3& a)
@@ -189,7 +189,7 @@ namespace vector3
 
 	inline float angle(const Vector3& a, const Vector3& b)
 	{
-		return math::acos(dot(a, b) / (length(a) * length(b)));
+		return acos(dot(a, b) / (length(a) * length(b)));
 	}
 
 	inline float* to_float_ptr(Vector3& a)

+ 3 - 3
engine/core/math/vector4.h

@@ -134,7 +134,7 @@ inline Vector4 operator/(Vector4 a, float k)
 
 inline bool operator==(const Vector4& a, const Vector4& b)
 {
-	return math::equals(a.x, b.x) && math::equals(a.y, b.y) && math::equals(a.z, b.z) && math::equals(a.w, b.w);
+	return equals(a.x, b.x) && equals(a.y, b.y) && equals(a.z, b.z) && equals(a.w, b.w);
 }
 
 namespace vector4
@@ -146,7 +146,7 @@ namespace vector4
 
 	inline float length(const Vector4& a)
 	{
-		return math::sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
+		return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
 	}
 
 	inline float squared_length(const Vector4& a)
@@ -183,7 +183,7 @@ namespace vector4
 
 	inline float angle(const Vector4& a, const Vector4& b)
 	{
-		return math::acos(dot(a, b) / (length(a) * length(b)));
+		return acos(dot(a, b) / (length(a) * length(b)));
 	}
 
 	inline float* to_float_ptr(Vector4& a)

+ 2 - 2
engine/crown.cpp

@@ -188,13 +188,13 @@ void parse_config_file(Filesystem& fs, ConfigSettings& cs)
 	JSONElement window_width = root.key_or_nil("window_width");
 	if (!window_width.is_nil())
 	{
-		cs.window_width = math::max((uint16_t)1, (uint16_t)window_width.to_int());
+		cs.window_width = max((uint16_t)1, (uint16_t)window_width.to_int());
 	}
 
 	JSONElement window_height = root.key_or_nil("window_height");
 	if (!window_height.is_nil())
 	{
-		cs.window_height = math::max((uint16_t)1, (uint16_t)window_height.to_int());
+		cs.window_height = max((uint16_t)1, (uint16_t)window_height.to_int());
 	}
 
 	cs.boot_script = root.key("boot_script").to_resource_id("lua").name;

+ 17 - 17
engine/lua/lua_math.cpp

@@ -37,112 +37,112 @@ namespace crown
 static int math_to_rad(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::to_rad(stack.get_float(1)));
+	stack.push_float(to_rad(stack.get_float(1)));
 	return 1;
 }
 
 static int math_to_deg(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::to_deg(stack.get_float(1)));
+	stack.push_float(to_deg(stack.get_float(1)));
 	return 1;
 }
 
 static int math_next_pow_2(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_uint32(math::next_pow_2(stack.get_int(1)));
+	stack.push_uint32(next_pow_2(stack.get_int(1)));
 	return 1;
 }
 
 static int math_is_pow_2(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_bool(math::is_pow_2(stack.get_int(1)));
+	stack.push_bool(is_pow_2(stack.get_int(1)));
 	return 1;
 }
 
 static int math_ceil(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::ceil(stack.get_float(1)));
+	stack.push_float(ceil(stack.get_float(1)));
 	return 1;
 }
 
 static int math_floor(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::floor(stack.get_float(1)));
+	stack.push_float(floor(stack.get_float(1)));
 	return 1;
 }
 
 static int math_sqrt(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::sqrt(stack.get_float(1)));
+	stack.push_float(sqrt(stack.get_float(1)));
 	return 1;
 }
 
 static int math_inv_sqrt(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::inv_sqrt(stack.get_float(1)));
+	stack.push_float(inv_sqrt(stack.get_float(1)));
 	return 1;
 }
 
 static int math_sin(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::sin(stack.get_float(1)));
+	stack.push_float(sin(stack.get_float(1)));
 	return 1;
 }
 
 static int math_cos(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::cos(stack.get_float(1)));
+	stack.push_float(cos(stack.get_float(1)));
 	return 1;
 }
 
 static int math_asin(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::asin(stack.get_float(1)));
+	stack.push_float(asin(stack.get_float(1)));
 	return 1;
 }
 
 static int math_acos(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::acos(stack.get_float(1)));
+	stack.push_float(acos(stack.get_float(1)));
 	return 1;
 }
 
 static int math_tan(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::tan(stack.get_float(1)));
+	stack.push_float(tan(stack.get_float(1)));
 	return 1;
 }
 
 static int math_atan2(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::atan2(stack.get_float(1), stack.get_float(2)));
+	stack.push_float(atan2(stack.get_float(1), stack.get_float(2)));
 	return 1;
 }
 
 static int math_abs(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::abs(stack.get_float(1)));
+	stack.push_float(abs(stack.get_float(1)));
 	return 1;
 }
 
 static int math_fmod(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(math::fmod(stack.get_float(1), stack.get_float(2)));
+	stack.push_float(fmod(stack.get_float(1), stack.get_float(2)));
 	return 1;
 }
 
@@ -153,7 +153,7 @@ static int math_ray_oobb_intersection(lua_State* L)
 	oobb.tm = stack.get_matrix4x4(3);
 	oobb.aabb.min = stack.get_vector3(4) * -0.5;
 	oobb.aabb.max = stack.get_vector3(4) * 0.5;
-	stack.push_float(math::ray_oobb_intersection(stack.get_vector3(1), stack.get_vector3(2), oobb));
+	stack.push_float(ray_oobb_intersection(stack.get_vector3(1), stack.get_vector3(2), oobb));
 	return 1;
 }
 

+ 1 - 1
engine/physics/controller.cpp

@@ -60,7 +60,7 @@ Controller::Controller(const PhysicsResource* pr, SceneGraph& sg, int32_t node,
 	desc.nonWalkableMode = PxCCTNonWalkableMode::eFORCE_SLIDING;
 	desc.radius = contr->radius;
 	desc.height = contr->height;
-	desc.slopeLimit = math::cos(contr->slope_limit);
+	desc.slopeLimit = cos(contr->slope_limit);
 	desc.stepOffset = contr->step_offset;
 	desc.contactOffset = contr->contact_offset;
 	desc.upDirection = PxVec3(0.0, 1.0, 0.0);

+ 8 - 8
engine/renderers/debug_line.cpp

@@ -175,22 +175,22 @@ void DebugLine::add_sphere(const Vector3& center, const float radius, const Colo
 
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	{
-		const float rad0 = math::to_rad((float) deg);
-		const float rad1 = math::to_rad((float) deg + deg_step);
+		const float rad0 = to_rad((float) deg);
+		const float rad1 = to_rad((float) deg + deg_step);
 
 		// XZ plane
-		const Vector3 start0(math::cos(rad0) * radius, 0, -math::sin(rad0) * radius);
-		const Vector3 end0  (math::cos(rad1) * radius, 0, -math::sin(rad1) * radius);
+		const Vector3 start0(cos(rad0) * radius, 0, -sin(rad0) * radius);
+		const Vector3 end0  (cos(rad1) * radius, 0, -sin(rad1) * radius);
 		add_line(center + start0, center + end0, color);
 
 		// XY plane
-		const Vector3 start1(math::cos(rad0) * radius, math::sin(rad0) * radius, 0);
-		const Vector3 end1  (math::cos(rad1) * radius, math::sin(rad1) * radius, 0);
+		const Vector3 start1(cos(rad0) * radius, sin(rad0) * radius, 0);
+		const Vector3 end1  (cos(rad1) * radius, sin(rad1) * radius, 0);
 		add_line(center + start1, center + end1, color);
 
 		// YZ plane
-		const Vector3 start2(0, math::sin(rad0) * radius, -math::cos(rad0) * radius);
-		const Vector3 end2  (0, math::sin(rad1) * radius, -math::cos(rad1) * radius);
+		const Vector3 start2(0, sin(rad0) * radius, -cos(rad0) * radius);
+		const Vector3 end2  (0, sin(rad1) * radius, -cos(rad1) * radius);
 		add_line(center + start2, center + end2, color);
 	}
 }

+ 2 - 2
engine/resource/physics_resource.cpp

@@ -218,8 +218,8 @@ namespace physics_resource
 				}
 				case PhysicsJointType::SPHERICAL:
 				{
-					pj.y_limit_angle = joint.key_or_nil("y_limit_angle").to_float(math::HALF_PI);
-					pj.z_limit_angle = joint.key_or_nil("z_limit_angle").to_float(math::HALF_PI);
+					pj.y_limit_angle = joint.key_or_nil("y_limit_angle").to_float(HALF_PI);
+					pj.z_limit_angle = joint.key_or_nil("z_limit_angle").to_float(HALF_PI);
 					pj.contact_dist =  joint.key_or_nil("contact_dist").to_float(0.0f);
 					break;
 				}

+ 2 - 2
engine/resource/texture_resource.cpp

@@ -225,8 +225,8 @@ namespace texture_resource
 				return;
 			}
 
-			width = math::max(1u, width >> 1);
-			height = math::max(1u, height >> 1);
+			width = max(1u, width >> 1);
+			height = max(1u, height >> 1);
 			cur_mip++;
 			src += size;
 		}