War In Space Day 4

WarInSpace4

Physics

I added a PhysicsGameComponent, which sounds like more than it actually is, since it only applies forces to the ships and integrates the equations of motion using Euler integration. However, since I currently don’t plan on having collisions between ships or other more physics-intensive effects, that will suffice very nicely. The result can be seen in the image, with one of the ships moved from it’s default position.

When I implemented a clamping of the speed of the ships, I realized that I should watch out for the units in which things such as forces or velocity are handled, so far I’m only fiddling with the values until they look good.

DirectInput Gamepads

Using the library I mentioned in the last post, I chose a very simple means of encapsulating the different controllers. On XBox 360, the only input devices used are the controllers. However on Windows, we use the DirectInputGamepad class, which gives access to all gamepads, including the XBox 360 gamepad. Using conditional compilation, this looks like the following function.

public float GetRotation(PlayerIndex playerIndex) {
    #if XBOX360
        return GamePad.GetState(playerIndex).ThumbSticks.Left.X;
    #else
        return DirectInputGamepad.Gamepads[GetPlayerNumber(playerIndex)].ThumbSticks.Left.X;
    #endif
}

I also stumbled over a small problem with the library, which showed itself in an error claiming there was a Loader Lock detected, look here for a solution to this problem.