Object Selection (OpenGL)

Started by
6 comments, last by muimui1911 18 years, 3 months ago
Hi everyone, I like to ask some questions about objects selection. I know in OpenGL there is a function for selecting and picking objects in 3D, they are GL_SELECT etc.. I know they works like glInitNames((); .....and so on. however, does this function works on objects that is loaded from other resources, such as .obj, .3ds ....etc.
Advertisement
Whatever is rendered between a name push and pop can be selected with that name, so it doesnt matter if it was loaded from a resource. Check out NeHe's tutorial on the subject. If you still have questions after that, feel free to ask them here.
Developer Journal: The Life of Corman
I have look at that example before, however i do still have problems.
that is how do i assign the name to individual object?

my loading code

CObjLoader object;

///////////
for(i=0; i< object.numofobjects; i++)
object.rederscene();
///////////

How do i ensure the name is assigned in each individual object?


please give me a hand.

millions of thanks
for(i=0; i< object.numofobjects; i++)
{
glPushName(i);
object.rederscene();
glPopName();
}
Developer Journal: The Life of Corman
sorry my friend, i have another question to ask.
i can correct detect if my cursor have been hit the object. however, say if i want to click the object and then move it; in that case how would I know which object I need to change coordinates(translate), i can't just use "gltranslatef" for translating the object because I load the files into a template and collisiion detection is a part of my project.

please give me some adive on it.

Millions of thanks.

One way would be to add a unique identifier to each object you are going to draw. When you draw for picking purposes, use that identifier in the glPushName(). When you detect a hit, search all your objects for the one that has the matching identifier.

One word of caution. Using the GL_SELECT rendering mode on some ATI cards can have severe performance penalties. I don't know if they have addressed this issue, since it's been a few months since I've tried. I ended up switching to using unique colors for each item I want to select and reading back from the color buffer.
I am Sorry to ask you again, but how do i set an identifier to each object?
the following are some codes of my program.
CObjLoader object;/////////////////////object.Load(Filename);bool TRANS = FALSE;float xx=0, yy=0, zz=0;//////////////////////////////////////////for(i=0; i< object.numofobjects; i++){   if(TRANS)   translate(xx, yy, zz);   object.pModel->renderscene();}///////////////////////when i do translation i simply add the number to every vertices of the object.void translate(float xx, float yy, float zz){   for(int i; i< NumOfObjects; i++)    {          for(int j; j< object.NumOfVertice; j++)       {        object.pModel->pVerts[j].x += xx;	object.pModel->pVerts[j].y += yy;	object.pModel->pVerts[j].z += zz;       }    }  }
if you want more codes to show, welcome to ask, but please give me some more advices and direction.

thanks

This topic is closed to new replies.

Advertisement