Game Development Reference
In-Depth Information
Figure 8.19
Coordinate systems of the form.
The Input class will be initiated and updated in the form. GameStates that
wish to know about the mouse position need to take the Input object into their
constructors. Add an Input object to the form class now.
public partial class Form1 : Form
{
Input _input = new Input();
In the form a new function needs to be created that will update the Input class;
this will be called every frame.
private void UpdateInput()
{
System.Drawing.Point mousePos = Cursor.Position;
mousePos = _openGLControl.PointToClient(mousePos);
// Now use our point definition,
Point adjustedMousePoint = new Point();
adjustedMousePoint.X = (float)mousePos.X - ((float)ClientSize.Width
/ 2);
adjustedMousePoint.Y = ((float)ClientSize.Height / 2)-(float)mouse-
Pos.Y;
_input.MousePosition = adjustedMousePoint;
}
private void GameLoop(double elapsedTime)
{
UpdateInput();
UpdateInput translates the mouse position from the form's coordinate system
to the control coordinate system by using the PointToClient function. The
 
Search WWH ::




Custom Search