gluLookAt confusing me??

Started by
8 comments, last by kburkhart84 19 years, 1 month ago
Hi, I have been reading the OpenGl programmers guide v1.1. In my program I am just drawing a simple rectangle, and experimenting with gluLookAt and glTranslatef. Here's my code :

	gluLookAt(-0.25,-0.25,0.0, 0.0,0.0,0.0, 0.0,0.0,0.0);

	//glTranslatef(0.25,0.25,0.0);

	glBegin(GL_POLYGON);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(0.5,0.0,0.0);
		glVertex3f(0.5,0.5,0.0);
		glVertex3f(0.0,0.5,0.0);
	glEnd();
I have read in the book that glTranslatef can be used inplace of gluLookAt . But here when I use gluLookAt in place of glTranslatef it does not give me the same effect. Can somebody pls explain me where I am going wrong? Thanks. --eminemence.
You cannot build character and courage by taking away a person's initiative and independence. -Benjamin Franklin
Advertisement
Well, you missing the second and third triad of parameters.

1th triad - position of your eye
2nd triad - point you looking at (try: [0,0,-1 or 1])
3rd triad - up vector (try: [0,1,0])
Well I tried this:
gluLookAt(-0.25,-0.25,0.0, 0.0,0.0,1.0, 0.0,1.0,0.0);
And the result is that now i can see the rect but it seems to have scaled
instead of translating..
Thanks.
--eminemence.
You cannot build character and courage by taking away a person's initiative and independence. -Benjamin Franklin
Quote:Original post by eminemence
Well I tried this:
gluLookAt(-0.25,-0.25,0.0, 0.0,0.0,1.0, 0.0,1.0,0.0);
And the result is that now i can see the rect but it seems to have scaled
instead of translating..
Thanks.
--eminemence.


Are you trying to position the polygon? If so glLookAt() will not do that you need to use glTranslatef() to move the polygons around. Also your polygons will look scaled if you are using gluPerspective() vs. glOrtho(). So if you are away from the polygon a bit, it will look smaller until you move up on it. HTH?
gluLookAt combines a few rotations and translation depending on the parameters. It is used to position and rotate the camera, not the polygons. The first 3 params are a vector that represents where the camera is position. The second is a vector that represents a point that the camera is looking at. In front of the camera. The third is the vector representing UP usually up is 0, 1, 0 but if you roll in 3d up may very well be 0, -1, 0 if you are actually upside down. The function then translates and rotates the camera to get what you are looking for.


Is there any benefit to doing the matrix math yourself? I downloaded a demo w/source code, and the programmer wrote his own matrix library for 4x4 matrices....

I'm new to OpenGL (used to be/still am a Direct3D guy).... are there equivalent functions for doing matrix stuff like there is with D3DX?
Quote:Original post by WilyCoder
are there equivalent functions for doing matrix stuff like there is with D3DX?


Not really. There are a few functions to set rotations etc within OpenGL, but if you need the matrices for anything else you have to read them back from the driver, which is a pain. I have always used my own matrix functions.
You can use your matrices or use rotation/scale etc.. functions within OpenGL. However, combining them isn't always pretty. I usually see it one way or the other.


Quote:Is there any benefit to doing the matrix math yourself?

speedwise no, though its useful sometimes to know what matrix the scene is viewing (hmm exmplained bad)

Quote:I have read in the book that glTranslatef can be used inplace of gluLookAt

no, with translate u dont 'really' supply a difrection
**no, with translate u dont 'really' supply a difrection**
translate can be used instead of gluLookAt, but you have to glRotate as well. gluLookAt basicly does this anyway.About using your own matrices, the only thing I ever need to add my own matrix for is shadows(I think the technique is called projective shadows). You create a shadow matrix based on the position of a light and a plane. Then you translate like normal, glMultMatrix(the matrix), then draw like normal(black, no texture, blended, maybe offset a little from the plane), this matrix basicly plasters all the vertices onto the plane according to the light position. This is the only technique I use my own matrices for. In order to use quaternions, you would have to use your own matrices as well, but I haven't needed quats yet. For either of these cases, you don't have to retrieve the current matrix. Just MultMatrix and OpenGL does it for you. If there is a great need to get the matrix, it may be faster to implement your own, but I dn't have a use for that as of yet, maybe for physics calculations or something like that.


This topic is closed to new replies.

Advertisement