EntityIconHit ( entity,view_camera,x#,y#[,size#][,padding#] )

Parameters

entity - camera or light entity

view_camera - camera the icon is drawn for

x# - viewport-local X in pixels
y# - viewport-local Y in pixels

size# (optional) - icon size in viewport pixels, matching DebugEntityIcon; 40 (default)

padding# (optional) - extra hit margin in pixels; 6 (default)

Description

Returns True if a viewport point lies on an entity's debug icon.

Use it to click-select cameras and lights in an editor. The test uses the same geometry as DebugEntityIcon, including rotation, zoom and spot angle, against the projected bounds of the outline plus padding.

Hidden or disabled entities, their descendants, other entity classes and the view camera itself return False. Both entities must belong to the same world. This does not test scene occlusion, change CameraPick results or pick modes, or create scene objects.


See also: DebugEntityIcon, CameraPick, DebugEntityBounds.

Example

; EntityIconHit Example
; ---------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-6

; A lamp that circles the scene, as a level editor might show it
pivot=CreatePivot()
lamp=CreateLight(2,pivot)
PositionEntity lamp,2,0,0
LightRange lamp,4

cube=CreateCube()
EntityColor cube,80,120,160

selected=False

While Not KeyDown(1)

    TurnEntity pivot,0,0.5,0

    ; Is the mouse over the lamp's icon (with 6 pixels of padding)?
    hover=EntityIconHit(lamp,camera,MouseX(),MouseY(),40,6)
    If hover And MouseHit(1) Then selected=Not selected

    ; Orange while hovered, cyan once clicked, cream otherwise
    If hover
        DebugEntityIcon lamp,camera,40,255,140,0
    ElseIf selected
        DebugEntityIcon lamp,camera,40,0,220,255
    Else
        DebugEntityIcon lamp,camera,40,255,230,160
    EndIf

    ; 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   Mouse: hover / click the lamp icon   Esc: exit"
    Text 0,20,"EntityIconHit(lamp,camera,MouseX(),MouseY()) = "+hover+"   selected: "+selected

    Flip

Wend

End

Index