Advertisement

OpenGL PICKING won't work with gluLookAt()

Started by February 17, 2003 08:52 PM
3 comments, last by v0rtex 22 years ago
Hello, I have been looking for an answer to my problem round the web and I couldnt find it yet. The problem is that I switch to selection mode, and I draw my targets (objects to pick), everything works ok but... If I move the camera it doesnt work!.... (I can pick where there are no objects, etc)... plz help me, I paste some code: =========================================================== CODE START :: pick(int x, int y) =========================================================== if(!Landscape.IsLoaded()) return; GLuint buffer[512]; // Set Up A Selection Buffer GLint hits; // The Number Of Objects That We Selected GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(512, buffer); glRenderMode(GL_SELECT); glInitNames(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3]-y), 1.0f, 1.0f, viewport); gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 300.0f); // draw glMatrixMode(GL_MODELVIEW); // look trough camera Camera.Look(); Landscape.Render(); // Select & Pop glMatrixMode(GL_PROJECTION); glPopMatrix(); // Set render mode glMatrixMode(GL_MODELVIEW); hits = glRenderMode(GL_RENDER); if(hits) MessageBox(NULL,"I''m hit!",NULL,0); =========================================================== CODE END =========================================================== Where is the error... help!! Lords of Genesis | 3D Online RPG in development http://www.lordsofgenesis.tk
Lords of Genesis | 3D Online RPG in developmenthttp://www.lordsofgenesis.tk
Does Render assign a name for each object?

Cause you selection buffer looks local.

[edited by - bgcjr on February 18, 2003 9:38:10 AM]
Game Core
Advertisement
The buffer is local, and the names are pushed and popped in the Landscape.Render() function.
I''m not checking for the pushed name, I''m just checking if there was a hit or not, and I get hits even when I dont click in an object.

PS: I added glLoadIdentity() after
// draw
glMatrixMode(GL_MODELVIEW);
and it works a little better now, but it doesnt work ok yet.

Lords of Genesis | 3D Online RPG in development
http://www.lordsofgenesis.tk
Lords of Genesis | 3D Online RPG in developmenthttp://www.lordsofgenesis.tk
Don''t call gluLookAt() when doing the picking. Just call it when you render normaly. E.g:
Camera.Look();Landscape.Render();pick(); 


And in pick(), remove the Camera.Look(). That should work, at least it did for me (although I didn''t render a landscape).
My normal render routine includes gluLookAt(), its inside camera.look()..

it still doesnt work.

Lords of Genesis | 3D Online RPG in development
http://www.lordsofgenesis.tk
Lords of Genesis | 3D Online RPG in developmenthttp://www.lordsofgenesis.tk

This topic is closed to new replies.

Advertisement