Archived

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

sc0rpy

lookat() my sad math skills

Recommended Posts

sc0rpy    122
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?

Share this post


Link to post
Share on other sites
WitchLord    4677
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 this post


Link to post
Share on other sites
sc0rpy    122
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 this post


Link to post
Share on other sites
WitchLord    4677
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 this post


Link to post
Share on other sites
sc0rpy    122
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 this post


Link to post
Share on other sites
Joviex    250
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"
}

Share this post


Link to post
Share on other sites
sixb0nes    122
joviex:
>> First off, those people ''where'' confused ...
before criticizing other people in the art of english,
check your spelling...

/sixb0nes

Share this post


Link to post
Share on other sites
a2k    124
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

Share this post


Link to post
Share on other sites