Basic Dogfight Mode (4): Conclusion

Well, my imitation DFM didn't turn out the way I thought it would, but I was still able to figure out why my original idea didn't work and why. And once I did, all it took was a bit of a spin on the concept and I was mostly able to use it again.

Previous Post:
Basic Dogfight Mode (3): Yaw/Pitch/Throttle Spring Theory - Memories of Melon Pan

Many of you may have noticed that whenever I calculated yaw or pitch, I never calculated absolute yaw and pitch, only relative yaw and pitch from the ship's current heading. I actually don't keep track of absolute yaw, pitch, and roll when I update all the matrices on my ships. All I keep track of is current heading and up vector - each frame I look at the controller input (or DFM input), and adjust those two by the yaw, pitch, and roll of that frame. Then I make a new rotation matrix.

public void UpdateRotation(GameTime Time, float Yaw, float Pitch, float Roll) {
  Vector3 Right = Vector3.Cross(m_Dir, m_Up);


  // Local rotation around current direction.
  Matrix Rotation = Matrix.CreateFromAxisAngle(Right, Pitch)
            * Matrix.CreateFromAxisAngle(m_Up, Yaw)
            * Matrix.CreateFromAxisAngle(m_Dir, Roll);


  // Adjusting direction and up vector.
  m_Dir = Vector3.TransformNormal(m_Dir, Rotation);
  m_Up = Vector3.TransformNormal(m_Up, Rotation);
  Right = Vector3.Cross(m_Dir, m_Up);


  m_Dir.Normalize();
  m_Up.Normalize();
  Right.Normalize();


  // World rotation matrix.
  m_RotMatrix = Matrix.Identity;
  m_RotMatrix.Forward = m_Dir;
  m_RotMatrix.Up = m_Up;
  m_RotMatrix.Right = Right;
}

This is why for my final DFM run, I stopped as soon as I calculated axis velocity, since I add that to whatever is the current rotation every frame.

As always, the DFM used in Ace Combat: Assault Horizon is probably more complex than what I've done here, but I think I've done a decent imitation of it - enough that someone would get the idea about what DFM is all about and how they could do it too.