Game Development Reference
In-Depth Information
public void Update()
{
Value = MapZeroToOne(Sdl.SDL_JoystickGetAxis(_joystick, _index));
}
private float MapZeroToOne(short value)
{
float output = ((float)value / short.MaxValue);
if (_top == false)
{
if (output > 0)
{
output = 0;
}
output = Math.Abs(output);
}
// Be careful of rounding error
output = Math.Min(output, 1.0f);
output = Math.Max(output, 0.0f);
if (Math.Abs(output) < _deadZone)
{
output = 0;
}
return output;
}
}
}
The ControlTrigger class operates on an axis but only takes half the value of
it. There are only two triggers so it's not much to add to the controller class. In
the constructor, the two triggers are set up using the same axis.
Finally, both the triggers must be added to the Update function of the
controller.
public ControlTrigger RightTrigger { get; private set; }
Search WWH ::




Custom Search