Craving control.
Tags: opengles2, android, vrgame, devlog
Published: 2020-04-23 19:28:00

#Overview
In order for the player to move around the scene and look around we need to receive input from the player, the planning of this aspect is what this blog post will concentrate on.

#Device rotation
The desired control input method for looking around the scene would be using the android devices internal sensors to control the <code>GameCamera</code>s look direction, unfortunately while following the android documentation on [using the position sensors](https://developer.android.com/guide/topics/sensors/sensors_position) I discovered that my device does not support either of the required <code>Sensor.TYPE_GAME_ROTATION_VECTOR</code> or <code>Sensor.TYPE_MAGNETIC_FIELD</code> sensors.
So initially, I shall use an xbox controller to look around as well as move around the scene.

#Xbox One Controller
The initial plan for moving around the screen was to use a Nintendo Joycon controller, while testing this though, the lag seemed to be too large to make it usable (_even with bluetooth headphones connected at the same time_).
Therefore I decided to change to an xbox one controller, pairing with my android device was seamless and once paired, the device responded quickly to stick movements and button presses. 
###Pairing
Pairing the controller with my android device was simple, I followed these steps:
<ul>
<li>Ensure your Xbox console is unplugged to prevent the controller pairing with the console</li>
<li>Turn on the controller by pressing the xbox button in the center of the controller which should then start flashing.</li>
<li>Hold the sync button at the top of the controller near the USB socket, until the xbox button flashes faster.</li>
<li>Enter your devices bluetooth menu and search for a the controller and pair with it, on my device it was called "Xbox Wireless Controller"</li>
</ul>
If pairing is successful, the xbox button should stop flashing and remain lit.

#Controller abstraction
To facilitate changing the control input methods in future I plan on abstracting the game controls from the input methods using an interface for the look control input, an interface for the move control input, an interface for button control inputs and a hub which can use any class that implements these interfaces as the input methods.

###The <code>LookControlInterface</code>
This interface is implemented by any class which can be used to generate look control input.
The <code>XboxController</code> class implements this interface and also the <code>DeviceRotationSensor</code> class implements it, so in future I can swap out the control methods depending on what is supported by the device.
![LookControlInterface UML](https://dev-to-uploads.s3.amazonaws.com/i/cr2esolj4kc5lnbrqvgg.PNG)
###The <code>MoveControlInterface</code>
This interface is implemented by any class which can be used to generate movement control input.
The <code>XboxController</code> class is the only one to implement this interface currently but any new controllers added going forward would also implement it. 
![MoveControlInterface UML](https://dev-to-uploads.s3.amazonaws.com/i/3o1t43cd8sk4533j55q7.PNG)
###The <code>ButtonControlInterface</code>
This interface is implemented by any class which can be used to generate button press inputs (initially one an action button input).
The <code>XboxController</code> class is the only one to implement this interface currently but any new controllers added going forward would also implement it.  
![ButtonControlInterface UML](https://dev-to-uploads.s3.amazonaws.com/i/8j972e57e264qrgb7q8u.PNG)
###The <code>GameControlHub</code> Class
This class is the hub which connects the selected look control method, movement control method and button control method to the game code, thus allowing different control methods to be set based on the device capabilities.
![GameControlHub UML](https://dev-to-uploads.s3.amazonaws.com/i/a4oxx2k029qd8pgbc3r5.PNG)
#The next step
Following from this post, I shall be looking to implement the interfaces and classes detailed here and using the xbox controller as the main input method.