Ver Fonte

Add MouseAxis::CURSOR_DELTA

Daniele Bartolini há 10 anos atrás
pai
commit
c9aebda0bd
3 ficheiros alterados com 19 adições e 4 exclusões
  1. 1 0
      src/input/input_types.h
  2. 3 2
      src/lua/lua_input.cpp
  3. 15 2
      src/main/main.cpp

+ 1 - 0
src/input/input_types.h

@@ -143,6 +143,7 @@ struct MouseAxis
 	enum Enum
 	enum Enum
 	{
 	{
 		CURSOR,
 		CURSOR,
+		CURSOR_DELTA,
 		WHEEL,
 		WHEEL,
 		COUNT
 		COUNT
 	};
 	};

+ 3 - 2
src/lua/lua_input.cpp

@@ -125,8 +125,9 @@ struct MouseAxisInfo
 
 
 static MouseAxisInfo s_mouse_axis[] =
 static MouseAxisInfo s_mouse_axis[] =
 {
 {
-	{ "cursor", MouseAxis::CURSOR },
-	{ "wheel",  MouseAxis::WHEEL  }
+	{ "cursor",       MouseAxis::CURSOR       },
+	{ "cursor_delta", MouseAxis::CURSOR_DELTA },
+	{ "wheel",        MouseAxis::WHEEL        }
 };
 };
 CE_STATIC_ASSERT(CE_COUNTOF(s_mouse_axis) == MouseAxis::COUNT);
 CE_STATIC_ASSERT(CE_COUNTOF(s_mouse_axis) == MouseAxis::COUNT);
 
 

+ 15 - 2
src/main/main.cpp

@@ -21,6 +21,17 @@ bool process_events()
 	bool exit = false;
 	bool exit = false;
 	InputManager* im = device()->input_manager();
 	InputManager* im = device()->input_manager();
 
 
+	static int16_t mouse_curr_x = 0;
+	static int16_t mouse_curr_y = 0;
+	static int16_t mouse_last_x = 0;
+	static int16_t mouse_last_y = 0;
+
+	const int16_t dt_x = mouse_curr_x - mouse_last_x;
+	const int16_t dt_y = mouse_curr_y - mouse_last_y;
+	im->mouse()->set_axis(MouseAxis::CURSOR_DELTA, vector3(dt_x, dt_y, 0.0f));
+	mouse_last_x = mouse_curr_x;
+	mouse_last_y = mouse_curr_y;
+
 	while(next_event(event))
 	while(next_event(event))
 	{
 	{
 		if (event.type == OsEvent::NONE) continue;
 		if (event.type == OsEvent::NONE) continue;
@@ -53,10 +64,12 @@ bool process_events()
 						im->mouse()->set_button_state(ev.button, ev.pressed);
 						im->mouse()->set_button_state(ev.button, ev.pressed);
 						break;
 						break;
 					case OsMouseEvent::MOVE:
 					case OsMouseEvent::MOVE:
-						im->mouse()->set_axis(0, vector3(ev.x, ev.y, 0.0f));
+						mouse_curr_x = ev.x;
+						mouse_curr_y = ev.y;
+						im->mouse()->set_axis(MouseAxis::CURSOR, vector3(ev.x, ev.y, 0.0f));
 						break;
 						break;
 					case OsMouseEvent::WHEEL:
 					case OsMouseEvent::WHEEL:
-						im->mouse()->set_axis(1, vector3(ev.wheel, 0.0f, 0.0f));
+						im->mouse()->set_axis(MouseAxis::WHEEL, vector3(ev.wheel, 0.0f, 0.0f));
 						break;
 						break;
 					default:
 					default:
 						CE_FATAL("Unknown mouse event type");
 						CE_FATAL("Unknown mouse event type");