|
x# - x coordinate of start of line pick y# - y coordinate of start of line pick z# - z coordinate of start of line pick dx# - x direction and distance of line pick dy# - y direction and distance of line pick dz# - z direction and distance of line pick radius# (optional) - radius of line pick; 0 (default) |
|
Casts a ray from x,y,z to x+dx,y+dy,z+dz and returns the first pickable entity it hits, or 0 if it hits nothing. Note that dx,dy,dz is the direction and length of the pick, not a destination point. LinePick is the workhorse ray test: fire it straight down (LinePick px,py,pz,0,-100,0) to find the ground height below a point, forward from a gun muzzle for hitscan bullets, or between two points as a custom line-of-sight probe. Only entities made pickable with EntityPickMode are considered. The optional radius turns the thin ray into a swept sphere, so the pick has thickness - useful for making narrow gaps stop a fat projectile. The pick's details are then available from the Picked commands: PickedX/Y/Z for the exact point hit, PickedNX/NY/NZ for the surface normal, PickedTime for how far along the ray it hit, and PickedEntity/PickedSurface/PickedTriangle for what was hit. See also: CameraPick, EntityPick, EntityPickMode, PickedX, PickedTime. |
; 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