entitypickmode problem

Blitz3D Forums/Blitz3D Programming/entitypickmode problem

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Yes, I see .. Hmm .. I replaced the PointEntity command in the UpdateSprites function, and inserted a pivot to parent the sprite, so that aligning it to the camera doesn't affect it's orientation:
; CreateSphere Example
; --------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

piv=CreatePivot()
camera=CreateCamera()
MoveEntity camera, 0, 0, -2

textu = CreateTexture(80, 15)
SetBuffer TextureBuffer(Textu)
ClsColor 255, 0, 0
Cls
Text 1,1, "no"
SetBuffer BackBuffer()

Sprite = CreateSprite()
EntityTexture Sprite, Textu
ScaleSprite sprite, 0.5, 0.1
SpriteViewMode sprite, 1
FreeTexture Textu

EntityPickMode Sprite, 2
;EntityRadius sprite, 0.13, 0.9


;create spheres
For i = 0 To 1000
	ok = CreateSphere()
	PositionEntity ok, Rnd(-100, 100), Rnd(-100, 100), Rnd(-100, 100)
	EntityColor ok, Rand(255), Rand(255), Rand(255)
Next

PositionEntity camera, 1,0,-2
Repeat

	If KeyDown(203) Then TurnEntity camera, 0, +1, 0
	If KeyDown(205) Then TurnEntity camera, 0, -1, 0
	If KeyDown(200) Then TurnEntity camera, -1, 0, 0
	If KeyDown(208) Then TurnEntity camera, +1, 0, 0
	
	UpdateSprites(camera)
	
	RenderWorld
	CameraPick camera, MouseX(), MouseY()
	Color 255, 255, 255
	Text 0, 0, "you picked: " + PickedEntity()
	Flip
	
Until KeyHit(1)

End


;-----------------------------------------------------------------------------------------------------
; 											MESH-BASED SPRITE COMMANDS
;-----------------------------------------------------------------------------------------------------

Type Sprites
	Field pivot
	Field mesh
	Field view
End Type

;-----------------------------------------------------------------------------------------------------
;												LoadSprite()
;-----------------------------------------------------------------------------------------------------
Function LoadSprite(filename$, texflag = 9, parent = 0)

	tex = LoadTexture(filename$, texflag)

	pivot = CreatePivot(parent)	
	mesh = CreateMesh(pivot)
	surf = CreateSurface(mesh)
	
	AddVertex surf, -1, -1, 0, 1, 1
	AddVertex surf, +1, -1, 0, 0, 1
	AddVertex surf, +1, +1, 0, 0, 0
	AddVertex surf, -1, +1, 0, 1, 0
	
	AddTriangle surf, 0, 1, 2
	AddTriangle surf, 0, 2, 3

	;double sided method I, works with PickMode 2
	;AddTriangle surf, 2, 1, 0
	;AddTriangle surf, 3, 2, 0
	
	If tex <> 0 Then	
		EntityTexture mesh, tex
		FreeTexture tex
	End If
	
	;double sided method II, could give problems with PickMode 2
	;EntityFX mesh, 16
	
	s.Sprites = New Sprites
	s\mesh = mesh
	s\pivot = pivot
	
	Return mesh
	
End Function

;-----------------------------------------------------------------------------------------------------
;												ScaleSprite()
;-----------------------------------------------------------------------------------------------------
Function ScaleSprite(sp, x#, y#)

	ScaleEntity sp, x, y, 1
	
End Function

;-----------------------------------------------------------------------------------------------------
;												RotateSprite()
;-----------------------------------------------------------------------------------------------------
Function RotateSprite(sp, x#)

	RotateEntity sp, 0, 0, x, 1
	
End Function

;-----------------------------------------------------------------------------------------------------
;												HandleSprite()
;-----------------------------------------------------------------------------------------------------
Function HandleSprite(sp, x#, y#)

	PositionMesh sp, x, y, 0
	
End Function

;-----------------------------------------------------------------------------------------------------
;												SpriteViewMode()
;-----------------------------------------------------------------------------------------------------
Function SpriteViewMode(sp, vm)

  For s.Sprites = Each Sprites
	If s\mesh = sp Then s\view = vm
  Next

End Function

;-----------------------------------------------------------------------------------------------------
;											UpdateSprites()
;-----------------------------------------------------------------------------------------------------
Function UpdateSprites(cam)

  For s.Sprites = Each Sprites
	 If s\mesh <> 0 Then 
	
		 ;sprite view modes
	     Select s\view
	     Case 1	  
		   RotateEntity s\mesh, 0, 180 + EntityYaw(cam, 1), 0
		 Case 2
		   ;nothing needed
		 Case 3
			RotateEntity s\mesh, -EntityPitch(cam, 1), 180 + EntityYaw(cam, 1), -EntityRoll(cam, 1)
		 Case 4	
			RotateEntity s\mesh, 0, 180 + EntityYaw(cam, 1), -EntityRoll(cam, 1)
		 End Select
	 
     End If
  Next

End Function

;-----------------------------------------------------------------------------------------------------
;												FreeSprite()
;-----------------------------------------------------------------------------------------------------
Function FreeSprite(sp)

  For s.Sprites = Each Sprites
	If s\mesh = sp Then
		FreeEntity sp
		Delete s
	End If
  Next
		
End Function

;-----------------------------------------------------------------------------------------------------
;												CreateSprite()
;-----------------------------------------------------------------------------------------------------
Function CreateSprite(parent = 0)
	Return LoadSprite("", 0, parent)
End Function