template <class T> view<T> &view<T>::LookAt(T eX,T eY,T eZ,
T cX,T cY,T cZ,
T uX,T uY,T uZ){
Unit();
V3D F,UP,s,u;
UP.set(uX,uY,uZ);
F.set(eX-cX,eY-cY,eZ-cZ);
F.normal();
s.CrossProduct(UP,F);
u.CrossProduct(F,s);
s.normalize();
u.normalize();
this->arrMat[0]=s.x;
this->arrMat[1]=s.y;
this->arrMat[2]=s.z;
this->arrMat[4]=u.x;
this->arrMat[5]=u.y;
this->arrMat[6]=u.z;
this->arrMat[8]=F.x;
this->arrMat[9]=F.y;
this->arrMat[10]=F.z;
this->MultMatrix();
this->Translate(-eX,-eY,-eZ);
return *this;
}
gluLookAt()
Hi, i am tring to make gluLookAt function to use it in my class but i face some problem like when i use gluLookAt(...) it give me a result and when i use my own test.LookAt(...) same value diffrent result
i use the same gluLookAt's code .
bye
an image of how they look different might be usefull... or at least some numbers for the final modelview matrix...
hi,
when i use
gluLookAt(0,0,0,0,0,-1,0,1,0);
it works and i can see my triangle
and this is the modelview matrix after gluLookAt
0.894427 0 -0.447214 0
0 1 0 0
0.447214 0 0.894427 0
0.894427 0 -0.447214 1
but when i use
test.LookAt(0,0,0,0,0,-1,0,1,0);
empty scene the triangle dosen't show up :(
and this is the modelview matrix after test.LookAt
0 0 0 0
0 0 0 0
-0.4 0 0.8 0
0 0 0 1
[Edited by - ff8 on June 18, 2005 10:19:22 AM]
when i use
gluLookAt(0,0,0,0,0,-1,0,1,0);
it works and i can see my triangle
and this is the modelview matrix after gluLookAt
0.894427 0 -0.447214 0
0 1 0 0
0.447214 0 0.894427 0
0.894427 0 -0.447214 1
but when i use
test.LookAt(0,0,0,0,0,-1,0,1,0);
empty scene the triangle dosen't show up :(
and this is the modelview matrix after test.LookAt
0 0 0 0
0 0 0 0
-0.4 0 0.8 0
0 0 0 1
[Edited by - ff8 on June 18, 2005 10:19:22 AM]
I wrote this code to replace gluLookAt() ages ago. Virtually the same thing, 'cept it uses trigonometry instead of matrix operations, and you can get the rotations on the x and y axiis for sprites. ;)
[EDIT]
If you don't need the rotational values, you can always remove the 'rs' bit, or use this:
//THIS IS A REPLACEMENT FOR gluLookAt.//It requires 1 less argument (the 'up' vector), because the positive Y axis is//always 'up', unless you rotate it on the Z axis, which you can do on your own.//It will also fill the array with the rotation angles, that way you can counter-//rotate things like sprites.GLvoid doLookAtR(GLdouble eyeX,GLdouble eyeY,GLdouble eyeZ,GLdouble centerX,GLdouble centerY,GLdouble centerZ,GLdouble* rs){ GLdouble x = eyeX - centerX; GLdouble y = eyeY - centerY; GLdouble z = eyeZ - centerZ; //lengths = 0, no difference = no rotation if ((x == y) && (y == z) && (z == 0.0f)) return; //if looking straight up or down (fix for the gimbal lock - as found in gluLookAt) if ((x == z) && (z == 0.0f)){ if (y < 0.0f){//if looking straight up glRotated(-90.0f,1,0,0); }else{//if looking straight down glRotated(+90.0f,1,0,0); } glTranslated(-x,-y,-z); return; } GLdouble rx = 0.0f; GLdouble ry = 0.0f; GLdouble hypA = (x == 0.0f) ? z : hypot(x,z); GLdouble hypB = (y == 0.0f) ? hypA : hypot(y,hypA); if (z == 0.0f) hypB = hypot(x,y); rx = toDegs(asin(y / hypB)); ry = toDegs(asin(x / hypA)); //rotate and translate accordingly glRotated(rx,1,0,0); if (z < 0.0f){ ry += 180.0f; }else{ ry = 360.0f - ry; } glRotated(ry,0,1,0); glTranslated(-eyeX,-eyeY,-eyeZ); if (rs){ rs[0] = rx; rs[1] = ry; }}
[EDIT]
If you don't need the rotational values, you can always remove the 'rs' bit, or use this:
GLvoid doLookAt(GLdouble eyeX,GLdouble eyeY,GLdouble eyeZ,GLdouble centerX,GLdouble centerY,GLdouble centerZ){ return doLookAtR(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,0);}
Quote:Original post by ff8
Hi, i am tring to make gluLookAt function to use it in my class but i face some problem like when i use gluLookAt(...) it give me a result and when i use my own test.LookAt(...) same value diffrent result
*** Source Snippet Removed ***
i use the same gluLookAt's code .
bye
Your rotation matrix isn't correct, you want the inverse of that. Or, in full, including the translation:
[ Sx Sy Sz -P.S ][ Ux Uy Uz -P.U ][ Fx Fy Fz -P.F ][ 0 0 0 1 ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement