Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

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


Sign up now

gluLookAt()

4: Adsense

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.


  • You cannot reply to this topic
6 replies to this topic

#1 ff8   Members   

134
Like
0Likes
Like

Posted 18 June 2005 - 02:42 AM

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
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;
}

i use the same gluLookAt's code . bye

#2 phantom   Members   

11218
Like
0Likes
Like

Posted 18 June 2005 - 03:53 AM

an image of how they look different might be usefull... or at least some numbers for the final modelview matrix...

#3 ff8   Members   

134
Like
0Likes
Like

Posted 18 June 2005 - 04:19 AM

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]

#4 Gorax   Members   

202
Like
0Likes
Like

Posted 18 June 2005 - 04:29 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. ;)


//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);
}



#5 python_regious   Members   

929
Like
0Likes
Like

Posted 18 June 2005 - 04:39 AM

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 ]

If at first you don't succeed, redefine success.

#6 ff8   Members   

134
Like
0Likes
Like

Posted 18 June 2005 - 04:45 AM

hi
what are P.S,P.U and P.F ??and how can i calculate them ??

#7 python_regious   Members   

929
Like
0Likes
Like

Posted 18 June 2005 - 04:49 AM

P is the position vector, so P.U would be, well, P dot U.
If at first you don't succeed, redefine success.




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.