How does "LinePick" works, please ? I need help !

Blitz3D Forums/Blitz3D Beginners Area/How does "LinePick" works, please ? I need help !

etxtra(Posted 2011) [#1]
Hi everyone ! I would like to know how does "LinePick ( )" works ? Maybe it's simple, maybe it's simple for you but for me it's not clear... I don't get it. here is a simple program snippet I wrote to understand "LinePick". In this program, I have created a cube and I want the cube to be "red" because [to me,] it is between the 2 points of "LinePick" but it don't work, see:
; I want the cube to be red, how ? I want to use "LinePick" to do this how?
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

cube = CreateCube ( )
;contact = LinePick ( 0.0, -50.0, 0.0, 0.0, 100.0, 0.0 )
contact = LinePick ( 0.0, -50.0, 0.0, 0.0, (-50.0) + 100.0, 0.0 )
If contact <> 0 Then EntityColor contact, 255, 0.0, 0.0

;setup camera (has no collisions)
camera = CreateCamera()

PositionEntity camera, 0, 0, -5


Repeat

	;update&render
	;UpdateWorld ;performs actual collisionchecking and response
			    ;this command also updates b3d/3ds animations
	RenderWorld

	Text 0, 0, "The cube ain't red, why ?"	
	Flip
	
Until KeyHit(1)

End



Warner(Posted 2011) [#2]
You should enable picking mode on the cube first:
EntityPickMode cube, 2


Last edited 2011


etxtra(Posted 2011) [#3]
Ok, understood ! here is an example of how I will use "LinePick", use arrows keys to turn camera:
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

cube = CreateCube ( )
EntityAlpha cube, 0.5
test = CreateSphere ( )
EntityPickMode cube, 2
;contact = LinePick ( 0.0, -50.0, 0.0, 0.0, 100.0, 0.0 )
contact = LinePick ( 0.0, -2.0, 0.0, 0.0, 2.0, 0.0 )
If contact <> 0 Then EntityColor contact, 255, 0.0, 0.0

;setup camera (has no collisions)
camera = CreateCamera()

PositionEntity camera, 0, 0, -15


Repeat
	PositionEntity test, EntityX# ( camera ),  EntityY# ( camera ), EntityZ# ( camera )
	RotateEntity test, 0.0, EntityYaw# ( camera ), 0.0
	MoveEntity test, 0.0, 0.0, 15.0 * 2
	
	contact = LinePick ( EntityX# ( camera ), EntityY# ( camera ), EntityZ# ( camera ), EntityX# ( test ), EntityY# ( test ), EntityZ# ( test ) )
	If contact = cube
		EntityColor contact, 255, 0.0, 0.0
	Else
		EntityColor cube, 200, 200, 200
	EndIf
	
	If KeyDown ( 203 ) = 1 Then TurnEntity camera, 0.0, 1.0, 0.0
	If KeyDown ( 205 ) = 1 Then TurnEntity camera, 0.0, -1.0, 0.0
	;update&render
	;UpdateWorld ;performs actual collisionchecking and response
			    ;this command also updates b3d/3ds animations
	RenderWorld

	Text 0, 0, "Use Arrow keys (left / right) to turn camera"	
	Flip
	
Until KeyHit(1)


End



Warner(Posted 2011) [#4]
LinePick doesn't use 2 points, but a point and a vector (xyz-difference between start and endpoint), like this: