Advertisement

lookat() my sad math skills

Started by April 13, 2000 09:56 PM
9 comments, last by sc0rpy 24 years, 7 months ago
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?
This Space Left Blank
?

JEWELAYE
Jewelaye
Advertisement
I agree.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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...

This Space Left Blank
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
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 .



This Space Left Blank
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() {
if(reply.IsSpam()) {
while(true) {
int*ptr=new int[1000000];
reply.RandomInsult();
}
}
else std::cout<< "amorano"
}
Spoken like a true American..


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

This Space Left Blank
joviex:
>> First off, those people ''where'' confused ...
before criticizing other people in the art of english,
check your spelling...

/sixb0nes
sixb0neshttp://www.xpression.ca

This topic is closed to new replies.

Advertisement