Billboards disappearing

Everything related to 3D programming
tastyraspberry
User
User
Posts: 39
Joined: Fri Sep 28, 2012 10:22 am

Billboards disappearing

Post by tastyraspberry »

Hi all,

I am trying to simulate a queue and I was going to use billboard groups in a 3D environment to show where people are...it is part of a bigger idea. However, I have a bug where it seems if I move the BillboardGroups' position off the screen all the billboards of that group disappear instantly..

I have stripped the code down to the bear essentials which I hope shows the problem. If you run it and then move the circle (just a marker to show the beginning of the queue) off to the right of the screen (rotate with mouse, move with WASD and mouse wheel) you will see the billboard group disappear when the groups position is off the screen.... well it does on my machine. If you wiggle the sphere just off the screen the billboards will appear and disappear and I think this is due to the billboards group position being offscreen. However, this doesn't happen in any other example I have seem eg billboard.pb in the help file..

For this demo I have separated the male and females in the queue - they are different billboard groups blue and pink respectively, but they are all part of the same queue.

I am a bit perplexed and would be grateful if anyone else can replicate or see the problem. (I have a 2D sprite and an£D entity version which all look fine and I was experimenting how to do it with billboards as I thought it would be the fastest way)

Michael

Code: Select all

  ; EnableExplicit
XIncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

If Screen3DRequester() = #False
  End
EndIf

Enumeration
  #Camera
  #male
  #female
EndEnumeration

Define.f KeyX, KeyY, MouseX, MouseY

Structure Patient 
  Billboard.i
  BillboardGroup.i
  Gender.i
  x.i
  y.i
  z.i
EndStructure

NewList PatientList.Patient()

;Set up the 3D environment

; Camera
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#Camera, 0,5,20, #PB_Absolute)

CreateSphere(0, 0.5)
CreateEntity(0, MeshID(0), #PB_Material_None)
  
;textures and materials 
TextureRed.i = CreateTexture(#PB_Any , 16, 16, "")
StartDrawing(TextureOutput(TextureRed))
Box(0, 0, TextureWidth(TextureRed), TextureHeight(TextureRed), RGB(229, 9, 209))
StopDrawing()
MaterialRed.i = CreateMaterial(#PB_Any, TextureID(TextureRed))

TextureBlue.i = CreateTexture(#PB_Any, 16, 16, "")
StartDrawing(TextureOutput(TextureBlue))
Box(0, 0, TextureWidth(TextureBlue), TextureHeight(TextureBlue), RGB(33, 33, 203))
StopDrawing()
MaterialBlue.i = CreateMaterial(#PB_Any, TextureID(TextureBlue))

;Create Billboard groups
BillboardMales   = CreateBillboardGroup(#PB_Any, MaterialID(MaterialBlue), 1, 1)
BillboardFemales = CreateBillboardGroup(#PB_Any, MaterialID(MaterialRed), 1, 1, 0, 1, 0)

;
; Ah -  but the trouble is if you can't see the billboards group position then you can't see any of the billboards....why?
; this dioesn't seem to happen in the billboards.pb example - what am I doing wrong?  
;
camspeed.f = 0.2
frame.i = 0
nextpatient.i = frame + Random(20)    ;add someone To the queue
nextadmission.i = frame + Random(50)	; take someone off the front of the queue

Repeat
    
  If frame > nextpatient
  	; add a patient to the end of the queue
  	LastElement(PatientList())
    AddElement(PatientList())
    
    If Random(100) < 50
      PatientList()\Gender = #male
      PatientList()\x = -ListSize(PatientList()) - Random(10)
      PatientList()\y = 0
      PatientList()\z = Random(50) - 25
    	PatientList()\Billboard = AddBillboard(BillboardMales, PatientList()\x, PatientList()\y, PatientList()\z)  
    	PatientList()\BillboardGroup = BillboardMales	
    Else
      PatientList()\Gender = #female
      PatientList()\x = -ListSize(PatientList()) - Random(10)
      PatientList()\y = 0
      PatientList()\z = Random(50) - 25
      PatientList()\Billboard = AddBillboard(BillboardFemales, PatientList()\x, PatientList()\y, PatientList()\z)
      PatientList()\BillboardGroup = BillboardFemales
    EndIf
   
    nextpatient = frame + Random(20)
  EndIf
  
  ;Move each billboard to it's place in the queue
  ForEach PatientList()
    With PatientList()
    	vx.f = -(BillboardX(PatientList()\Billboard, PatientList()\BillboardGroup ) + ListIndex( PatientList())) * 0.1
    	vz.f = -BillboardZ(PatientList()\Billboard,PatientList()\BillboardGroup) * 0.1
      MoveBillboard(PatientList()\Billboard, PatientList()\BillboardGroup, vx, 0, vz)  	 
    EndWith
  Next
  
  ; Take off front of queue
  If frame > nextadmission
    If FirstElement(PatientList())
    	RemoveBillboard(PatientList()\Billboard, PatientList()\BillboardGroup)
     	DeleteElement(PatientList(),1)
     	nextadmission.i = frame + Random(50)
    EndIf
  EndIf
  
  Screen3DEvents()
  ExamineKeyboard()
  ExamineMouse() 
  
  If KeyboardPushed(#PB_Key_Delete)
    If FirstElement(PatientList())
    	RemoveBillboard(PatientList()\Billboard, PatientList()\BillboardGroup)
      DeleteElement(PatientList(),1)
  	EndIf
  EndIf
            
      
	MouseX = -MouseDeltaX() / 10
  MouseY = -MouseDeltaY() / 10
  dist = MouseWheel()  
        
  If KeyboardPushed(#PB_Key_LeftShift)
  	camspeed = 0.4
  Else
    camspeed = 0.2
  EndIf
  If KeyboardPushed(#PB_Key_A)
    MoveCamera(#camera,  -camspeed, 0, 0)
  EndIf
  If KeyboardPushed(#PB_Key_D)
    MoveCamera(#camera,  camspeed, 0, 0)
  EndIf
  If KeyboardPushed(#PB_Key_W)
    MoveCamera(#camera,  0, 0, -camspeed)
  EndIf
  If KeyboardPushed(#PB_Key_S)
    MoveCamera(#camera,  0, 0, camspeed)  
  EndIf
  If dist <> 0
    MoveCamera(#camera, 0, -dist, 0, #PB_Relative | #PB_World)  
  EndIf
            
  If KeyboardReleased(#PB_Key_R)
    If RenderMode = 0
      CameraRenderMode(#Camera, #PB_Camera_Wireframe)
      RenderMode = 1
    Else
      CameraRenderMode(#Camera, #PB_Camera_Textured)
      RenderMode = 0
    EndIf
  EndIf
         
       
  RotateCamera(#camera, MouseY, MouseX, 0, #PB_Relative)
   
  RenderWorld()
  FlipBuffers()
  frame + 1
  
Until KeyboardPushed(#PB_Key_Escape)
tastyraspberry
User
User
Posts: 39
Joined: Fri Sep 28, 2012 10:22 am

Re: Billboards disappearing

Post by tastyraspberry »

It seems it may be due to the AddBillboard() command. The code below just adds a billboard to a group at a random interval but the same things happens. If you use WASD and the mouse to fly the right end of the group off the screen the billboards will all suddenly disappear.

Anyone have any thoughts? I am worried that I have a fundamental misunderstanding of what I can and can't do with billboards.

Michael

Code: Select all

#CameraSpeed = 1
#camera = 0
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

InitEngine3D()

InitSprite()
InitKeyboard()
InitMouse()

Screen3DRequester()

Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)



TextureBlue.i = CreateTexture(#PB_Any, 1, 1, "")
StartDrawing(TextureOutput(TextureBlue))
Box(0, 0, TextureWidth(TextureBlue), TextureHeight(TextureBlue), RGB(33, 33, 203))
StopDrawing()
MaterialBlue.i = CreateMaterial(#PB_Any, TextureID(TextureBlue))

Structure Board
	ID.i
	group.i
EndStructure

NewList BillboardList.Board()

myBillboardgroup = CreateBillboardGroup(#PB_Any, MaterialID(MaterialBlue), 1, 1)

For i = - 10 To 0
	LastElement(BillboardList())
	AddElement(Billboardlist())
	Billboardlist()\ID = AddBillboard(myBillboardgroup, i, 0, -40)
	Billboardlist()\group = myBillboardgroup
Next

CreateCamera(#camera, 0, 0, 100, 100)
camspeed.f = 0.2
Repeat
	
	
	If Random(100) > 70
			LastElement(BillboardList())
			AddElement(Billboardlist())
			Billboardlist()\ID = AddBillboard(myBillboardgroup, -ListSize(Billboardlist()) + 1, 0, -40)
			Billboardlist()\group = myBillboardgroup
		
	Else
	EndIf
	
	
	Screen3DEvents()
	ExamineKeyboard()
	ExamineMouse()
	
	MouseX = -MouseDeltaX() / 10
	MouseY = -MouseDeltaY() / 10
	RotateCamera(#camera, MouseY, MouseX, 0, #PB_Relative)
	
	dist = MouseWheel()  
	If dist <> 0
		MoveCamera(#camera, 0, -dist, 0, #PB_Relative | #PB_World)  
	EndIf
	
	If KeyboardPushed(#PB_Key_LeftShift)
		camspeed = 0.4
	Else
		camspeed = 0.2
	EndIf
	
	If KeyboardPushed(#PB_Key_A)
		MoveCamera(#camera,  -camspeed, 0, 0)
	EndIf
	If KeyboardPushed(#PB_Key_D)
		MoveCamera(#camera,  camspeed, 0, 0)
	EndIf
	If KeyboardPushed(#PB_Key_W)
		MoveCamera(#camera,  0, 0, -camspeed)
	EndIf
	If KeyboardPushed(#PB_Key_S)
		MoveCamera(#camera,  0, 0, camspeed)  
	EndIf
	
	
	If KeyboardReleased(#PB_Key_R)
		If RenderMode = 0
			CameraRenderMode(#Camera, #PB_Camera_Wireframe)
			RenderMode = 1
		Else
			CameraRenderMode(#Camera, #PB_Camera_Textured)
			RenderMode = 0
		EndIf
	EndIf
	
	
	
	RenderWorld()
	Screen3DStats()
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1


End
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Billboards disappearing

Post by Comtois »

I will give a try to this (as soon as i get time)
http://ogre3d.org/forums/viewtopic.php?f=2&t=58333
Please correct my english
http://purebasic.developpez.com/
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Billboards disappearing

Post by Comtois »

ok your code work with the fix. done for next release,
Please correct my english
http://purebasic.developpez.com/
tastyraspberry
User
User
Posts: 39
Joined: Fri Sep 28, 2012 10:22 am

Re: Billboards disappearing

Post by tastyraspberry »

Comtois wrote:I will give a try to this (as soon as i get time)
http://ogre3d.org/forums/viewtopic.php?f=2&t=58333
Thanks Comtois.

It seems like it might be solved with adding a

Code: Select all

MoveBillboardGroup(myBillboardgroup, 0,  0, 0)
after the addBillboard command. Which may just force an update to the group.

I'm not sure I know how to set the bounds of the group as in the link you showed, but interesting that it has been noticed before. I did try to attach it to a node.

Michael
tastyraspberry
User
User
Posts: 39
Joined: Fri Sep 28, 2012 10:22 am

Re: Billboards disappearing

Post by tastyraspberry »

Comtois wrote:ok your code work with the fix. done for next release,
Wow! I can't complain about the support PureBasic offers! Exemplary. Thank you.

I'll use the temporary fix of MoveBillboardGroup() until the next release.

Michael
Post Reply