Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to draw simple model, but I am experiencing strange error. When I use this View matrix:

Matrix.CreateLookAt(new Vector3(0, 200, 1), new Vector3(0, 0, 0), Vector3.Up);

my model is drawn correctly. But when I set camera position Z to 0 like this:

Matrix.CreateLookAt(new Vector3(0, 200, 0), new Vector3(0, 0, 0), Vector3.Up);

nothing is rendered. Why?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

This is probably because your up vector is exactly opposite to the eye vector in the second example. This makes the cross product, which is used to calculate the view matrix unreliable (for a lack of a better word).

EDIT: If this is not enough information, then you should read up on how a view matrix is calculated. You need three things to do that, an eye vector, an up vector and the camera position. Then the cross product is used to calculate a 4x4 matrix which transforms your points from world space into camera space. In the CreateLookAt function, the eye vector is calculated simply by subtracting the target position from the camera position, then normalizing the result.

So in your second example, the calculated eye vector is pointing straight down, while the up vector is pointing straight up. This means that you can't calculate the cross product between the eye vector and the up vector, which means that the view matrix can't be constructed. I say "can't", it can, but you get errors.

share|improve this answer
    
In the second case the result is undefined, as there is an unlimited amount of solutions or more exactly there is no solution where the requested up vector is pointing up in the resulting matrix. Basically the same problem as in (gamedev.stackexchange.com/questions/45280/…) any many other questsions on se. –  Archy Dec 10 '12 at 13:59
    
thanks I missed this :-) –  Vodáček Dec 10 '12 at 14:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.