Explorar el Código

tools: never feed dx/dy externally

Daniele Bartolini hace 7 años
padre
commit
27c47b1243

+ 4 - 4
samples/core/editors/level_editor/camera.lua

@@ -5,8 +5,8 @@ FPSCamera = class(FPSCamera)
 function FPSCamera:init(world, unit)
 	self._world = world
 	self._unit = unit
-	self._translation_speed = 47
-	self._rotation_speed = 0.38
+	self._translation_speed = 20
+	self._rotation_speed = 0.14
 	self._perspective_local_pose = Matrix4x4Box(Matrix4x4.identity())
 end
 
@@ -69,7 +69,7 @@ function FPSCamera:screen_length_to_world_length(position, length)
 	return length / Vector3.distance(a, b)
 end
 
-function FPSCamera:update(dt, dx, dy, keyboard)
+function FPSCamera:update(dt, dx, dy, keyboard, mouse)
 	local sg = World.scene_graph(self._world)
 
 	local camera_local_pose = SceneGraph.local_pose(sg, self._unit)
@@ -81,7 +81,7 @@ function FPSCamera:update(dt, dx, dy, keyboard)
 
 	-- Rotation
 	if dx ~= 0 or dy ~= 0 then
-		if not self:is_orthographic() then
+		if not self:is_orthographic() and mouse.right then
 			local rotation_speed = self._rotation_speed * dt
 			local rotation_around_world_up = Quaternion(Vector3(0, 1, 0), dx * rotation_speed)
 			local rotation_around_camera_right = Quaternion(camera_right_vector, dy * rotation_speed)

+ 7 - 10
samples/core/editors/level_editor/level_editor.lua

@@ -1314,7 +1314,7 @@ function LevelEditor:init()
 	self._lines_no_depth = World.create_debug_line(self._world, false)
 	self._lines = World.create_debug_line(self._world, true)
 	self._fpscamera = FPSCamera(self._world, World.spawn_unit(self._world, "core/units/camera"))
-	self._mouse = { x = 0, y = 0, dx = 0, dy = 0, button = { left = false, middle = false, right = false }, wheel = { delta = 0 }}
+	self._mouse = { x = 0, y = 0, x_last = 0, y_last = 0, button = { left = false, middle = false, right = false }, wheel = { delta = 0 }}
 	self._keyboard = { ctrl = false, shift = false, alt = false }
 	self._grid = { size = 1 }
 	self._rotation_snap = 15.0 * math.pi / 180.0
@@ -1350,14 +1350,13 @@ function LevelEditor:update(dt)
 		draw_world_origin_grid(self._lines, 10, self._grid.size)
 	end
 
-	local delta = Vector3.zero();
-	if self._mouse.right then
-		delta.x = self._mouse.dx;
-		delta.y = self._mouse.dy;
-	end
+	self._mouse.dx = self._mouse.x - self._mouse.x_last
+	self._mouse.dy = self._mouse.y - self._mouse.y_last
+	self._mouse.x_last = self._mouse.x
+	self._mouse.y_last = self._mouse.y
 
 	self._fpscamera:mouse_wheel(self._mouse.wheel.delta)
-	self._fpscamera:update(dt, delta.x, delta.y, self._keyboard)
+	self._fpscamera:update(dt, self._mouse.dx, self._mouse.dy, self._keyboard, self._mouse)
 
 	self.tool:update(dt, self._mouse.x, self._mouse.y)
 
@@ -1401,11 +1400,9 @@ function LevelEditor:set_mouse_state(x, y, left, middle, right)
 	self._mouse.right = right
 end
 
-function LevelEditor:mouse_move(x, y, dx, dy)
+function LevelEditor:mouse_move(x, y)
 	self._mouse.x = x
 	self._mouse.y = y
-	self._mouse.dx = dx
-	self._mouse.dy = dy
 
 	self.tool:mouse_move(x, y)
 end

+ 1 - 8
tools-imgui/level_editor.cpp

@@ -343,7 +343,6 @@ struct SceneView
 	ImVec2 _origin;
 	ImVec2 _size;
 	ImVec2 _mouse;
-	ImVec2 _mouse_last;
 	bool _open;
 
 	SceneView()
@@ -1438,17 +1437,11 @@ bool tool_process_events()
 					if (!io.WantCaptureMouse)
 					{
 						ImVec2& mouse_curr = s_editor->_scene_view._mouse;
-						ImVec2& mouse_last = s_editor->_scene_view._mouse_last;
 
 						mouse_curr.x = io.MousePos.x - s_editor->_scene_view._origin.x;
 						mouse_curr.y = io.MousePos.y - s_editor->_scene_view._origin.y;
 
-						f32 delta_x = mouse_curr.x - mouse_last.x;
-						f32 delta_y = mouse_curr.y - mouse_last.y;
-
-						tool::mouse_move(ss, mouse_curr.x, mouse_curr.y, delta_x, delta_y);
-
-						mouse_last = mouse_curr;
+						tool::mouse_move(ss, mouse_curr.x, mouse_curr.y);
 					}
 					break;
 

+ 2 - 4
tools-imgui/tool_api.h

@@ -120,13 +120,11 @@ void mouse_wheel(StringStream& out, f32 delta)
 	out << delta << ")";
 }
 
-void mouse_move(StringStream& out, f32 x, f32 y, f32 dx, f32 dy)
+void mouse_move(StringStream& out, f32 x, f32 y)
 {
 	out << "LevelEditor:mouse_move(";
 	out << x << ",";
-	out << y << ",";
-	out << dx << ",";
-	out << dy << ")";
+	out << y << ")";
 }
 
 void keyboard_pressed(StringStream& out, char c)

+ 2 - 2
tools/api/engine_api.vala

@@ -90,9 +90,9 @@ namespace Crown
 				);
 		}
 
-		public string mouse_move(int x, int y, int dx, int dy)
+		public string mouse_move(int x, int y)
 		{
-			return "LevelEditor:mouse_move(%d,%d,%d,%d)".printf(x, y, dx, dy);
+			return "LevelEditor:mouse_move(%d,%d)".printf(x, y);
 		}
 
 		public string mouse_wheel(double delta)

+ 1 - 14
tools/level_editor/engine_view.vala

@@ -16,8 +16,6 @@ namespace Crown
 
 		private int _mouse_curr_x;
 		private int _mouse_curr_y;
-		private int _mouse_last_x;
-		private int _mouse_last_y;
 
 		private bool _mouse_left;
 		private bool _mouse_middle;
@@ -63,8 +61,6 @@ namespace Crown
 
 			_mouse_curr_x = 0;
 			_mouse_curr_y = 0;
-			_mouse_last_x = 0;
-			_mouse_last_y = 0;
 
 			_mouse_left   = false;
 			_mouse_middle = false;
@@ -194,17 +190,8 @@ namespace Crown
 		{
 			_mouse_curr_x = (int)ev.x;
 			_mouse_curr_y = (int)ev.y;
-			int _mouse_delta_x = _mouse_curr_x - _mouse_last_x;
-			int _mouse_delta_y = _mouse_curr_y - _mouse_last_y;
 
-			_client.send_script(LevelEditorApi.mouse_move(_mouse_curr_x
-				, _mouse_curr_y
-				, _mouse_delta_x
-				, _mouse_delta_y
-				));
-
-			_mouse_last_x = _mouse_curr_x;
-			_mouse_last_y = _mouse_curr_y;
+			_client.send_script(LevelEditorApi.mouse_move(_mouse_curr_x, _mouse_curr_y));
 
 			return false;
 		}