LinePick problem

Blitz3D Forums/Blitz3D Beginners Area/LinePick problem

flag(Posted 2005) [#1]
I want that spheres don't cover the boxes. I try to use linePick but it doesn't work. Anyone knows? Is it because i don't use correctly the function or there's another problem?

Thanx
Flag

my code (it's function createXcibles() which doesn't work) :



;Init graphiques
Graphics3D 1024,768

SetBuffer BackBuffer()


Const TYPE_JOUEUR% = 1
Const TYPE_DECOR% = 2
Const TYPE_ENEMY% = 3
Const TYPE_CIBLE% = 4
Global fond,cube

Type Tcible
Field x#,y#,z# ;position
Field vx#,vy#,vz# ; vitesse
Field etat% ; Flag
Field entite
Field Typ%
End Type


;Environnement
camera=CreateCamera()


Light=CreateLight()
;rotateEntity light,90,0,0
PositionEntity light,-10,-1,0



oldmillisecs# =MilliSecs()

loadLevel()



SeedRnd (MilliSecs ())



;cam
CameraProjMode camera,2
CameraZoom camera,.35
PositionEntity camera,.2,0,-3.4 ;.4,.4
PointEntity camera,fond
;PointEntity light,fond

;boucle principale de jeu
;========================

;Init
partie = createXcibles(100)

timeDeb# = MilliSecs()
While (Not KeyDown( 1 ))

thistime# = MilliSecs()
deltatime#=thistime#-oldmillisecs#
oldmillisecs#=thistime#

TurnEntity cube,0,0,.1


UpdateWorld()
ClearCollisions
RenderWorld
Flip

Wend




;Fonctions
;=========


Function createxCibles(nb%)
Local e
For i%=0 To nb%
k% = 0
c.TCible = New TCible
c\typ% = typ%
c\entite = CreateSphere(16)
ScaleEntity c\entite,.05,.05,.05
EntityType c\entite,TYPE_CIBLE
EntityColor c\entite,100,100,180
EntityRadius c\entite,.05
NameEntity c\entite,Handle(c)

Repeat
; e = 0
c\x# = Rnd(-2,2)
c\y# = Rnd(-2,2)
;
e = LinePick(c\x#-.02,c\y#-.02,-.5,.07,.07,0)

If e <> 0 Then
DebugLog("move !!!" + k%)
k% = k% + 1
EndIf

Until (e = 0)
PositionEntity c\entite,c\x#,c\y#,-.5
Next


End Function


Function loadLevel()
;fond
fond=CreateCube()
ScaleEntity fond,2.66,2,.5
PositionEntity fond,0,0,0
EntityColor fond,100,150,100


;niveau
cube=CreateCube()
ScaleMesh cube,.5,.5,.5
PositionEntity cube,-1,0,-.25
RotateMesh cube,0,0,23
EntityType cube,TYPE_DECOR
EntityPickMode cube,2
NameEntity cube,"cube"
EntityAlpha cube,.4

cube2=CreateCube()
ScaleMesh cube2,.3,.3,.5
PositionEntity cube2,1,1,-.25
RotateEntity cube2,0,0,46
EntityType cube2,TYPE_DECOR
EntityPickMode cube2,2
NameEntity cube2,"cube2"
EntityAlpha cube2,.4


cube3=CreateCube()
ScaleEntity cube3,.6,.05,.5
PositionEntity cube3,0,-1,-.25
EntityType cube3,TYPE_DECOR
EntityPickMode cube3,2
NameEntity cube3,"cube3"
EntityAlpha cube3,.4

cube4=CreateCube()
ScaleEntity cube4,.6,.6,.5
PositionEntity cube4,-1,-1.5,-.25
EntityType cube4,TYPE_DECOR
EntityPickMode cube4,2
NameEntity cube4,"cube4"
EntityAlpha cube4,.4


End Function





End


WolRon(Posted 2005) [#2]
FYI, What are the forum codes?

You just didn't have your linepick command set up correctly. That's the only line I changed.
Since your cubes are at Z position -.25, I set the line pick to check from -1 to 0.
I also set it to have a radius of .05 to account for the radius of the sphere.

Function createxCibles(nb%)
	Local e 
	For i%=0 To nb%
		k% = 0
		c.TCible = New TCible
		c\typ% = typ%
		c\entite = CreateSphere(16)
		ScaleEntity c\entite,.05,.05,.05
		EntityType c\entite,TYPE_CIBLE
		EntityColor c\entite,100,100,180
		EntityRadius c\entite,.05
		NameEntity c\entite,Handle(c)
		
		Repeat
			; e = 0 
			c\x# = Rnd(-2,2)
			c\y# = Rnd(-2,2)
			; 
			e = LinePick(c\x#, c\y#, -1, 0, 0, 1, .05)
			
			If e <> 0 Then 
				DebugLog("move !!!" + k%)
				k% = k% + 1
			EndIf
		
		Until (e = 0)
	PositionEntity c\entite,c\x#,c\y#,-.5 
	Next


End Function


This basically works.
However, it doesn't take into account the fact that one of the cubes is rotating.
An easy fix for that could be to place a sphere/cylinder with the same radius as the cube at the rotating cubes position (with the same entitytype) while placing the small spheres, and then erase it later.