PDA

View Full Version : GLGroup class



fcoutel
08-20-2004, 07:13 AM
hi!

I would like to implement a GLGroup class which would contain a collection of OPenGL objects (spheres, cubes etc).

In this class I see that there would be a pointer keeping track of objects list and some members like
GLGroup::addobject
and one
GLGroup::deleteobject

My main problem is that I want to be able to select those objects on the screen and tell which one I have selected somehow

so in the selection mode I will have a

loop over objects
glPushName(i)

But I add/delete objects from the list how do I keep track of their names?

dorbie
08-20-2004, 07:23 AM
You associate the names with the objects, it is entirely up to you what you want to do with the names. The name does not have to be a list index, it could be cast from a pointer for example.

fcoutel
08-20-2004, 09:28 AM
could you please give me a brief example of how you would write this class?

dorbie
08-20-2004, 01:47 PM
I'm not talking about writing a class, I'm talking about storing a pointer to your class as the name.

Or you could use an array of pointers and use i as the index you sent to the pick stack, however I'd just go with the direct cast and cast back.

fcoutel
08-21-2004, 12:10 AM
I don't understand what you mean by "the direct cast and cast back" can you pls give me an example?

knackered
08-21-2004, 04:31 AM
Yeah dorbie, give him an example :p

jwatte
08-21-2004, 06:31 PM
I'm going to answer, but I also want a moderator to move the answer to the "for beginners" section.

Anyway:

For each object, allocate a struct, which allows you to keep track of the object, which group it is in, etc.

The pointer to this struct can be cast to an int, on all 32-bit platforms, and on 64-bit platforms with 64-bit ints. Cast the pointer-to-struct to int for each object.

This casted pointer is your name. Now, when you get a specific name back, you just cast back to pointer, and dereference -- voila, there is a struct telling you what the object is!

If you need to do this on a platform where names are 32 bit, but pointers are 64 bit, you can also just put all the different struct pointers into a vector, and make the index into the vector be the name.

fcoutel
08-23-2004, 03:04 AM
Thanks but I still don't understand this casting stuff.

What I plan to do is:
1) Create a GLobject class wich contains variables like name etc
2) create a List Pointer (like QT's QPtrList) containing all the GLobjects
3) iterate thru the list and give i to PushName
4) once I have i (the selected object) I can get the object via the List Pointer and then its name via its variable or a function.

Is there something wrong with this?

dorbie
08-23-2004, 04:25 AM
This is off topic, if you don't know what a cast is or how to cast in C++ then you need to do some more work on your basic programming knowledge.

Closing thread now.