Link to home
Start Free TrialLog in
Avatar of jsbsudha
jsbsudhaFlag for Germany

asked on

object picking opengl --Glut c++

I have displayed some cubes in the opengl window....All are in same color and only the size is different.......In this case If I select the cube during runtime by mouse click ......The coordinates of the selected cube should be displayed in the  opengl window or dos window.......... I  could get the code only by  selecting the object using colour  which is not very useful.........
Avatar of Infinity08
Infinity08
Flag of Belgium image

>> I  could get the code only by  selecting the object using colour

I don't understand what you mean here. Could you elaborate ? Can you maybe show the relevant code too ?
Avatar of jsbsudha

ASKER

I could see the source code for objectr selection and picking in the sam's opengl super bible book ........but that selection of objects  and picking is based on the colour of the objects.........But in my case the colour of the objects are same so I could not use that logic ...........

ASKER CERTIFIED SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> but that selection of objects  and picking is based on the colour of the objects

Well, then base your selection on something else. Give every object a unique id for example.
>> but that selection of objects  and picking is based on the colour of the objects

thats an easy way to check which object is selected, but it has almost no practical use, since it only works without textures, fog, lighting etc ..
that technique is based on the fact, that you can easily read the color at a given screen-position and compare it with your objects, assuming each objects has another color.

either you use the name-stack like shown in the links or you implement it yourself sending a ray down the camera and see which *objects* intersect ..
I want to pick the objects by using colour.....But I have used lighting effect.........can anyone give example.........the colours of the  objects are  like glcolor3f(0.8,0.2,0.0).........
if you use lighting you cant do it like this, because the color of the object changes depending on its position and orientation relative to the light source(s)