EntityPickMode entity,pick_geometry[,obscurer]
Parameters
|
entity - entity handle pick_geometry - type of geometry used for picking 0: unpickable (default) 1: sphere (EntityRadius is used) 2: polygon 3: box (EntityBox is used) obscurer (optional) - true if the entity 'obscures' other entities during an EntityVisible call; true (default) |
Description
|
Sets the pick mode for an entity - whether the pick commands can hit it, and with what geometry. Entities are unpickable by default, so every ray sails straight through them; giving an entity a pick mode is what registers it with CameraPick, LinePick and EntityPick. The geometry choice is a speed/accuracy trade-off. Sphere (1) is fastest and uses the entity's EntityRadius - fine for roughly round things. Box (3) tests against the entity's EntityBox. Polygon (2) tests the actual triangles of the mesh - exact, and needed when you care about the precise point and surface normal, but the most expensive on high-polygon meshes. Note that only sphere and box picking work with sprites; polygon picking needs a real mesh. The optional obscurer parameter feeds EntityVisible: it decides what can block the line-of-sight between two entities. With obscurer false an entity stays pickable by the pick commands but is treated as transparent by EntityVisible - handy for glass, fences and other see-through scenery. See also: CameraPick, LinePick, EntityPick, EntityVisible, EntityRadius, EntityBox. |
Example
; 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
Index