1

I've recently been venturing into conversion of 3D points in space to a 2D pixel position on a screen, and almost every single answer I've found has been something like "do X with your world-to-camera matrix, and multiply by your viewport height to get it in pixels".

Now, that's all fine and good, but oftentimes these questions were about programming for video game engines, where a function to get a camera's view matrix is often built into a library and called on-command. But in my case, I can't do that - I need to know how to, given an FOV (say, 78 degrees) and a position and angle (of the format pitch = x, yaw = y, roll = z) it's facing, calculate the view matrix of a virtual camera.

Does anybody know what I need to do? I'm working with Lua (with built-in userdata for things like 3D vectors, angles, and 4x4 matrices exposed via the C interface), if that helps.

mrjackman
  • 21
  • 2

1 Answers1

0

I am using gluPerspective

gluPerspective

where:

fovw,fovh // are FOV in width and height of screen angles [rad]
zn,zf     // are znear,zfar distances from focal point of camera

When using FOVy notation from OpenGL then:

aspect = width/height 
fovh   = FOVy
fovw   = FOVx = FOVy*aspect

so just feed your 4x4 matrix with the values in order defined by notations you use (column or row major order).

I got the feeling you are doing SW render on your own so Do not forget to do the perspective divide!. Also take a look at the matrix link above and also at:

Spektre
  • 49,595
  • 11
  • 110
  • 380