C++ 3D Game Tutorial Series: 14 | Input System | Early Access | Source Code on GitHub
The fourteenth tutorial of C++ 3D Game Tutorial Series is finally available in early access on GitHub!
Friday 29th May 2026

C++ 3D Game Tutorial Series: 14 | Input System | Source Code on GitHub


 

 

The source code of the 14th tutorial of the C++ 3D Game Tutorial Series is now available in early access on GitHub!

This tutorial introduces a comprehensive Input System to the engine, significantly enhances math utilities, and refactors the sample game to demonstrate these new capabilities with a player controller.

Here is a descriptive summary of the changes:

New Input System


  • InputSystem Class: A new core system has been added to handle keyboard and mouse input, implemented using Win32 APIs (GetAsyncKeyState, ShowCursor, etc.).

  • Key Mapping: A KeyCode enum defines inputs for letters (A-Z), numbers (0-9), modifiers (Escape, Shift, Space, Enter), arrows, and mouse buttons (Left, Middle, Right).

  • Input Queries: The system provides methods to check key states (isKeyDown, isKeyPressed, isKeyReleased) and track mouse metrics (getMousePosition, getMouseDelta).

  • Cursor Management: Utilities allow locking the cursor to the game window, toggling visibility, and defining the lock area.

Math & Vector Enhancements


  • New Vec2 Class: A 2D vector class has been added, likely used for screen-space coordinates and mouse tracking.

  • Vec3 Improvements: The 3D vector class now supports arithmetic operators (+=, *) and a normalize static method, enabling cleaner vector math operations throughout the engine.

  • Window Helpers: Window::getClientAreaInScreenSpace() was added to help map internal coordinates to screen space, essential for accurate input handling.

Engine Integration


  • Game Class: The Game class now instantiates the InputSystem, exposes it via getInputSystem(), and ensures it is updated every frame in onInternalUpdate.

Sample Game (MainGame) Overhaul


  • Player Controller: The demo playground has been refactored. The previous grid of nine rotating cubes has been replaced by a single m_player GameObject.

  • Controls Implemented:

    • Mouse Look: Player rotation is driven by mouse delta, with the cursor locked and hidden for an FPS-style experience.

    • WASD Movement: Keyboard input calculates a direction vector. The new Vec3::normalize and arithmetic operators are used to move the player forward/right based on speed and delta time.

Overall, this tutorial lays the groundwork for interactive gameplay by providing input handling and vector math, while the updated demo effectively showcases these features in action.

You can find the full source code on GitHub here: GitHub Link

I hope you enjoy the tutorial, and thank you for all your support!