Jump to content
  • Advertisement
Sign in to follow this  

I want to explain this 2 myself.help plz :)

This topic is 4421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to understand the viewing transformation that takes place in the pipeline. In directX , the view matrix is built as follows as i read fromm the help file: zaxis = normal(cameraTarget - cameraPosition) xaxis = normal(cross(cameraUpVector, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y zaxis.y 0 xaxis.z yaxis.z zaxis.z 0 -dot(xaxis,cameraPosition) -dot(yaxis,cameraPosition) -dot(zaxis,camera_posn) 1 see: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m_dec_2004/directx/ref/ns/microsoft.directx/s/matrix/m/lookatlh.asp the first 3 rows are , i feel, required to shift the individual components of the vertex in that dimension depending on how much each axis has shifted in that dimension.Eg, the X part of the vertex should be shifted based on the X components of the 3 axis in the new viewing co-ordinate system. But please explain me the reason for the last row of teh matrix as i am unable to imagine it in any way . I want to know why it is required. Why is it important?? thanks mishal

Share this post

Link to post
Share on other sites
Original post by mishal153
zaxis = normal(cameraTarget - cameraPosition)
xaxis = normal(cross(cameraUpVector, zaxis))
yaxis = cross(zaxis, xaxis)

xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis,cameraPosition) -dot(yaxis,cameraPosition) -dot(zaxis,camera_posn) 1
This demonstrates some of the ideas involved in constructing a view matrix, but note that it isn't 'the' view matrix; rather, it's a particular type of view matrix construction, usually called a 'look at' matrix.

In the most general sense, a view matrix simply transforms geometry into a space that is suitable for projection and viewport calculations. The usual convention is for +x to be to the right and +y to be up in this space; +z may go 'into' or 'out of' the screen, depending on the convention being used.

How the geometry gets transformed into this space is up to the programmer, more or less, but it's common to use a transformation consisting only of rotation and translation that can be thought of as the local coordinate system of a virtual camera.

The actual contruction of the above matrix (-dot(p,x) and all that) has to do with matrix inversion. A typical 'model' or 'world' matrix transforms geometry from local space to parent space; since a 'view' matrix is usually intended to do the opposite, we construct it by inverting the model matrix associated with the camera.

Share this post

Link to post
Share on other sites
--disclamer, someone should double check this since im not sure why -dot is in there... and why it isn't just camPosition.xyz ...

xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis,cameraPosition) -dot(yaxis,cameraPosition) -dot(zaxis,camera_posn) 1

Expanding on that...
the ?axis.? part makes up a 3x3 rotation matrix.
In a non-rotated ortho-normal basis the columns of this matrix are x,y,z.
These x,y,z can be scaled to enlongate any axis, and as such don't have to be unit vectors.
In a rotated ortho-normal basis, the colums are x',y',z'. These are perpendicular to eachother(ortho-normal) and are the
inversely(?) rotated xyz triplet that represents your new rotated object coordinate system.
If the x'y'z' are not perpendicular, then you have something like the projection matrix, that causes the image to fish-eye or zoom.

in the 4x4 matrix
the last row should be representing the translation away from the origin.
the last column should be the "w" coordinate which is part of the "affine transformation" part of the 3d math (someone else will have to explain this
better, but it affects how it transforms points and vectors)

[Edited by - KulSeran on June 9, 2006 6:30:01 PM]

Share this post

Link to post
Share on other sites
If you define a matrix with these axis's

xAxis.x yAxis.x zAxis.x
xAxis.y yAxis.y zAxis.y
xAxis.z yAxis.z zAxis.z

You'll see that you have three vector's in each column, the xAxis vector, the yAxis vector and the zAxis vector. These vector's as the name points out defines the vector for each axis in your world, if there is no rotation you should have these axis's(normal cartesian axis) x = <1,0,0> y = <0,1,0> and z<0,0,1> to give you this matrix

1 0 0
0 1 0
0 0 1

Now say you want the world rotated on the zAxis by 90 degree's, well rotating the x vector by 90 degree's will give have it pointing up at <0,1,0> and the y axis pointing left at <-1,0,0> so your new matrix will be

0, 1 0
-1 0 0
0, 0 1

Now to build a camera class you want take your camera's orientation and build your axis's based on it's orientation, so if your camera was simply rotated to point down 90 degree's you would use the above matrix to rotate the axis back to the origin.

So to do this, we can build a matrix called the look at matrix based on three variables the camera's eye position, what the camera is looking at(how far away it is) and the camera's up vector.

So the easiest axis to make is the z axis(which way the camera is pointing at). Take the position of the camera and subtract it from what its looking at so

zAxis = vEye - vAt;

*Note: You must do from Eye - At not At - Eye, to give you a backwards vector because you always want to build your matrix rotation opposite the way the camera is rotating, remember the transformation pipeline is about bringing vertices back to the origin to render.

Once we have the zAxis we can get the right axis or xAxis by doing the cross product of the camera's up vector with the zAxis.

xAxis = cross( vUp, zAxis )
normalize( xAxis )

The last axis remaining is the yAxis, since we have the z and x, z cross x will give us y.

yAxis = cross( zAxis, xAxis )
normalize( yAxis )

So now we have built our axis matrix, the last thing we need to take into consideration is the translation vector of the matrix. In row major the translation vector is across the bottom on _41, _42, _43. If we want to get the distance of how far the at point is from our camera, we can simply project the eye vector onto each of our axis's. Projecting these points will give us the displacement on each axis. The last step is to negate these components because we need to translate back to the origin, everything is always backwards.


_41 = -dot(xAxis, eye), _42 = -dot(yAxis, eye), _43 = -dot(zAxis, eye).

Once you have this matrix if you want to translate the camera further, you simply add your -translatioin vector onto that last row.

Also one last note, these axis matrices I've been refering to all along are actually rotation matrices in disguise. If you plug in numbers for a rotation matrix with 0 angle you'll get the identity matrix, or the three x,y,z axis. If you plug in 90 degree's you'll get the matrix I showed above.

Hope that helped

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!