Tutorial: The math behind the view transformation

Started by
20 comments, last by mhelvig 19 years, 1 month ago
I have been noticing that a lot of people don't understand very well how is made a view transformation. Some tutorials say that the camera position is transformed to the world coordinate system’s origin. This can confuse the people, if they don't know the math behind the view transformation. For this reason, I decided to write a simple tutorial explaining how a view matrix is created. Take a look at: www.adrianojmr.ubbi.com.br/viewtransf.doc Since the document has vectorial equations, it is recommended you have the MS Equation Editor installed in the Word. I hope it helps. Adriano Ribeiro [Edited by - adriano_usp on February 8, 2005 4:50:44 PM]
Advertisement
Great tutorial. I liked it, but you may end up confusing people more than helping :P
Quote:Great tutorial. I liked it, but you may end up confusing people more than helping :P


Why?... maybe because my English is terrible. [embarrass]

Thx your tutorial, I am reading now, and hope can help me to solve my problem, thx first
I have read your document, I can know more knowledge that World and Camera have its coordinates system, but when I read you document, I stop it in
"Since any vector can be expressed in relation to different coordinate systems." Becuase I don't know what you mean, why a vector will have relation will different coordinate system?
Quote:why a vector will have relation will different coordinate system?


Mathematically, a 3D vector can be defined (expressed) by a linear combination of other three independent vectors. These three vectors define a coordinate system. Well, since we can choose infinite groups of three independent vectors, we can generate infinite coordinate systems where one same vector can be expressed with different components.

For example: The T vector could be expressed in relation A, B, C,.. coord. systems, like this:
T = (Tax)ax + (Tay)ay + (Taz)az
T = (Tbx)bx + (Tby)by + (Tbz)bz
T = (Tcx)cx + (Tcy)cy + (Tcz)cz
...

where:
ax,ay and az are the unit vectors that define the A coord. system, and
Tax,Tay and Taz are the components of V when it is expressed in A. The same thought can be applied to the other coord. systems.

On that tutorial, I expressed one same vertice in relation to the world coord. system (W) and in relation to the camera coord. system (C) (what give me two different expression for the same vector). Why did I make that? Because using those two expression I can find a math relation that transforms vertex coordinates from one coord. system to another.
Well, that math relation is exactly the view matrix.

(Unfortunately, here I can't put an arrow on the caracters to represent vectors. This can confuse the explanation)


That tutorial requires some basic knowledge in lineal algebra and in analytic geometry. Did you know the math behind the dot product, cross product, transpose matrix, inverse matrix, product of matrices, etc?

If you don't understand or have other doubts, please ask again. I'll be happy to answering.
First of all, let's me to know the answer about that....

the camera coordinate, vlook, vUp, vRight must represent z-axis, y-axis and x-axis, right? These axis from the camera coordinate can different with the axis from the 3D world, right? Becasue the camera may be rotate, am I correct?
Quote:First of all, let's me to know the answer about that....

the camera coordinate, vlook, vUp, vRight must represent z-axis, y-axis and x-axis, right? These axis from the camera coordinate can different with the axis from the 3D world, right? Becasue the camera may be rotate, am I correct?


Almost that [smile].

For the camera:
z-axis = Normalize(pAt - pEye)
x-axis = Normalize(pUp x z-axis) <- this is a cross product
y-axis = (z-axis x x-axis) <- this is a cross product

pEye is the camera positon (camera's eye).
pAt is the camera target.
pUp is an orientation vetor for the camera.

These vectors are expressed in relation to world coordinate system. Don't worry about these terms... just keep in mind that you can treat the camera as an object. You only need to set the position of the camera, the target of the camera (where it points) and its orientation. Direct3D does the rest (it generate the axes from the camera coordinate system for you).

Answering the other question:
Yes, the axes from the camera coordinate system are different than the axes from the world coordinate system. But we practically only work with vectors expressed in the world coord. system. As I said, don't worry about the camera coordinate system.

Consider, for example, this code sample:

D3DXVECTOR3 pEye( 0.0f, 0.0f,-10.0f );
D3DXVECTOR3 pAt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 pUp( 0.0f, 1.0f, 0.0f );

D3DXMATRIX matR;
D3DXMatrixRotationY( &matR, 0.01f*timeGetTime());
D3DXVec3TransformCoord( &pEye, &pEye, &matR);

D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &pEye, &pAt, &pUp);
pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

Here I am rotating the position of the camera (pEye) around the origin. Notice that I treat the camera as an object, and all the vectors from that code sample were expressed in relation to world coord. system. You don't see the axes from the camera coord. system. In fact, they are generated by Direct3D (this is an intern operation).

[Edited by - adriano_usp on February 9, 2005 1:27:47 AM]
I want to ask a question?
the vUp is not the same as y-axis??

z-axis = Normalize(pAt - pEye)
x-axis = Normalize(pUp x z-axis) <- this is a cross product
y-axis = (z-axis x x-axis) <- this is a cross product
I'm not insulting your english [wink] What I meant was just that a lot of people run at the sight of math like that

This topic is closed to new replies.

Advertisement