PDA

View Full Version : Selection mode hits and pointers..



redarrow
10-11-2006, 10:10 AM
Hi everyone..

I've been storing pointers in the selection mode "hits stack" by casting them to unsigned ints, and afterwards casting them back into pointers...

In this case they are pointers to the object that was selected by the hit.. something like:

glPushName((unsigned int)obj);
draw_object(obj);
glPopName();This has worked no problem for me... but I've come to realize that this is probably not the best programming practice... it might not work on different machines/compilers etc..

Does OpenGL perhaps have some "hidden" function allowing me to modify the type of the hits stack?
Or does anyone have a smarter solution?

I did initially store an ID number for each object and then retrieve the object by searching for it's ID ... but this could get slow seeing as I use linked lists...

Thanks! :)

Bob
10-11-2006, 01:16 PM
Then don't use a linked list if it's slow.

std::map for example gives you logarithmic search time and is good for arbitrary values of the ID. Or if you use linear indices (staring from 0 and increasing by 1 for each object), then an std::vector with the hit record used as index into the vector provides a constant search time.

speed
10-11-2006, 02:20 PM
I don't know your data structure that stores the object, but if you use and array/vector, the index could be the position on the vector, and then the cost of obtain the object is O(1).

If you explain how is your data structures, we can give you a smart solution for your case.

redarrow
10-12-2006, 09:28 AM
Originally posted by Bob:
Then don't use a linked list if it's slow.
Yes.. I guess I shouldn't have used linked lists from the start... but I started the project a long time ago and to change it now will be .. difficult ... mind you if it's for the best I will recode the internals...


Originally posted by Bob:

std::map for example gives you logarithmic search time and is good for arbitrary values of the ID. Or if you use linear indices (staring from 0 and increasing by 1 for each object), then an std::vector with the hit record used as index into the vector provides a constant search time. I'm sorry.. that's a bit above my head... what do you mean by "linear indices"


Originally posted by speed:

I don't know your data structure that stores the object, but if you use and array/vector, the index could be the position on the vector, and then the cost of obtain the object is O(1).

If you explain how is your data structures, we can give you a smart solution for your case.
I use the "winged edge" data structure.. all done with linked lists.. e.g, something like:


typedef struct _KO {
struct _KF *faces;
struct _KE *edges;
struct _KV *verts;
} KObject;

typedef struct _KF {
struct _KF *next_face;
struct _KF *previous_face;
/* ... other face info */
} KFace;

typedef struct _KE {
struct _KE *next_edge;
struct _KE *previous_edge;
/* ... other edge info */
} KEdge;

typedef struct _KV {
struct _KV *next_vert;
struct _KV *previous_vert;
/* ... other vert info */
} KVertex;Not exactly like that.. but more or less...

I've actually released the whole project under GPL if anyone wants to peak at the actual code .. :)
See: http://kudu.sourceforge.net

Thanks for replys!

Bob
10-12-2006, 01:32 PM
[quote]Originally posted by redarrow:
[B]

int ID = 0;
std::vector<KObject *> selections;

for o = each object to draw during selection
glLoadName(ID);
o->draw();
selections.push_back(o);
++ID;
endAnd when selecting, the selection buffer returns an ID, and the corresponding KObject is obtained as

ID = get_hit_record();
o = selections[ID];

redarrow
10-13-2006, 05:31 AM
Thanks Bob... I see what you're getting at now...

I like that idea about adding the pointers to a different structure specifically for selection purposes..

Yea, I think that should work fine :)


Thanks a lot!