Procházet zdrojové kódy

Add ray_disc_intersection to Lua API

Daniele Bartolini před 10 roky
rodič
revize
c349c8d668
1 změnil soubory, kde provedl 42 přidání a 11 odebrání
  1. 42 11
      src/lua/lua_math.cpp

+ 42 - 11
src/lua/lua_math.cpp

@@ -22,7 +22,24 @@ static int math_ray_plane_intersection(lua_State* L)
 	Plane p;
 	p.n = stack.get_vector3(3);
 	p.d = stack.get_float(4);
-	stack.push_float(ray_plane_intersection(stack.get_vector3(1), stack.get_vector3(2), p));
+	const float t = ray_plane_intersection(stack.get_vector3(1)
+		, stack.get_vector3(2)
+		, p
+		);
+	stack.push_float(t);
+	return 1;
+}
+
+static int math_ray_disc_intersection(lua_State* L)
+{
+	LuaStack stack(L);
+	const float t = ray_disc_intersection(stack.get_vector3(1)
+		, stack.get_vector3(2)
+		, stack.get_vector3(3)
+		, stack.get_float(4)
+		, stack.get_vector3(5)
+		);
+	stack.push_float(t);
 	return 1;
 }
 
@@ -32,18 +49,23 @@ static int math_ray_sphere_intersection(lua_State* L)
 	Sphere s;
 	s.c = stack.get_vector3(3);
 	s.r = stack.get_float(4);
-	stack.push_float(ray_sphere_intersection(stack.get_vector3(1), stack.get_vector3(2), s));
+	const float t = ray_sphere_intersection(stack.get_vector3(1)
+		, stack.get_vector3(2)
+		, s
+		);
+	stack.push_float(t);
 	return 1;
 }
 
-static int math_ray_oobb_intersection(lua_State* L)
+static int math_ray_obb_intersection(lua_State* L)
 {
 	LuaStack stack(L);
-	OBB oobb;
-	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(ray_oobb_intersection(stack.get_vector3(1), stack.get_vector3(2), oobb));
+	const float t = ray_obb_intersection(stack.get_vector3(1)
+		, stack.get_vector3(2)
+		, stack.get_matrix4x4(3)
+		, stack.get_vector3(4)
+		);
+	stack.push_float(t);
 	return 1;
 }
 
@@ -552,8 +574,16 @@ static int matrix4x4_to_string(lua_State* L)
 {
 	LuaStack stack(L);
 	Matrix4x4& a = stack.get_matrix4x4(1);
-	stack.push_fstring("%.1f, %.1f, %.1f, %.1f\n%.1f, %.1f, %.1f, %.1f\n%.1f, %.1f, %.1f, %.1f\n%.1f, %.1f, %.1f, %.1f\n",
-						a.x.x, a.x.y, a.x.z, a.y.w, a.y.x, a.y.y, a.y.z, a.y.w, a.z.x, a.z.y, a.z.z, a.z.w, a.t.x, a.t.y, a.t.z, a.t.w);
+	stack.push_fstring(
+		"%.1f, %.1f, %.1f, %.1f\n"
+		"%.1f, %.1f, %.1f, %.1f\n"
+		"%.1f, %.1f, %.1f, %.1f\n"
+		"%.1f, %.1f, %.1f, %.1f\n"
+		, a.x.x, a.x.y, a.x.z, a.y.w
+		, a.y.x, a.y.y, a.y.z, a.y.w
+		, a.z.x, a.z.y, a.z.z, a.z.w
+		, a.t.x, a.t.y, a.t.z, a.t.w
+		);
 	return 1;
 }
 
@@ -865,8 +895,9 @@ static int lightuserdata_newindex(lua_State* L)
 void load_math(LuaEnvironment& env)
 {
 	env.load_module_function("Math", "ray_plane_intersection",  math_ray_plane_intersection);
+	env.load_module_function("Math", "ray_disc_intersection",   math_ray_disc_intersection);
 	env.load_module_function("Math", "ray_sphere_intersection", math_ray_sphere_intersection);
-	env.load_module_function("Math", "ray_oobb_intersection",   math_ray_oobb_intersection);
+	env.load_module_function("Math", "ray_obb_intersection",    math_ray_obb_intersection);
 
 	env.load_module_function("Vector3", "new",            vector3_new);
 	env.load_module_function("Vector3", "x",              vector3_x);