Up direction, perpendicular to the look-at direction t
We establish the camera as the origin, with up at Y and look-at towards −Z. This approach enables us to transform everything in relation to the camera's position and orientation. Consequently, we construct a Camera Transform Matrix Mview to translate e to the origin, rotate g towards −Z, and rotate g×t towards X. Mview=RviewTview Although direct rotation might seem complex, we can apply reverse rotation: Rview−1=xg×tyg×tzg×t0xtytzt0x−gy−gz−g00001 Given that the rotation matrix is orthogonal: Rview=(Rview−1)−1=(Rview−1)T=xg×txtx−g0yg×tyty−g0zg×tztz−g00001 Thus, by transforming the object with Mview, the objects' appearance remains consistent from the camera's viewpoint.
In general, for a cuboid, we first translate it to the centre. Then, we use the parameters left, right, bottom, top, far, and near to define its dimensions as [l,r]×[b,t]×[f,n]. This allows us to transform it into a canonical cube of dimensions [−1,1]3. Mortho=r−l20000t−b20000n−f200001100001000010−2r+l−2t+b−2n+f1
Perspective Projection
Recall: [x,y,z,1]T=[kx,ky,kz,k]T=[xz,yz,z2,z]T in homogeneous coordinates.
For perspective projection, we start by transforming the frustum into a cuboid, which is then followed by an orthographic projection. This involves:
Keep near plate the same
Keep z value of far plate the same
Keep the centre of far plate the same.
Through similarity, the projection on the x and y axes can be represented as: x′=znx
y′=zny So we can have part of our Mper: Mper→othro=n0#00n#000#100#0 Based on our rule, we need near plate and the centre of far plate remain the same. Mper→othr[x,y,n,1]T=[x,y,n,1]T==[nx,ny,n2,n]T
Mper→othr[0,0,f,1]T=[0,0,f,1]T==[0,0,f2,f]T
Solve, it: Mper→othr=n0000n0000n+f100−fn0 Then, we can have: Mper=MothrMper→othr The refined explanation for the Perspective to Orthographic projection transformation is as follows: R′=Mper→othrR=xyz1n0000n0000n+f100−fn0=znxznyn+f−znf1 Specifically, when z equals the near n or far f plane distances, the transformed z′ coordinate remains unchanged. However, for values of z between n and f, z′ becomes smaller, approaching f. This transformation, therefore, compresses the depth dimension, making objects appear further away as they move closer to the far plane.