Problem with picking
Hello, I followed the picking tutorial to help me in implementing picking in my own project but I've run into a problem when actually selecting an object on the screen. In the tutorial gluPerspective is used to set the perspective but thats the only place i use it. I'm using the glLookAt function in order to view things. How would I go about combining what I have with glLookAt with gluPerspective?? Does this problem make sense??
www.lefthandinteractive.net
How exactly are you doing the picking? (I didn't read the tutorial). If you do it by testing individual pixels, how you set your frustrum and camera doesn't really matter.
jon - your question is a bit vague. gluPerspective() and glLookAt() aren't directly related to picking - they're related to cameral positioning and setup. Can you express your problem a bit more clearly?
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Ok, the problem I am having now is that when I move my camera and then try to select an object is doesn't detect a selection. I'm using gluLookAt in my render function to position my camera. Things are fine when I dont move the camera and select different objects but as soon as I move the camera things get screwy. Inside my mouse selection function (I'm using glut) right before I render my scene in GL_SELECT mode I recall my look at routine to place the camera in the right spot. This is where things get messed up when I try to move the camera. Should I call a glPushMatrix/glPopMatrix before I call gluLookAt??
www.lefthandinteractive.net
glPushMatrix()'s and glPopMatrix()'s should be used every time you call glRotate() or glTranslate() that is not related to permanently redefining the origin of the renderer. For instance, if you have three spheres, each having a translation and a rotation offset, you should place them at (0, 0, 0) and render them as such:
This will guarantee that each of the spheres will be relative to the absolte origin of the 3D space, not each other, which might be the case in your code.
Also, make sure you're calling the exact same translation, camera placement and frustum definition code in the select as well as the render mode. Using the select mode effectively doubles the amount of rendering you have to do (lest you optimize by cutting down on the number of faces in the select mode).
The third issue comes to play when you're trying to pick stuff in windowed mode - you'll have to take into account the window caption bar and possibly the menu heights. I suggest you first try to get it working in fullscreen mode.
Any more questions? Shoot.
for(int i = 0; i < 3; i++) { glPushMatrix(); glTranslatef(sphere.x, sphere.y, sphere.z); glRotatef(sphere.ry, 0, 1, 0); sphere.Render(); glPopMatrix(); }
This will guarantee that each of the spheres will be relative to the absolte origin of the 3D space, not each other, which might be the case in your code.
Also, make sure you're calling the exact same translation, camera placement and frustum definition code in the select as well as the render mode. Using the select mode effectively doubles the amount of rendering you have to do (lest you optimize by cutting down on the number of faces in the select mode).
The third issue comes to play when you're trying to pick stuff in windowed mode - you'll have to take into account the window caption bar and possibly the menu heights. I suggest you first try to get it working in fullscreen mode.
Any more questions? Shoot.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
If I understand you correct...
Picking and rendering are done in seperate modes, right? So, if you want to "pick" correctly, you need to make sure you set your view and perspective identically in each mode, so that when you render a sphere in modelview, it gets put in the same spot when doing the picking. If you are using gluLookAt to set up your rendering, you use gluLookAt to set up your picking. The key is that they just need to be the same.
Picking and rendering are done in seperate modes, right? So, if you want to "pick" correctly, you need to make sure you set your view and perspective identically in each mode, so that when you render a sphere in modelview, it gets put in the same spot when doing the picking. If you are using gluLookAt to set up your rendering, you use gluLookAt to set up your picking. The key is that they just need to be the same.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement