LinePick

Blitz3D Forums/Blitz3D Programming/LinePick

xmlspy(Posted 2006) [#1]
I need a linepick example... I'm using it to check from point a to point b... but I'm a little confused on how it works.

Does it work like this?
Linepick entityx, entityy, entityz, destinationx, destinationy, destinationz, radius


big10p(Posted 2006) [#2]
The first 3 params are the absolute world coords of where the line starts. The next 3 params represent the distance/offset from the start point.


Ross C(Posted 2006) [#3]
Something like this as a small example i keep on my computer for times like this...

;linepick example by RossC

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera = CreateCamera()
Global light = CreateLight()

Global player = CreateCone()
EntityType player,1
EntityRadius player,1
EntityColor player,50,70,255
PositionEntity player,0,0.5,0

Global cam_piv = CreatePivot(player)
PositionEntity cam_piv,0,2,-8

Global tex=CreateTexture(64,64,1+8)
SetBuffer TextureBuffer(tex)
For loop=0 To 3000
	Color Rnd(190,255),Rnd(190,255),Rnd(190,255)
	Rect Int(Rnd(0,63)),Int(Rnd(0,63)),1,1
Next
Color 255,255,255

SetBuffer BackBuffer()

Global plane=CreatePlane()
EntityType plane,2
EntityColor plane,200,100,120
EntityTexture plane,tex
EntityPickMode plane,2


Global sphere=CreateSphere(10)
ScaleEntity sphere,10,3,10
EntityPickMode sphere,2
EntityType sphere,2
PositionEntity sphere,-2,0,19

Collisions 1,2,2,2; set up collisions between the ground and the player

Global jump_force#
Global jump_flag=0; set jump flag to 'no jump'
Global gravity#=0.9; set gravity value

While Not KeyHit(1)

	; this part is the linepick. The tform part, is to make sure the linepick is done from the players
	; actual rotation, straigh down.
	TFormVector 0,-10,0,player,0
	; the values from the tform then get used in the linepick command. if you just substitute your
	; variable for the player into here, everything will be cool!
	LinePick(EntityX(player,True),EntityY(player,True),EntityZ(player,True),TFormedX(),TFormedY(),TFormedZ()); do a linepick straight down form the players location
	; aligns the player to the scenery, whatever has has a pickmode set.
	AlignToVector player,PickedNX(),PickedNY(),PickedNZ(),2,0.1
	
	If KeyDown(200) Then MoveEntity player,0,0,0.1
	If KeyDown(208) Then MoveEntity player,0,0,-0.1
	If KeyDown(203) Then TurnEntity player,0,1,0
	If KeyDown(205) Then TurnEntity player,0,-1,0	
	
	update_camera()
	
	UpdateWorld
	RenderWorld
	Text 0,0," Press Space to jump. Arrow keys to move!"
	;DebugLog(" pickedy="+PickedY())
	Flip
Wend
End

Function update_camera()
	PointEntity camera,cam_piv
	MoveEntity camera,0,0,EntityDistance#(camera,cam_piv)/40.0
	PointEntity camera,player
End Function



xmlspy(Posted 2006) [#4]
This messed up my entire ai system... haha.

Well, I need a function that does a straight line, from the desired initial xyz to the destination xyz.


Ross C(Posted 2006) [#5]
Function Line_Pick(sx,sy,sz,dx,dy,dz)
   Linepick sx,sy,sz,sx-dx,sy-dy,sz-dx
End Function


Should do the trick :o)


John Blackledge(Posted 2006) [#6]
Ross, nice code.
But the cone appears to float above the white thingy.

Could this be because it should be
PickedNX#(),PickedNY#(),PickedNZ#(),
instead of
PickedNX(),PickedNY(),PickedNZ()?


big10p(Posted 2006) [#7]
That shouldn't make any difference, John - I never bother specifying the # when using these functions, myself.

Ross: There's a typo in the Line_Pick function. The final LinePick param should be sz-dz. ;)


Stevie G(Posted 2006) [#8]
Should the direction vectors not be dx-sx, dy-sy & dz-sz instead of the way you have them?

You may want to use floats for the function params too.

Stevie


big10p(Posted 2006) [#9]
Yes you're right, Stevie. :)