Posted: 19th Mar 2003 0:06
I just thought of a clever way of doing this without having to fiddle around with mathematics and/or other CPU-intensive operations...

Control the camera with the arrowkeys and click on the object with the mouse.

+ Code Snippet
rem Amount of objects and pickcolor
objects=10
dim object_pickcolor(objects)

rem Make the objects
for t=1 to objects

   make object cube t,10
   position object t,0,0,t*30
   color object t,rgb(0,150,0)
   object_pickcolor(t)=rgb(t,0,0)

next t

rem Position and rotate camera
position camera -100,0,100
yrotate camera 90

rem Set manual synchronization on
sync on

rem Loop
Do

   rem If we want to pick an object
   if mouseclick()=1 and picked=0

      rem Set the picked object to none
      picked_object=0

      rem Do the "picking"-operation
      for t=1 to objects

         rem Set object properties
         set object light t,0
         color object t,object_pickcolor(t)

      next t

      rem Update the screen
      sync

      rem Color at the mousecursor
      color=rgbr(point(mousex(),mousey()))

      rem Match the color with the objects
      for t=1 to objects

         rem If match
         if color=rgbr(object_pickcolor(t))

            rem Set the picked object to the object number
            picked_object=t
            exit

         endif

      next t

      rem Restore object properties
      for t=1 to objects

         set object light t,1
         color object t,rgb(0,150,0)

      next t

      rem Color the picked object
      if picked_object>0 then color object picked_object,rgb(100,0,0)

      picked=1

   endif
   if mouseclick()=0 then picked=0

   rem Simple camera control
   control camera using arrowkeys 0,5.0,2.0

   rem Update screen
   sync

Loop


It could be done better using direct backbuffer access instead of the point command, but I'm too tired to do that now.

Anyway, hope someone will find it useful...
Posted: 19th Mar 2003 3:59
i dont get how you got that..... good code. ..
Posted: 19th Mar 2003 9:06
Hmm. Just popped into my head. "Hey, why don'tĀ“just color every object with a separate color and then get the screen color at the mousecursor"?

Does it work properly?
Posted: 19th Mar 2003 17:28
Yes it does, good code!
(LOL!)
Cheers.