I’m trying to implement a simple ray-tracing algorithm
so the first step is to convert pixel coordinates into uvw coordinates system
iam using those two equations that i found in a book

where l,r,b,t are the view frustum points , (i,j) are the pixel indexes , (nx,ny) are the scene width and height
then to calculate canonical coordinate i use

i want to understand the previous equations and why they give uwv coordinates for perspective projection not for orthogonal projection (when i use orthogonal projection the equation still gives the result as if perspective projection is used)
Let’s assume your camera is some sort of a pyramid. It has a bottom face which I’ll refer to as the “camera screen”, and the height of the pyramid, also known as the focal length, will be marked as F (or in your equations, Ws).
Let’s assume
jgoes from the bottom to the top (from-Ny/2to+Ny/2in steps of1/Ny), andigoes from left to right (from-Nx/2to+Nx/2in steps of1/Nx). Note that if Ny is even, j goes up toNx/2-1(and similar whenNxis even).As you go from bottom to top in the image, on the screen, you move from the
Bvalue to theTvalue. At the fractiond(between 0=bottom and 1=top) of your way from bottom to top, your height isA bit of messing around shows that the fraction
dis actually:So:
And similarly:
Now, let’s denote
Uas the vector going from left to right,Vfrom bottom to top, ‘W’ going from the eye forward. All these vectors are normalized.Now, assume the eye is located directly above
(0,0)where that is exactly above the center of the rectangular face of the pyramid.To go from the eye directly to
(0,0)you would go:And then to go from that point to another point on the screen at indexes
(i,j)you would go:You will be able to see that
Us = 0fori = 0andVs = 0forj = 0(sinceB = -TandL = -R, as the eye is directly above the center of the rectangle).And finally, if we compose it together, a point on the screen at indexes
(i,j)isEnjoy!