Home > Enterprise >  Why is my rotation matrix returning not working properly?
Why is my rotation matrix returning not working properly?

Time:07-02

I've been working a bit on this simple rasterizer, but the cube I imported is not rotating properly. Here's a picture of the issue: enter image description here

I copied a rotation matrix from this fig1

Given a point P with (x,y,z) coordinates, you want to find point Q which is the projection on the model plane.

More specifically you need to find the distance QC and relate it as a ratio to the distance AB. This is because on screen the distance AB corresponds to the height H in pixels of your viewport.

So the vertical pixel count is

          y     L
py = H * --- * ---
         AB    L-z

where L is the distance to the camera/eye along the z axis.

Sometimes the model size AB isn't known, but instead the field of view (FOV) in degrees is. From trigonometry, we have tan(fov/2*π/180) = AB/(2*L) which simplifies the projection as such

                 1          y
py = H * -------------- *  ---
         tan(fov*π/360)    L-z

Typically the factor f=H/tan(fov*π/360) is pre-computed and the projection of point P is

px = f * (x/(L-z))
py = f * (y/(L-z))
  • Related