; LinePick Example ; ---------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,10,-14 RotateEntity camera,35,0,0 light=CreateLight() RotateEntity light,60,30,0 floor=CreatePlane() EntityColor floor,40,60,90 ; Radar station at the centre of the arena radar=CreatePivot() PositionEntity radar,0,1,0 ; Visible beam - a thin cylinder parented to the radar, lying along its z axis beam=CreateCylinder(8,1,radar) ScaleEntity beam,0.05,6,0.05 RotateEntity beam,90,0,0 PositionEntity beam,0,0,6 EntityColor beam,0,255,0 ; Four crates for the radar to find - EntityPickMode 2 makes them pickable crate1=CreateCube() PositionEntity crate1,-6,1,3 EntityPickMode crate1,2 crate2=CreateCube() PositionEntity crate2,5,1,6 EntityPickMode crate2,2 crate3=CreateCube() PositionEntity crate3,2,1,-6 EntityPickMode crate3,2 crate4=CreateCube() PositionEntity crate4,-4,1,-5 EntityPickMode crate4,2 While Not KeyDown(1) ; Sweep the radar round TurnEntity radar,0,1.5,0 ; Convert 12 units along the radar's z axis into a world-space direction TFormVector 0,0,12,radar,0 ; LinePick casts a ray from the radar along the beam picked=LinePick(EntityX(radar),EntityY(radar),EntityZ(radar),TFormedX(),TFormedY(),TFormedZ()) ; Repaint the crates, then flash the one the beam is hitting EntityColor crate1,180,140,80 EntityColor crate2,180,140,80 EntityColor crate3,180,140,80 EntityColor crate4,180,140,80 If picked<>0 Then EntityColor picked,255,255,255 ; 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 Text 0,0,"Arrow keys: move camera Esc: exit" If picked<>0 Text 0,20,"LinePick: contact! Entity handle "+picked Else Text 0,20,"LinePick: 0 (beam sweeping - nothing on this bearing)" EndIf Flip Wend End