preface

This paper mainly summarizes the principle of view transformation, orthogonal projection transformation and perspective matrix derivation process. The derivation process was really difficult, but fortunately, IT was very fruitful. Finish flower ✿✿, (°▽°) blue. At the same time, thank you for the qi big guy enlighten the lesson.

Graphics Series:

  • Graphics 01 – Awesome vector and linear algebra
  • Graphics 02 – Weird 2D and 3D transformations
  • Graphics 03 – Challenge view, Projection transformation demon

View transformation

There are three steps: Model, view and projection.

How do I transform my view?

  • First you need to define the camera

    • Set position (origin)
    • Define the direction in which the camera looks (the direction of observation)
    • Define the upward direction
  • The key observation

    If the camera moves with all the objects, the “photo” will be the same.

    So we say, always keep the camera in a fixed position, everything else is moving, the camera is never moving, and the camera is always at the origin, always looking in the -z direction. And the camera is always going up on the Y-axis.

    By converting the camera:

    We always transform the camera to the origin, at Y, look at -z.

    The conversion process is as follows:

    become

    Steps:

    • Convert e to the origin
    • I’m going to rotate g to minus Z
    • I’m going to rotate t to Y
    • I’m going to rotate g x t to x

View/camera conversion

Steps:

  • The formula is as follows: translation followed by rotation.

  • Convert e to the origin

  • Rotate g to minus Z, t to Y, g x t to x. (Any axis, rotation to the specified axis, hard to write, let’s take the inverse transform, take the inverse transform, transpose it back)

  • Consider its inverse rotation: X to (g X t), Y to t, Z to -g

Projection transformation

Projection in computer graphics

  • 3 d and 2 d
  • Orthogonal projection
  • Perspective projection

Perspective projection vs. orthogonal projection:

Orthogonal projection

No matter far away or near, they all crowded onto a flat surface.

How do we understand orthogonal projections

Simple understanding:

  • The camera is at the origin, looking at -z, and the Y-axis is up.
  • Get rid of z
  • Translate and scale the resulting rectangle to [-1, 1]2

Usually on:

  • We want to map a cuboid [L, r] x [b, t] x [f, n] to the canonical (regular, canonical, standard) “cube [-1, 1]3

The order will vary (to the simple way) :

  • I translate the center cube
  • Scale to the “spec” cube

Matrix representation

First, move the center to the origin and then scale (divide the length, width and height by 2).

Warning:

  • Everything we’re talking about is looking at minus Z, so closer is bigger than farther.
  • That’s why OpenGL is left-handed.

Perspective projection

Perspective projection, most commonly found in computer graphics, art, and visual systems, supports near large and far small to satisfy this property, parallel lines are not parallel; Converges to a single point.

So just to review the properties of homogeneous coordinates that we’ll use in the next section.

  • (x, y, z, 1), ( kx, ky, kz, k ! = 0), (xz, yz, z2, z ! = 0) represents the same point (x, y, z) in 3D

  • For example, (1, 0, 0, 1) and (2, 0, 0, 2) both represent (1, 0, 0)

How to understand perspective projection

The points in the far plane are squeezed into the near plane, the sides are cuboids, and the orthogonal projection is done again. (From perspective to orthogonal)

Matrix is derived

  • Find a transformation

    • Recall the key idea: find the transformation point (x’, y’, z’) and the origin (x, y, z)

  • Based on the similar triangle principle, the corresponding relation between y’ and y is obtained

    So you get the relationship between the transformation point (x’, y’, z’) and the original point (x, y, z)

  • In homogeneous coordinates:

    So “squeeze” (perspective to ortho) projection is done this way

  • That’s enough to find part of Mpersp-> Ortho

  • Observation: third line z ‘

    • Nothing in the near plane is going to change
    • Z is not going to change at any point in the far plane

    Using the fact that no point in the near plane will change, the condition follows:

    • So the third row has to be 0, 0, A, B.

    • Now what we know is that

    • Similarly, using the fact that z at any point in the far plane does not change, this condition is derived:

    • So let’s solve for A and B

    • Finally, every entry in Mpersp-> Ortho is known
    • The last step is to do the orthogonal projection (Mortho) to finish