; EntityPickMode Example ; ---------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-7 light=CreateLight() RotateEntity light,45,45,0 floor=CreatePlane() EntityColor floor,70,110,70 ; The target cone cone=CreateCone() PositionEntity cone,0,1.2,3 ; Collision volumes used by the sphere and box pick modes - both are ; deliberately much bigger than the cone itself EntityRadius cone,2 EntityBox cone,-2,-2,-2,4,4,4 ; Start with exact polygon picking mode=2 mode_name$="polygon (exact mesh)" picked=0 wobble#=0 While Not KeyDown(1) ; Number keys choose the pick geometry If KeyHit(2) Then mode=1 : mode_name$="sphere (EntityRadius 2)" If KeyHit(3) Then mode=2 : mode_name$="polygon (exact mesh)" If KeyHit(4) Then mode=3 : mode_name$="box (EntityBox 4x4x4)" If KeyHit(11) Then mode=0 : mode_name$="unpickable" ; The star of the show: choose which geometry pick rays test against EntityPickMode cone,mode ; The cone bobs gently - its pick volume moves with it wobble=wobble+2 PositionEntity cone,0,1.2+0.2*Sin(wobble),3 ; Click to try to pick the cone If MouseHit(1) Then picked=CameraPick(camera,MouseX(),MouseY()) ; White while the last click hit, orange after a miss If picked<>0 Then EntityColor cone,255,255,255 Else EntityColor cone,220,120,40 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld ; Crosshair at the mouse position Rect MouseX()-6,MouseY(),13,1 Rect MouseX(),MouseY()-6,1,13 Text 0,0,"Click near the cone 1/2/3: pick geometry 0: unpickable Esc: exit" Text 0,20,"EntityPickMode cone,"+mode+" ("+mode_name$+")" If picked<>0 Then Text 0,40,"Last click: HIT" Else Text 0,40,"Last click: miss" Text 0,60,"Sphere and box are bigger than the cone - near-misses still hit in modes 1 and 3" Flip Wend End