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)