Jump to content
  • Advertisement
Sign in to follow this  
grumpyOldDude

GLU.gluLookAt( ... ) not working

This topic is 564 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A gremlin that gets rubbed in my face all the time is that i'm still using GL10. I'm going to sort that out later as the mechanics of other underlying code is complex enough and is keeping me extremely busy in other parts of the program.

 

In the mean time GLU.gluLookAt( cameraPosition, centreOfView, upDirection ) should still work.  But however much i change the parameters of the camera position and the centre of view - the object drawn doesn't shift a bit

 

Here is the GL code, something must be wrong with the order of the code. Does any one know? Thanks and Happy new year

 

BTW this is GLES on Android platform

		@Override
		   public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
		       gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);  
		       gl.glClearDepthf(1.0f);            
		       gl.glEnable(GL10.GL_DEPTH_TEST);   
		       gl.glDepthFunc(GL10.GL_LEQUAL);   
		       gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);  
		       gl.glShadeModel(GL10.GL_SMOOTH);        
    		       gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
		 
		   } 
		 
			@Override
		   public void onSurfaceChanged(GL10 gl, int width, int height) { 
			   if (height == 0) height = 1;  
			   float aspect = (float)width / height;
			   gl.glViewport(0, 0, width, height);			
			   gl.glMatrixMode(GL10.GL_PROJECTION); 
			   gl.glLoadIdentity();                 
		     		  			  
			   GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.0f);		
			   gl.glMatrixMode(GL10.GL_MODELVIEW);             
			   gl.glLoadIdentity();                 		
			   GLU.gluLookAt(gl,    0.0f, 6.0f, 0.0f,     0.0f, -6.0f, 0.0f,    0.0f, 1.0f, 0.0f);
		   } 
		 
			@Override
		   public void onDrawFrame(GL10 gl) { 
		     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
		     gl.glMatrixMode(GL10.GL_MODELVIEW); 
		     gl.glLoadIdentity();
		     
		     cPuzzle.setByteBuffers();
		     cPuzzle.rotateObj(gl);
		     cPuzzle.drawObj(gl);
		   } 

Share this post


Link to post
Share on other sites
Advertisement

Lookat can not be on a parallel line with your up vector. In short you cant look perfectly up and down. At least not with that up vector.

Edited by slicer4ever

Share this post


Link to post
Share on other sites

Good point Slicer, so I changed the direction, (like I did several times already, in fact it was too much 'changelings' that got me to that odd direction in the first place) to

GLU.gluLookAt(gl,    0.0f, 0.0f, 5.0f,     0.0f, 0.0f, -5.0f,    0.0f, 1.0f, 0.0f);

and

GLU.gluLookAt(gl,    0.0f, 0.0f, -5.0f,     0.0f, 0.0f, 0.0f,    0.0f, 1.0f, 0.0f);  and

GLU.gluLookAt(gl,    0.0f, 0.0f, 5.0f,     0.0f, 0.0f, 0.0f,    0.0f, 1.0f, 0.0f);

but the problem remains - the view is not changing. So there is still something fundamentally wrong with the sequence/order of the code which I can't figure out

Share this post


Link to post
Share on other sites
GLU.gluLookAt(gl, 0.0f, 6.0f, 0.0f, 0.0f, -6.0f, 0.0f, 0.0f, 1.0f, 0.0f);

Whats that gl for? I didn't know you could do that and I can't find an example.

ED: Nevermind, I just realized that wasn't c++ Edited by fleabay

Share this post


Link to post
Share on other sites

GLU.gluLookAt(gl, 0.0f, 6.0f, 0.0f, 0.0f, -6.0f, 0.0f, 0.0f, 1.0f, 0.0f);

Whats that gl for? I didn't know you could do that and I can't find an example.

ED: Nevermind, I just realized that wasn't c++

 

What 'gl' is for .... see documentation below

 

[attachment=34372:glu lookAt.jpg]

 

Still original problem remains unsolved,  view doesn't change on changing gluLookAt ( ... ) camera position and centre of view 

Share this post


Link to post
Share on other sites


What I'm seeing is the modelView matrix is being set to identity at draw, overwriting the matrix state set by lookAt in onSurfaceChange.

 

Thanks @[member='Goliath Forge'], so how can i fix it?

 

Share this post


Link to post
Share on other sites
What do you mean? Don't overwrite your matrix set by glLookAt. If you need additional model transforms after you get this part working, you'd be looking toward glPushMatrix, glPopMatrix, glMultMatrixf and friends. Or move to modern opengl.

Share this post


Link to post
Share on other sites

how could I use gluLookAt( ... ) effectively without causing an overwrite?

 

Like I said switching to modern GL is on the agenda, but in the current order of things the view change needs to be changeable first, thnx

Share this post


Link to post
Share on other sites

gluLookAt is not what's causing the overwrite.

 

Look at your code again.  In onSurfaceChanged you have this:

			   gl.glMatrixMode(GL10.GL_MODELVIEW);             
			   gl.glLoadIdentity();                 		
			   GLU.gluLookAt(gl,    0.0f, 6.0f, 0.0f,     0.0f, -6.0f, 0.0f,    0.0f, 1.0f, 0.0f);

In onDrawFrame you have this:

		     gl.glMatrixMode(GL10.GL_MODELVIEW); 
		     gl.glLoadIdentity();

So onDrawFrame is what's overwriting the matrix.  The solution is to remove those two lines from onDrawFrame.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!