|
camera - camera handle viewport_x# - x coordinate within the camera's viewport viewport_y# - y coordinate within the camera's viewport |
|
Picks the entity visible at the given viewport coordinates. Returns the entity picked, or 0 if there is none. This is the 'what is under the mouse?' command: CameraPick( camera,MouseX(),MouseY() ) fires a ray from the camera through that pixel, out to the camera's far range, and returns the nearest pickable entity it hits - point-and-click object selection in one call. An entity must have its EntityPickMode set to a non-0 value to be pickable; everything else is ignored by the ray. After a successful pick, the PickedX/Y/Z commands give the exact point hit, PickedNX/NY/NZ the surface normal, and PickedEntity, PickedSurface and PickedTriangle the details of what was hit. The coordinates are relative to the camera's viewport, not the screen - only identical for a default full-screen viewport. See also: EntityPick, LinePick, EntityPickMode, PickedX, PickedEntity. |
; 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