Camera/Viewing Transformation Matrix
I was wondering if someone can show me the steps into developing a 4x4 transformation matrix that can be used as the viewing transformation.
The camera is at (1, 2, 2)^T The camera is pointed at the direction (0, 1, 0)^T The up-vector, which will be mapped to the positive y direction on the image, is the direction (0; 0; 1)^T.
I've looked through my notes and do not understand how to solve these types of problems as I know they are quite common in co开发者_开发技巧mputer graphics.
You can use the formulas here, just filling in the matrices and multiply each matrix one after the other until you've built up your transformation matrix. (The rotation matrices there may be wrong so double check the formulas here.)
What type of problems are you trying to solve? You didn't really ask a narrow question.
The camera position would be set with a Translation matrix:
[1 0 0 X]
[0 1 0 Y]
[0 0 1 Z]
[0 0 0 1]
substituting [1,2,2]^T for [X,Y,Z]^T
would give you a Translation matrix:
[1 0 0 1]
[0 1 0 2]
[0 0 1 2]
[0 0 0 1]
This can be multiplied by an input vector
[x y z 1]^T
to transform that point, like so:
[1 0 0 1] [x] = x+1
[0 1 0 2] [y] = y+2
[0 0 1 2] [z] = z+2
[0 0 0 1] [1] = 1
For input vector [4,5,6,1] this would yield [5,7,8,1].
See, it just moves or translates the input x,y,z point by the X,Y,Z we plugged in above (ignoring the last component for now).
Remember that a matrix M multiplied by a vector v gives you a vector, call it p
p = M v
think of this as calling a function, sort of like p = sin(x) but instead p = M(v) where M is a transformation function, it happens to be in the form of matrix since the transformations we care about can be represented strictly by linear operators, a fancy way of saying a matrix multiplication, which is just a fancy way of saying the sum of 4 scalar multiplications. To chain these matrix transformations as if they were function calls, just multiply them one after another. (Note that this is a simplification since we need to do division to do perspective transformations, so that's why we cheat and do tricks with a 4x4 matrix instead of a just 3x3 -- that's what the weird term "homogeneneous coordinates" means.)
Does your class have a textbook or lecture notes (if it's online can you link to it)? I would imagine the materials would cover the other transformations and possibly provide examples. You can try it, multiply some vector v = [-9 -8 -7] by the 4x4 matrix above and see what [x y z w] vector you get out of it. Then try plugging in other values for the rotation matrices.
You may run in to tricky bits where you need to multiply the rotation matrix by the translation matrix in the right order: R T would be a different matrix than T R if the translation matrix is any other than 0,0,0.
精彩评论