Game Development Reference
In-Depth Information
_controller.LeftControlStick.Y * -300);
Gl.glColor3f(0, 1, 0);
Gl.glVertex2f(
_controller.RightControlStick.X * 300,
_controller.RightControlStick.Y * -300);
}
Gl.glEnd();
}
The Render function draws a white background and a green and red dot re-
presenting each of the control sticks. The point size is increased and texture
mode is disabled to make the dots more visible. Run the program and move the
dots around the screen. The control stick's values only go from -1 to 1, which
isn't a large enough number to visually move the dots around the screen; there-
fore, the value is multiplied by 300. The Y axis is multiplied by -300 to invert it;
try removing the minus sign and see which control scheme you prefer.
The next control to wrap is the button. There are actually ten buttons on the
Xbox 360 controller. The X, Y, A, B buttons, start and back, the two shoulder
buttons, and pushing in the two control sticks. As before, add the following
control class to the engine library project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.Sdl;
namespace Engine
{
public class ControllerButton
{
IntPtr _joystick;
int _buttonId;
public bool Held { get; private set; }
public ControllerButton(IntPtr joystick, int buttonId)
{
_joystick = joystick;
_buttonId = buttonId;
}
 
Search WWH ::




Custom Search