Matrix algbera question for Projection matricies

markraz

Full Member
Joined
Feb 19, 2014
Messages
338
I have a bunch of questions:

I'm trying to write a 3d game in C++. I have no problems with 2d matrices but 3d is giving me some trouble since I am mildly retarded. If I have a bunch of vectors that will represent vertices of the polygon data and I want to ultimately view them in 3D. I want to be to view this data in various projections mode i.e. orthographic and perspective for starters. I apparently have to multiply the vectors by various projection matrices to obtain these ortho and persp views. To view in 3D I think I have to project to 2D since pc screen is 2d.

My first question is:

1. To obtain various ortho views (front side top) do I ultimately have to transform the vectors to represent a particular view? So I'm not really moving an imaginary "camera" or "eye" perse am I really ultimately just rotating the vectors(vertices) to project in different views? giving an illusion that I move a camera or 'eye'?? is that correct?

2. What would these projection matrices look like? would front be 1 1 0 ? and side be 1 0 1 and top be 0 1 1?

Front
1 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1

side
1 0 0 0
0 0 0 0
0 0 1 0
0 0 0 1

top
0 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

then multiply either of these times a 3d vector?

x
y
z
1

is that how they do it? thank you so much math friends
 
Last edited:
Your "3D vectors" are really what are called "projective" (not "projection") coordinates: the vector (x, y, z) is represented by (x, y, z, 1) with the understanding that if any operation results in that last component being non-zero, we divide by it. That is, (x, y, z, a) is the same vector as (x/a, y/a, z/a, 1).

The point of that, especially in computer graphics, is that we can include translations as matrix operations the same as rotations. The rotation, around the z-axis, through angle \(\displaystyle \theta\) is given by \(\displaystyle \begin{bmatrix}cos(\theta) & - sin(\theta) & 0 \\ sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}x \\ y \\ z\end{bmatrix}\) in projective form would be \(\displaystyle \begin{bmatrix}cos(\theta) & - sin(\theta) & 0 & 0 \\ sin(\theta) & cos(\theta) & 0 & 0\\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1\end{bmatrix}\begin{bmatrix}x \\ y \\ z \\ 1 \end{bmatrix}\) and the translation that maps \(\displaystyle (x_0, y_0, z_0)\) to \(\displaystyle (0, 0, 0)\) which, in vector form would be \(\displaystyle <x- x_0, y- y_0, z- z_0>\), in projective form would be \(\displaystyle \begin{bmatrix}1 & 0 & 0 & -x_0 \\ 0 & 1 & 0 & -y_0\\0 & 0& 1 & -z_0 \\ 0 & 0 & 0 & 1\end{bmatrix}\begin{bmatrix}x \\ y \\ z \\ 1 \end{bmatrix}\).

To rotate around the z-axis, through angle \(\displaystyle \theta\), about the point \(\displaystyle (x_0, y_0, z_0)\), first translate so that \(\displaystyle (x_0, y_0, z_0)\) is moved to the origin, rotate around the origin, and then translate back. That can be done by matrix multiplication of the projective matrices for each operation:
\(\displaystyle \begin{bmatrix}1 & 0 & 0 & x_0 \\ 0 & 1 & 0 & y_0 \\ 0 & 0 & 1 & z_0 \\ 0 & 0 & 0 & 1\end{bmatrix}\begin{bmatrix}cos(\theta) & -sin(\theta) & 0 & 0 \\ sin(theta) & cos(\theta) & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1\end{bmatrix}\begin{bmatrix}1 & 0 & 0 & -x_0 \\ 0 & 1 & 0 & -y_0 \\ 0 & 0 & 1 & -z_0 \\ 0 & 0 & 0 & 1\end{bmatrix}\begin{bmatrix}x \\ y \\ z \\ 1\end{bmatrix}\).

(To rotate around the y-axis rather than the z-axis, use \(\displaystyle \begin{bmatrix}cos(\theta) & 0 & -sin(\theta) & 0 \\ 0 & 1 & 0 & 0 \\ sin(\theta) & 0 & cos(\theta) & 0 \\ 0 & 0 & 0 & 1\end{bmatrix}\) and around the x-axis, \(\displaystyle \begin{bmatrix}1 & 0 & 0 & 0 \\ 0 & cos(\theta) & -sin(\theta) & 0 \\ 0 & sin(\theta) & cos(\theta) & \\ 0 & 0 & 0 & 1\end{bmatrix}\). Rotations around other axes can be analyzed as combinations of rotations around the x, y, and z-axes: rotate around the z-axis so that the y-axis is rotated to the projection of the given axis of rotation, then rotate around the x-axis so that the y-axis is rotated to the given axis of rotation, rotate everything around the new y-axis the desired angle. then rotate back.)
 
Last edited:
Top