I want to pick a cube on the screen with the mouse under Borland CBuilder. There are 5*5 cubes on the screen in one row, but when I click on one of them, I get 25 as a “hit” number. But where is it coming from???
I post a simpified code here, I hope someone will know what I’m doing wrong…
Well, how are you drawing your cubes? Could you post the code for cubes.draw_cubes()?
I haven’t had much time with picking, apart from the redbook example, but my guess is that all 25 of them have the same name?
Also, by taking a look at the definition I saw the name parameter is a GLuint. It’s unsigned, so passing it -1 is certainly not -1 but something else.
I found something. If I push the cubes out of the screen leaving only the 5 leftmost cubes visible, I get 5 for ‘hits’. This means, that the things I’ve done were right, and the value of ‘hits’ is the total of the cubes drawn on the screen.
So, I tried gluPickMatrix. Nothing changed.
Can it be, that i used gluPickMatrix in a wrong way?
Thanks Hlz. The tutorial told me the answer. My use_cam was actually loading the identity matrix before setting the perspective. It ‘destroyed’ the view.
The trick I use to pick objects is simply to get ZBuff value on mouse X,Y before drawing world, then in drawing routine code, after each object has been drawn, I just check if ZBuff changed and if so, I keep the pointer/ID of the last drawn instance and continue until the whole scene is drawn. The last pointer (or ID) I have is the mouse pointed objet one.
It works however complex the models are and uses only draw loop.