Picking questions

Hello …
I’m new to JOGL .
I’m nearly finished with my picking-implementation ( with glpickmatrix() ).
I have filled my Selectbuffer.
Can sombody give me a description of the values stored in the buffer ?
My selectionbuffer does not corresopond with the descripions i’ve read in other posts about picking…
Here is an example (values stored in my selection buffer):
I have 10 Objects in my scene ,clicked on one object and got the following result:

buffer[0] = 10
buffer[1] = 175751660
buffer[2] = 1787727146
buffer[3] = 0
buffer[4] = 0
buffer[5] = 1
buffer[6] = 2
buffer[7] = 3
buffer[8] = 4
buffer[9] = 5
buffer[10] = 6
buffer[11] = 7
buffer[12] = 8
buffer[13] = 0
buffer[14] = 0

I think the first value (10) is the name of the Object (Object 10) i clicked on… and not the fourth value ???

How can i access my Objects now? What can i do with the ID ?

To be more precisely :
I render some randomly located cubes in space. I want the cubes to change their color, if they are selected.
How do i have to do to modify my renderroutine to get the desired effect( with the information stored in the selectbuffer)
I hope you understand what i mean. I´m no native speaker…

thx

You need a data structure to map the OpenGL name back to your application’s data structure. Have you looked at the source for demos.misc.Picking in the jogl-demos workspace?

Its ok…
I solved my problem…but thank you for the hint…

I used gl.glPushName( ) instead of gl.glLoadName( ). :wink:

I think you can close this thread now, cause it does not contain much valuable information.

Now another question concerning picking…

i used glpickmatrix( ) to generate the values in the selectbuffer…

Why are the z-values stored in the buffer so huge ?

for example : 2048039168

Is this ok ?

thx

The values in the z-buffer are not simply the distance from the camera to the object, but are based on the values of the near and far clipping planes, and will utilise the full range of possible values. They are also in a non-linear scale so that nearer objects have greater precision than those further away.

You can certainly compute the distance from the z-buffer value, but I couldn’t tell you how to go about it.

Without having looked it up, it should be something like this:

int Z_BUFFER_MAX = (1<<31)-1;
float distance = (float)Math.sqrt(zBufferValue/(float)Z_BUFFER_MAX)*(zClipFar-zClipNear)+zClipNear;

where zClipNear and zClipFar is the near and far clipping planes of the frustum

Well , i did not expect such a complex answer, but thank you…

:o

Another question…

I want my application to highlight the first hit object, e.g. the object with the lowest z-value.

If i click on one object it works… well, cause there’s only one object :wink:

But if i klick on multiple objects that obscure each other, my application takes nearly always the object that is the furthest one.
Altough i use the following codesnippet that commands my programm to choose the one with the lowest z-value :


 if (hits > 0) {
		        	
		        	if(hits == 1){
		        	System.out.println(hits + " Objekt has been hit");
		        	}
		        	else{
		        		System.out.println(hits + " Objekts have been hit.");	
		        	}
		        	
		        	choose = selectbuff.get(3); // Save the first Object
		            depth = selectbuff.get(1); // Save how far away it is
		           
		            if(hits>1){
		            for (int loop = 1; loop < hits; loop++) // check all objects
		            {
//		            Hier wird getestet ob das Objekt was wir im Moment betrachten näher ist als das was 
//		            wir vorher ausgewählt hatten.
		            
		           
		            if (selectbuff.get(loop*4+1) < depth)
		            {
		            	System.out.println("change");
		            choose = selectbuff.get(loop*4+3); // Auswahl des näheren Objekts
		            depth = selectbuff.get(loop*4+1); // Speichern wie weit es entfernt ist
		            }
		            }
		            }
		            
		            System.out.println("Objekt " + choose+ " wurde als erstes getroffen !");
		            System.out.println("-------------------------------------------------");
		            
		            Population[choose].hit = true; // Markiere das Objekt als getroffen
		            Population[choose].r = 1.0f;
		            Population[choose].g = 0;
		            Population[choose].b = 0;
		            
		           
		          
		      } else {
		    	  System.out.println("Kein Treffer !");
		          
		      }

What do you think ?

And why do i have negative values ??

???

Ok i solved it…

i had negative values due to a conversion problem from c to java …

I changed the z-values stored in the z-buffer in the following manner:

I opened a new thread an got following answers and solutions:

http://www.java-gaming.org/forums/index.php?topic=13812.0 :wink: