Daniele Bartolini hace 9 años
padre
commit
78ee2cec75

+ 8 - 0
src/lua/lua_api.cpp

@@ -1946,6 +1946,13 @@ static int render_world_set_light_spot_angle(lua_State* L)
 	return 0;
 }
 
+static int render_world_debug_draw_light(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.get_render_world(1)->debug_draw_light(stack.get_light_instance(2), *stack.get_debug_line(3));
+	return 0;
+}
+
 static int render_world_enable_debug_drawing(lua_State* L)
 {
 	LuaStack stack(L);
@@ -3260,6 +3267,7 @@ void load_api(LuaEnvironment& env)
 	env.add_module_function("RenderWorld", "set_light_range",      render_world_set_light_range);
 	env.add_module_function("RenderWorld", "set_light_intensity",  render_world_set_light_intensity);
 	env.add_module_function("RenderWorld", "set_light_spot_angle", render_world_set_light_spot_angle);
+	env.add_module_function("RenderWorld", "debug_draw_light",     render_world_debug_draw_light);
 	env.add_module_function("RenderWorld", "enable_debug_drawing", render_world_enable_debug_drawing);
 
 	env.add_module_function("PhysicsWorld", "actor_instances",               physics_world_actor_instances);

+ 1 - 1
src/world/physics_world.h

@@ -182,7 +182,7 @@ public:
 	virtual EventStream& events() = 0;
 
 	/// Draws debug lines.
-	virtual void draw_debug() = 0;
+	virtual void debug_draw() = 0;
 
 	virtual void enable_debug_drawing(bool enable) = 0;
 };

+ 1 - 1
src/world/physics_world_bullet.cpp

@@ -931,7 +931,7 @@ public:
 		return _events;
 	}
 
-	void draw_debug()
+	void debug_draw()
 	{
 		if (!_debug_drawing)
 			return;

+ 1 - 1
src/world/physics_world_null.cpp

@@ -290,7 +290,7 @@ public:
 		return _events;
 	}
 
-	virtual void draw_debug()
+	virtual void debug_draw()
 	{
 	}
 

+ 39 - 37
src/world/render_world.cpp

@@ -293,7 +293,44 @@ void RenderWorld::render(const Matrix4x4& view, const Matrix4x4& projection)
 	}
 }
 
-void RenderWorld::draw_debug(DebugLine& dl)
+void RenderWorld::debug_draw_light(LightInstance i, DebugLine& dl)
+{
+	LightManager::LightInstanceData& lid = _light_manager._data;
+
+	const Vector3 pos = translation(lid.world[i.i]);
+	const Vector3 dir = -z(lid.world[i.i]);
+
+	switch (lid.type[i.i])
+	{
+		case LightType::DIRECTIONAL:
+		{
+			const Vector3 end = pos + dir*3.0f;
+			dl.add_line(pos, end, COLOR4_YELLOW);
+			dl.add_cone(pos + dir*2.8f, end, 0.1f, COLOR4_YELLOW);
+			break;
+		}
+		case LightType::OMNI:
+		{
+			dl.add_sphere(pos, lid.range[i.i], COLOR4_YELLOW);
+			break;
+		}
+		case LightType::SPOT:
+		{
+			const f32 angle  = lid.spot_angle[i.i];
+			const f32 range  = lid.range[i.i];
+			const f32 radius = tan(angle)*range;
+			dl.add_cone(pos + range*dir, pos, radius, COLOR4_YELLOW);
+			break;
+		}
+		default:
+		{
+			CE_ASSERT(false, "Bad light type");
+			break;
+		}
+	}
+}
+
+void RenderWorld::debug_draw(DebugLine& dl)
 {
 	if (!_debug_drawing)
 		return;
@@ -310,42 +347,7 @@ void RenderWorld::draw_debug(DebugLine& dl)
 	}
 
 	for (u32 i = 0; i < lid.size; ++i)
-	{
-		const Vector3 pos = translation(lid.world[i]);
-		const Vector3 dir = -z(lid.world[i]);
-
-		// Draw tiny sphere for all light types
-		dl.add_sphere(pos, 0.1f, lid.color[i]);
-
-		switch (lid.type[i])
-		{
-			case LightType::DIRECTIONAL:
-			{
-				const Vector3 end = pos + dir*3.0f;
-				dl.add_line(pos, end, COLOR4_YELLOW);
-				dl.add_cone(pos + dir*2.8f, end, 0.1f, COLOR4_YELLOW);
-				break;
-			}
-			case LightType::OMNI:
-			{
-				dl.add_sphere(pos, lid.range[i], COLOR4_YELLOW);
-				break;
-			}
-			case LightType::SPOT:
-			{
-				const f32 angle = lid.spot_angle[i];
-				const f32 range = lid.range[i];
-				const f32 radius = tan(angle)*range;
-				dl.add_cone(pos + range*dir, pos, radius, COLOR4_YELLOW);
-				break;
-			}
-			default:
-			{
-				CE_ASSERT(false, "Bad light type");
-				break;
-			}
-		}
-	}
+		debug_draw_light({ i }, dl);
 }
 
 void RenderWorld::enable_debug_drawing(bool enable)

+ 4 - 1
src/world/render_world.h

@@ -99,8 +99,11 @@ public:
 	/// Sets whether to @a enable debug drawing
 	void enable_debug_drawing(bool enable);
 
+	/// Fills @a dl with debug lines from light @a i.
+	void debug_draw_light(LightInstance i, DebugLine& dl);
+
 	/// Fills @a dl with debug lines
-	void draw_debug(DebugLine& dl);
+	void debug_draw(DebugLine& dl);
 
 private:
 

+ 2 - 2
src/world/world.cpp

@@ -196,8 +196,8 @@ void World::render(CameraInstance i)
 
 	_render_world->render(camera_view_matrix(i), camera.projection);
 
-	_physics_world->draw_debug();
-	_render_world->draw_debug(*_lines);
+	_physics_world->debug_draw();
+	_render_world->debug_draw(*_lines);
 
 	_lines->submit();
 	_lines->reset();