This post is a reading note of Chatper 5: Geometry for 3D Engine in the book Mathematics for 3D Game Programming and Computer Graphics, Third Edition.
Lines in 3D Space
Lines or segments can be represented in two ways:
Or
The distance between a point \(Q\) and a line is given by
Planes in 3D Space
Plane Equation
A plane can be determined by a point \(P\) and a normal vector \(N\). The equation is:
If we write the euqation in coordinates, i.e. let \(Q = (x, y, z) \), then we have
where
Suppose we have \( \lVert N \rVert = 1 \) and let \( d = N \cdot Q + D \). Then d is a signed distance between the point \(Q\) and the plane. With simple calculation, we can derive that \( \frac{|D|}{\lVert N \rVert} \) is the distance between the origin and the plan.
Four-dimensional Vector of Plane
Suppose we are using the homogeneous coordinates of the point \(Q\), which is \( Q = (x, y, z, 1) \). Now, we can represent the plane using the four-dimensional vector
where \(N\) is the normal vection and \(D = -N \cdot P\).
If \(Q\) is on the plane, then we will have
Plan Transformation
Suppose we have a four-dimensional transformation matrix and a plane \(L = \langle N, D \rangle\). We want to know the plane expression after the transformation.
Recall that there are two types of vectors
- contravariant vectors: vectors that are transformed in the ordinary fashion using the matrix \(M\), such as points and tagent vectors.
- covariant vectors: for example, normal vectors.
For normal vectors, the effective transformation matrix is \( G = (M^{-1})^{T} \). Therefore
To calculate \( D' \), we can use the formula
It can be shown that
And it turns out we have
which gives us:
Note: We can see that the plane vector \( L = \langle N, D \rangle \) is a covariatne vector.
Projection Plane and Frustum
To render a 3D scene, we need a projection plane and a frustum. The projection plane is used to display the 2D view of the scene and the frustum defines a space where objects are considered visible. Note that the view frustum is aligned to camera space, where the camera lies at the origin.
Definition: The projection plane is a plane that is perpendicular to the camera's viewing direction and lies at the distance \(e\) from the camera where the left and right frustum planes intersect it at \( x = -1 \) and \( x = 1 \).
Here are the basic concept related to the projection plane
- The focal length the distance between the origin and the projection plane.
- The horizontal field of view angle: This is the angle formed between the left and right frustum plane.
- The vertical field of view angle.
- The aspect ratio: this is the ratio of height to width.
projection plane
The view frustum has 6 planes: left, right, top, bottom, near and far. It "shares" the horizontal/vertical view angle with the projection plane.
view frustum
In the diagram below, we have the projection plane colored in blue and the near plane of the view frustum colored in orange.
Perspective Projection
The idea is to map the points in the view frustum to a cube. We need a cube because we want to keep track of the z coordinate of objects so that we can determine if an object is hidden behind another one. \(x\) and \(y\) coordinates are easy to map. \(z\) coordinate mapping needs some consideration. The reason is that we need to implement perspective-correct interpolation, which is in the form of
Here is the form of the transformation matrix:
----- END -----
©2019 - 2022 all rights reserved