Game Development Reference
In-Depth Information
mouse position is then finally converted to the OpenGL coordinate system based
on the center of the OpenGL control. This is done by taking away half the width
and height of the control from its X and Y position. The final coordinate now
correctly maps the mouse position from the form coordinates to OpenGL co-
ordinates. If the mouse was placed in the center of the OpenGL control, it would
have the Input class report the position (0,0).
There is one last thing that needs to be written before leaving the form code. The
new input object must be added to the constructor of the circle state.
_system.AddState("circle_state", new CircleIntersectionState(_input));
The state's constructor must also be modified.
Input _input;
public CircleIntersectionState(Input input)
{
_input = input;
Once the input is being passed to the state then the mouse position can be used.
It's worth confirming that everything is working correctly. The easiest way to do
this is to draw a dot where the cursor is in OpenGL.
public void Render()
{
Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_circle.Draw();
// Draw the mouse cursor as a point
Gl.glPointSize(5);
Gl.glBegin(Gl.GL_POINTS);
{
Gl.glVertex2f(_input.MousePosition.X,
_input.MousePosition.Y);
}
Gl.glEnd();
}
Run the program and a small square will follow the pointer of the cursor. You
may note that I've added the glClear commands. Try removing the glClear
commands and see what happens.
 
Search WWH ::




Custom Search