; CameraPick Example ; ------------------ Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-10 light=CreateLight() RotateEntity light,45,45,0 ; Make the ground plane pickable, using pick mode 2 (polygon-accurate) plane=CreatePlane() EntityPickMode plane,2 ground_tex=LoadTexture("media/MossyGround.BMP") ScaleTexture ground_tex,4,4 EntityTexture plane,ground_tex ; A crate to click on - also pickable crate=CreateCube() EntityPickMode crate,2 crate_tex=LoadTexture("media/b3dlogo.jpg") EntityTexture crate,crate_tex PositionEntity crate,0,1,0 While Not KeyDown(1) ; 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 ; Left mouse button fires a pick ray through the mouse position - ; it can hit the crate, the ground, or nothing at all If MouseHit(1) Then picked=CameraPick(camera,MouseX(),MouseY()) RenderWorld Text 0,0,"Click: CameraPick at the mouse Arrow keys: move camera Esc: exit" Text 0,20,"PickedEntity: "+picked Text 0,40,"PickedX: "+PickedX#() Text 0,60,"PickedY: "+PickedY#() Text 0,80,"PickedZ: "+PickedZ#() Text 0,100,"PickedNX: "+PickedNX#() Text 0,120,"PickedNY: "+PickedNY#() Text 0,140,"PickedNZ: "+PickedNZ#() Flip Wend End