Sign in to follow this  

Object Selection (OpenGL)

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

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
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[i]->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[i]->pVerts[j].x += xx;
object.pModel[i]->pVerts[j].y += yy;
object.pModel[i]->pVerts[j].z += zz;
}
}
}



Share this post


Link to post
Share on other sites

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this