#### Archived

This topic is now archived and is closed to further replies.

# lookat() my sad math skills

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

## Recommended Posts

Ok, some of you math psychos, incase you wanna show off your mad skills why not make a post describing why gluLookAt() (and mesa''s implementation of it) makes things "disappear" when the eye-position and the center point (reference point) and the world vector are all coincident. eg: your ''up'' vector is 0,1,0 your eye position is 0,10,0 your center (reference) is 0,0,0 you draw a cube at 0,0,0 the cube is invisible. if you change the x or z component of either the cube or the eye position, you can see the cube.. I''m not sure why it disappears tho. Mesa''s imp of lookat() has a comment : /* cross product gives area of parallelogram, which is < 1.0 for * non-perpendicular unit-length vectors; so normalize x, y here */ Is this the answer?

?

JEWELAYE

I agree.

##### Share on other sites
Here's how the view matrix is computed (pseudo code):

gluLookAt(Eye, Center, CameraUp);{  VECTOR Front = Normalize(Center - Eye);  // Compute an up vector that is perpendicular to Front  VECTOR Up = CameraUp - DotProduct(CameraUp, Front)*Front;  float Length = Magnitude(Up);  if( Length > 0 )    Up /= Length;  else  {    // The Camera up and front are parallel and we cannot compute its orientation  }  // If Up is zero length, then Right will also be zero length  VECTOR Right = CrossProduct(Up, Front);  MATRIX View;  View._11 = Right.x; View._12 = Right.y; View._13 = Right.z; View._14 = -DotProduct(Eye, Right);  View._21 =    Up.x; View._22 =    Up.y; View._23 =    Up.z; View._24 = -DotProduct(Eye, Up);  View._31 = Front.x; View._32 = Front.y; View._33 = Front.z; View._34 = -DotProduct(Eye, Front);  View._41 =       0; View._42 =       0; View._43 =       0; View._44 = 1;}

If the CameraUp vector is parallel to (Center-Eye) the algorithm above cannot compute any vector perpendicular to the Front vector of the camera, hence you will not see anything. It can be solved by guessing at the up vector but that way the programmer has no control over the orientation of the camera, so OpenGL don't do that and instead presumes that the programmer use proper arguments for the function call.

/
AJ

Edited by - WitchLord on 4/14/00 10:15:09 AM

##### Share on other sites
Thanks WitchLord. It semi-clarifies my question. Apparently the other 2 people had problems decyphering my question, hopefully your comments will enlighten them to my query.

The other question I have is.. If the magnitude of the UP vector is determined to be 0 (or as your comment states: // The Camera up and front are parallel)
how would a person compensate for that, or correct the problem.

IMHO it''s logical to assume that the camera could fly above an object and look directly down upon the object forcing that up vector to make the object disappear. Would you in that case ''tweak'' the up vector so the object wouldn''t disappear or would you simply not allow the camera to fly to that sort of coordinate system?

Oddly enough I don''t remember having this problem in D3D, I wonder if it does something internally to compensate for this problem...

##### Share on other sites
D3D does indeed do something internally to compensate for the parallelity: If the length of the internal up vector is determined to be zero, it uses (0,1,0) instead and retests for parallelity. If that doesn''t work either it uses (1,0,0). This time it will work since both cannot be parallel to the front vector.

So in your case you always use (0,1,0) for camera up vector but when that camera is looking directly up or down you''ll have to use another up vector for example (1,0,0).

You can see the implementation that Direct3D uses in d3dutil.cpp which comes with the SDK. The function you should look at is D3DUtil_SetViewMatrix().

/
AJ

##### Share on other sites
Thanks again WitchLord.

Once again I am your servant.

Goes to show ya how much more advanced you Europeans are in mathematics against us NorthAmericans.

There are exceptions tho, but I know I am NOT one of them .

##### Share on other sites
quote:
Original post by sc0rpy

Thanks again WitchLord.

Once again I am your servant.

Goes to show ya how much more advanced you Europeans are in mathematics against us NorthAmericans.

There are exceptions tho, but I know I am NOT one of them .

First off, those people where confused since you obviously don''t know english either.

Secondly, no thanks, I don''t need you speaking for my North American math skills.

Thirdly, why not spend some time reading about vectors and matricies before asking a convoluted question.

int main() {
while(true) {
int*ptr=new int[1000000];
}
}
else std::cout<< "amorano"
}

##### Share on other sites
Spoken like a true American..

If I wanted your opinion I''d give you one.

##### Share on other sites
joviex:
>> First off, those people ''where'' confused ...
before criticizing other people in the art of english,

/sixb0nes

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013719
×