Can someone tell me how can i select object in multiple viewports?
I have my function to retrieve the objects ID like that: ***************************************************************************** ***************************************************************************** int RetrieveObjectID(int x, int y) { int objectsFound = 0; int viewportCoords[4] = {0}; unsigned int selectBuffer[32] = {0}; glSelectBuffer(32, selectBuffer); glGetIntegerv(GL_VIEWPORT, viewportCoords); glMatrixMode(GL_PROJECTION); glPushMatrix(); glRenderMode(GL_SELECT); glLoadIdentity(); gluPickMatrix(x, viewportCoords[3] - y, 2, 2, viewportCoords); gluPerspective(45.0f,(float)g_rRect.right/(float)g_rRect.bottom,0.1f,150.0f); glMatrixMode(GL_MODELVIEW); DrawGLScene(); objectsFound = glRenderMode(GL_RENDER); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); if (objectsFound > 0) { unsigned int lowestDepth = selectBuffer[1]; int selectedObject = selectBuffer[3]; for(int i = 1; i < objectsFound; i++) { if(selectBuffer[(i * 4) + 1] < lowestDepth) { lowestDepth = selectBuffer[(i * 4) + 1]; selectedObject = selectBuffer[(i * 4) + 3]; } } return selectedObject; } return 0; } ******************************************************************************* ******************************************************************************* The function worked fine before i put in multiple viewports I want to do my selection in one viewport... but i cant Also i call my function with: case WM_LBUTTONDOWN: { objectID = RetrieveObjectID(LOWORD(lParam), HIWORD(lParam)); switch(objectID) { case RotateID_O: { if(!RotationInCourse) { Rotate_O = true; RotationInCourse = true; m_angle = 0; } } break; **************************************************************************** **************************************************************************** Can you tell me whats the problem with my code ?
Well here is what's happening:
Let's say you have 2 viewports and you do something like this
You set the dimensions for viewport 1
Draw things in viewport1
You set the dimensions for viewport 2
Draw things in viewport2
Now for object selection this is exactly the same
If you rendered an object in viewport 1 it won't show in viewport2 and vice-versa
If you want to query for object selection do like this
You set the dimensions for viewport 1
objectID = RetrieveObjectID(LOWORD(lParam), HIWORD(lParam));
this will retrieve the object selected(if any) in viewport1
You set the dimensions for viewport 2
objectID = RetrieveObjectID(LOWORD(lParam), HIWORD(lParam));
this will retrieve the object selected(if any) in viewport2
Hope this helps!
:)
Let's say you have 2 viewports and you do something like this
You set the dimensions for viewport 1
Draw things in viewport1
You set the dimensions for viewport 2
Draw things in viewport2
Now for object selection this is exactly the same
If you rendered an object in viewport 1 it won't show in viewport2 and vice-versa
If you want to query for object selection do like this
You set the dimensions for viewport 1
objectID = RetrieveObjectID(LOWORD(lParam), HIWORD(lParam));
this will retrieve the object selected(if any) in viewport1
You set the dimensions for viewport 2
objectID = RetrieveObjectID(LOWORD(lParam), HIWORD(lParam));
this will retrieve the object selected(if any) in viewport2
Hope this helps!
:)
You have a strong point there. But for some reason my application crash when i do it like that.
I have like this:
**********************************************************************************
if(loop == 6)
{
glViewport (0, 0, window_width, window_height/1.2 - 1);
ObjectID = RetrieveObjectID(window_width, window_height/1.2 - 1);
glMatrixMode (GL_PROJECTION); glLoadIdentity ();
gluPerspective( 45.0, (GLfloat)(window_width)/(GLfloat)(window_height), 0.1f, 150.0 );
}
*********************************************************************************
If you know off any other metods please let me know.
I have like this:
**********************************************************************************
if(loop == 6)
{
glViewport (0, 0, window_width, window_height/1.2 - 1);
ObjectID = RetrieveObjectID(window_width, window_height/1.2 - 1);
glMatrixMode (GL_PROJECTION); glLoadIdentity ();
gluPerspective( 45.0, (GLfloat)(window_width)/(GLfloat)(window_height), 0.1f, 150.0 );
}
*********************************************************************************
If you know off any other metods please let me know.
Then it means you have a bug somewhere else.
For picking you can use the ray-trace approach: you do like this: you shoot a ray with the same direction as your viewdir,traverse all objects, test for intersection, and find the closest object it interesects this way. This is a bit more work if you have a complex scene, you have to use spatial paritioning to speed things up(octrees, bsp trees are more common).
For picking you can use the ray-trace approach: you do like this: you shoot a ray with the same direction as your viewdir,traverse all objects, test for intersection, and find the closest object it interesects this way. This is a bit more work if you have a complex scene, you have to use spatial paritioning to speed things up(octrees, bsp trees are more common).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement