Sanjay Madhav %!s(int64=8) %!d(string=hai) anos
pai
achega
4c04879384
Modificáronse 3 ficheiros con 26 adicións e 1 borrados
  1. 6 1
      Chapter08/Game.cpp
  2. 15 0
      Chapter08/InputSystem.cpp
  3. 5 0
      Chapter08/InputSystem.h

+ 6 - 1
Chapter08/Game.cpp

@@ -30,7 +30,7 @@ Game::Game()
 
 bool Game::Initialize()
 {
-	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0)
+	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_GAMECONTROLLER) != 0)
 	{
 		SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
 		return false;
@@ -122,6 +122,11 @@ void Game::ProcessInput()
 			case SDL_QUIT:
 				mIsRunning = false;
 				break;
+			case SDL_MOUSEWHEEL:
+				mInputSystem->ProcessEvent(event);
+				break;
+			default:
+				break;
 		}
 	}
 

+ 15 - 0
Chapter08/InputSystem.cpp

@@ -103,6 +103,7 @@ void InputSystem::PrepareForUpdate()
 	// Mouse
 	mState.Mouse.mPrevButtons = mState.Mouse.mCurrButtons;
 	mState.Mouse.mIsRelative = false;
+	mState.Mouse.mScrollWheel = Vector2::Zero;
 }
 
 void InputSystem::Update()
@@ -124,6 +125,20 @@ void InputSystem::Update()
 	mState.Mouse.mMousePos.y = static_cast<float>(y);
 }
 
+void InputSystem::ProcessEvent(SDL_Event& event)
+{
+	switch (event.type)
+	{
+	case SDL_MOUSEWHEEL:
+		mState.Mouse.mScrollWheel = Vector2(
+			static_cast<float>(event.wheel.x),
+			static_cast<float>(event.wheel.y));
+		break;
+	default:
+		break;
+	}
+}
+
 void InputSystem::SetRelativeMouseMode(bool value)
 {
 	SDL_bool set = value ? SDL_TRUE : SDL_FALSE;

+ 5 - 0
Chapter08/InputSystem.h

@@ -42,6 +42,7 @@ public:
 
 	// For mouse position
 	const Vector2& GetPosition() const { return mMousePos; }
+	const Vector2& GetScrollWheel() const { return mScrollWheel; }
 	bool IsRelative() const { return mIsRelative; }
 
 	// For buttons
@@ -50,6 +51,8 @@ public:
 private:
 	// Store current mouse position
 	Vector2 mMousePos;
+	// Motion of scroll wheel
+	Vector2 mScrollWheel;
 	// Store button data
 	Uint32 mCurrButtons;
 	Uint32 mPrevButtons;
@@ -74,6 +77,8 @@ public:
 	void PrepareForUpdate();
 	// Called after SDL_PollEvents loop
 	void Update();
+	// Called to process an SDL event in input system
+	void ProcessEvent(union SDL_Event& event);
 
 	const InputState& GetState() const { return mState; }