Detecting user inputs
The steps to control a 3D character through a game-controller are summarized below:
Get the character's pointer
Process the message from the game-controller
Interact with the 3D character
Step 1. Get the character's pointer
The first step is to get a pointer to the astronaut from the View Component.
In the snippet below, the class Earth implements the View component of the MVC. Whereas, the class GameLogic implements the Model component of the MVC.
In line 1, we get a pointer to the View component, that is the Earth class. In line 2, we search for the character of interest by providing its name.
Once you have the pointer to the character, you can now process the message from the controller.
Step 2. Process Message
The next step is to process the messages from the Controller Component and determine which button was pressed.
The message from the controller is handled by the receiveUserInput() method, as shown below.
Step 3. Interact with the game character
Finally, depending on the button pressed, we interact with the 3D character. For instance, in the snippet above, whenever the user presses button B, the character is translated ( line 4a).
Last updated