View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# lookat() my sad math skills

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1sc0rpy  Members

Posted 13 April 2000 - 03:56 PM

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?

### #2Jewelaye  Members

Posted 14 April 2000 - 02:48 AM

?

JEWELAYE

### #3benjamin bunny  GDNet+

Posted 14 April 2000 - 03:17 AM

I agree.

### #4Andreas Jonsson  Moderators

Posted 14 April 2000 - 04:12 AM

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

### #5sc0rpy  Members

Posted 14 April 2000 - 06:27 AM

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

### #6Andreas Jonsson  Moderators

Posted 14 April 2000 - 07:07 AM

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

### #7sc0rpy  Members

Posted 14 April 2000 - 07:15 AM

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 .

### #8Joviex  Members

Posted 14 April 2000 - 07:21 AM

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.

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

### #9sc0rpy  Members

Posted 14 April 2000 - 07:33 AM

Spoken like a true American..

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

### #10sixb0nes  Members

Posted 16 April 2000 - 04:36 AM

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

/sixb0nes

### #11a2k  Members

Posted 16 April 2000 - 05:21 AM

oh, please, stop it everyone. the only syntax that matters here is opengl and c++. leave yer arrogance at home, no matter how subtle. i don''t care if you don''t know what i''m talking about, because apparently, those who don''t know of their own arrogance, are way too arrogant to realize it themselves. stop bickering, and program those kickass games.

nuff said.

a2k

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.