2

Consider the following perspective-projection matrix which works (perfectly fine) with just vertical-field-of-view and aspect-ratio given by the caller:

func (me *Mat4) Perspective (fovY, aspect, near, far float64) {
    tfY = near * math.Tan(fovY * math.Pi / 360)
    tfX = tfY * aspect
    me.Frustum(-tfX, tfX, -tfY, tfY, near, far)
}

How would one go about extending this function's body to support this: caller can now specify either vertical (fovY) or horizontal (fovX) field-of-view, but not both, and an aspect-ratio. How would this function be able to calculate the missing fovY from just the given aspect-ratio and fovX?

metaleap
  • 2,132
  • 2
  • 22
  • 40

1 Answers1

3

This should work:

  1. Calculate width using horizontal FOV and distance to the near plane (hint: there's a right triangle with sides near and width/2 and an angle fovx/2).
  2. Calculate height using width and aspect ratio.
  3. Calculate vertical FOV using height and distance to the near plane (hint: there's a right triangle with sides near and height/2 and an angle fovy/2).
mazayus
  • 164
  • 1
  • 3