Advertisement

Using gluLookAt() with Lesson 10 from Nehe's tutorials

Started by December 19, 2002 10:13 PM
1 comment, last by rm3 22 years, 2 months ago
I want to utilize Lionel Brits and nehe''s code in lesson 10 to render a sector of a 3D world. Everything works great, except that instead of using the rotation, translation, and variable management in the original code I want to use gluLookAt which I think is a lot cleaner. However using gluLookAt seems to mess up the way the vertices are pieced together... Can anyone tell me how I can make this code work. Virtually everything is the same from the original lesson 10 code except I replaced

	GLfloat xtrans = -xpos;
	GLfloat ztrans = -zpos;
	GLfloat ytrans = -walkbias-0.25f;
	GLfloat sceneroty = 360.0f - yrot;

	glRotatef(lookupdown,1.0f,0,0);
	glRotatef(sceneroty,0,1.0f,0);

	glTranslatef(xtrans, ytrans, ztrans);
 
with

	float cosYaw = cos_t[(int)xRot];
	float sinYaw = sin_t[(int)xRot];
	float sinPitch = sin_t[(int)yRot];

	float lookx = float(pos.x + cosYaw);
	float looky = float(pos.y + sinPitch);
	float lookz = float(pos.z + sinYaw);

	gluLookAt(pos.x, pos.y, pos.z,
			  lookx, looky, lookz, 
		      0.0, 1.0, 0.0);
 
The gluLookAt code works fine with other 3d things I''ve written, like drawing an environment from cubes. What can I do to make it work with this?
i did pretty much the same thing that you have done and it works fine for me. heres my code:

Mag= cos( Angle.x * piover180);
Targ.x = Mag * cos(Angle.y * piover180);
Targ.y = Mag * tan(Angle.x * piover180);
Targ.z = Mag * sin(Angle.y * piover180);

gluLookAt(Pos.x, Pos.y, Pos.z,
Targ.x, Targ.y, Targ.z,
0, 1, 0);

angle is a struct, if you didnt notice, and when ever a key is pressed it increments one of the values whether it be x or y.
if you need further describing tell me.
Advertisement
Thanks, but that didn''t do anything. My gluLookAt code works fine with other things. But I guess that by lacking the rotate and transforms from lionel brit''s code the triangles can''t be rendered right.

So still my question is open... how can I get this thing drawn right using gluLookAt? Or... if I can''t, how can I replace gluLookAt with a few rots/trans (even though I''d rather not ... =| )?

Thanks to anyone who replies!

This topic is closed to new replies.

Advertisement