Jump to content
  • Advertisement
Sign in to follow this  
guvidu

Can someone tell me how can i select object in multiple viewports?

This topic is 4352 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

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 ?

Share this post


Link to post
Share on other sites
Advertisement
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!
:)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

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!