2

In the description of the Function D3DXMatrixLookAtLH(), the x-axis is equals to " normal( cross ( UpVec , z-axis ) ) " since we know that z-axis is the result of normal( AtVec - EyePosVec ) , most of time , we can calculate the matrix without any problem.

However , UpVec is usually( 0 , 1 , 0 ) , under a special circumstance , the z-axis and UpVec can be paralleled . So ( I think )we can not build a right camera basis because the y-axis and x-axis will be zero vectors . So , how can we fix this ? or I have something wrong ?

zdd
  • 8,258
  • 8
  • 46
  • 75
ZengCheng
  • 23
  • 3

2 Answers2

2

In order to define a view transformation you need to calculate an orthonormal base. This is a set of base vectors that are perpendicular to each other and that have unit length.

The unit length criterion can be easily achieved by normalizing the vectors.

The cross product is used to make the vectors orthogonal. As you already mentioned, the x-vector is orthogonalized first and afterwards the up-vector is recalculated by orthogonalizing it.

The x-axis (right direction) is always dependent on the view direction and the up vector. If we assume an up-vector of (0, 1, 0), then the x-axis only depends on the view direction. Here are some examples (the view direction is always in the same plane)

View visualization

You see that the right vector flips when the view direction passes through the up vector and changes its side. That's the reason why the calculation fails if up vector and view direction are parallel. There is no way to determine where the right vector should point to (resulting in a zero cross product). If you render a scene with these vectors, you will notice that the image will flip horizontally when the view direction passes the up vector.

If you want to specify a view direction parallel to the y-axis, you have to provide a non-parallel up vector. With this it is possible to calculate a reasonable right vector.

Of course, you can calculate the up vector if you want to fix a certain right vector with up = cross(direction, right).

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • You mentioned that I Can provide the up vector by myself when the view direction parallel to the y-axis. It helps a lot. But one more question here : I just provide a non-parallel up vector whatever I like? or is there some prior choice like (0 , 1 , 0) when the view direction is not parallel to the y-axis? – ZengCheng Aug 19 '13 at 11:17
  • The up-vector you provide will point to the top of the screen after projection. Basically, it's the roll rotation of a camera. – Nico Schertler Aug 19 '13 at 11:48
1

So ( I think )we can not build a right camera basis because the y-axis and x-axis will be zero vectors .

Yes, this will happen when you make a special case as below.

lookAt = D3DXVector3(0, 0, 0);
eyePos = D3DXVector3(0, Y, 0);

to put it exactly, the result is not an incorrect matrix, it's just a matrix you will see noting of your scene with it.

So , how can we fix this ?

You should take the response to prevent this happen.

zdd
  • 8,258
  • 8
  • 46
  • 75