Skip to content
PostComputer Graphics / Lecture

CG-Viewing Transformation

2025-03-02
Back to Blog

Computer Graphics - Viewing Transformation include the following topics: View / Camera Transformation and Projection Transformation.


CG-Viewing Transformation ​

View Transformation ​

sEmyaO

  • Define the camera first
    • Position e→
    • Look-at / gaze direction g→
    • Up direction t^ (assuming perpendicular to look-at)

Key observation ​

If the camera and all objects move together, the “photo” will be the same.

mfynva

How about that we always transform the camera to

  • The origin, up at Y, look at −Z
  • And transform the objects along with the camera

RdtATY

  • Mview in math?

    • Translates e→ to origin
    • Rotates g→ to −Z
    • Rotates t→ to Y
    • Rotates (g→×t→) to X
    • Difficult to write!
  • Mview in math?

    • Let's write Mview=RviewTview
      • Translate e→ to origin:
        Tview=[100−xe010−ye001−ze0001]
      • Rotate g→ to −Z, t→ to Y, (g→×t^) to X
    • Consider its inverse rotation: X→(g→×t^),Y→t^,Z→−g→
Rview−1=[xg^×t^xt^x−g→0yg^×t^yt^y−g→0zg^×t^zt^z−g→00001]Rview=[xg^×t^yg^×t^zg^×t^0xt^yt^zt^0x−g→y−g→z−g→00001]

Also Known as ModelView Transformation

Projection Transformation ​

2Tppp5

Orthographic Projection ​

  • A simple way of understanding

    • Camera located at origin, looking at −Z, up at Y
    • Drop Z coordinate
    • Translate and scale the resulting rectangle to [−1,1]2
  • In general

    • We want to map a cuboid [l,r]×[b,t]×[f,n]
      to the "canonical" (正则, 规范, 标准) cube [−1,1]3.

MYF0T2

  • Transformation matrix

    • Translate (center to origin) first, then scale (length/width/height to 2)
    Mortho=[2r−l00002t−b00002n−f00001][100−r+l2010−t+b2001−n+f20001]

Perspective Projection ​

  • How to do perspective projection
    • First "squish" the frustum into a cuboid (n→n,f→f) (Mpersp→ortho)
    • Do orthographic projection (Mortho, already known!)

0fL3IX

  • In order to find a transformation

    • Find the relationship between transformed points (x′,y′,z′)
      and the original points (x,y,z):
    y′=nzyx′=nzx (similar to y′)

mKkiAs

  • In homogeneous coordinates,
(xyz1)⟹(nxznyzunknown1)(mult. by z)==(nxnystill unknownz)
  • So the "squish" (persp to ortho) projection does this
Mpersp→ortho(4×4)(xyz1)=(nxnyunknownz)
  • Already good enough to figure out part of Mpersp→ortho:
Mpersp→ortho=(n0000n00????0010)
  • Observation: the third row is responsible for z′

    • Any point on the near plane will not change
    • Any point’s z on the far plane will not change
  • Any point on the near plane will not change

Mpersp→ortho(4×4)(xyz1)=(nxnyunknownz)(replace z with n)⇒(xyn1)⇒(xyn1)=(nxnyn2n)
  • So the third row must be of the form (00AB)
(00AB)(xyn1)=n2n2 has nothing to do with x and y
  • Any point’s z on the far plane will not change
(00f1)⇒(00f1)=(00f2f)Af+B=f2
  • Solve for A and B:
An+B=n2Af+B=f2⇒A=n+f,B=−nf
  • Finally, every entry in Mpersp→ortho is known!
Mpersp→ortho=(n0000n0000n+f−nf0010)
  • What’s next?
    • Perform orthographic projection (Mortho) to finish.
    • Combine transformations:Mpersp=Mortho⋅Mpersp→ortho

Vertical field-of-view (fovY)

I2FFJe

How to convert from fovY and aspect to l,r,b,t?

ANPsS1