Page 1 of 1

Changes to mousecontrols in PB 6 ?

Posted: Fri Jul 07, 2023 3:03 pm
by mrw
Hi,
I recently came back to PB after a while now and started by doing a PB upgrade to 6.02 only to discover some things that don´t work as before.
One of those things is Mouse control functions. In my case I use MouseDeltaX() and MouseDeltaY().
When I run my old testcode below, in PB v6.02, the mouse lags with a couple of seconds and does not work properly at all.
If I run it in v5.70 everything works.
I have search this forum and also the documentation if there are some newer alternatives to these commands that I should be using instead or if I simply need to change some of my implementation to get it to work with PB v6.02.

Any advice is much appreciated.

Code: Select all

Define nx.f, nz.f, Boost.f = 10, Yaw.f, Pitch.f

If InitEngine3D()
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  win_Main=OpenWindow(#PB_Any, 0, 0, 640, 480, "3D Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If win_Main>0       
    Result = OpenWindowedScreen(WindowID(win_Main), 0, 0, WindowWidth(win_Main), WindowHeight(win_Main), 0, 0, 0)
  EndIf
  
  ;-- 3d stuff
  WorldShadows(#PB_Shadow_Additive)
  AmbientColor(0)
  
  ; node for Light and Billboard (Sun)
  node_Sun=CreateNode(#PB_Any, 0, 3000, 0)
  
  ;Create light
  light_Sun=CreateLight(#PB_Any, RGB(90, 105, 132), 0, 3000, 0)
  AttachNodeObject(node_Sun, LightID(light_Sun))
  
  ;Sun
  texture_Sun=CreateTexture(#PB_Any,100,100)
  mat_Sun=CreateMaterial(#PB_Any,TextureID(texture_Sun))
  bbgroup_Sun=CreateBillboardGroup(#PB_Any, MaterialID(mat_Sun), 2048, 2048)
  bb_Sun=AddBillboard(bbgroup_Sun, 0, 3000, 0)
  AttachNodeObject(node_Sun, BillboardGroupID(bbgroup_Sun))
  
    
  ; Create Entity
  CreateCube(0, 1)
  CreateEntity(0, MeshID(0), #PB_Material_None)
  
  ; Create Static geometry
  CreateStaticGeometry(0, 1000, 1000, 1000, #True)
  
  For z = -10 To 10
    For x = -10 To 10
      AddStaticGeometryEntity(0, EntityID(0), x * 1000, 0, z * 1000, 1000,  10, 1000, 0, 0, 0)        
      Height.f = 200 + Random(800)
      AddStaticGeometryEntity(0, EntityID(0), x * 1000, Height/2, z * 1000,  200, Height, 200, 0, Random(360), 0)
    Next
  Next
  
  ; Build the static geometry
  BuildStaticGeometry(0)
  
  FreeEntity(0)
  
  ; Camera
  ;
  CreateCamera(0, 0, 0, 100, 100)
  MoveCamera(0, 2000, 2000, 2000, #PB_Absolute)
  CameraLookAt(0, 0, 0, 0)
  CameraRange (0, 2, 5000)
  CameraFOV   (0, 90)
  CameraBackColor(0, RGB(90, 105, 132))
  
  ;--
  
  Repeat
    Repeat
      Event = WindowEvent()
    Until Event = 0 Or #PB_Event_CloseWindow
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    ExamineKeyboard()             
    If KeyboardPushed(#PB_Key_W)    
      MoveCamera(0,  0, 0, -2 * Boost)
    ElseIf KeyboardPushed(#PB_Key_S)
      MoveCamera(0,  0, 0,  2 * Boost)
    EndIf 
  
    If KeyboardPushed(#PB_Key_A)  
      MoveCamera(0, -2 * Boost, 0, 0) 
    ElseIf KeyboardPushed(#PB_Key_D)
      MoveCamera(0,  2 * Boost, 0, 0)
    EndIf 
    
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      End
    EndIf
    
    ; Sun
    nx = 10000 * Cos(ElapsedMilliseconds() / 2500)
    nz = 10000 * Sin(ElapsedMilliseconds() / 2500)   
    MoveNode(node_Sun, nx, 3000, nz, #PB_Absolute)
      
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    Delay(1)

    RenderWorld()
    FlipBuffers()
  ForEver
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Re: Changes to mousecontrols in PB 6 ?

Posted: Fri Jul 07, 2023 4:15 pm
by Fred
Wasn't very easy to spot, but mouse lagging is often due to wrong event loop and that was the case here:

Code: Select all

Until Event = 0 Or #PB_Event_CloseWindow
Should be indeed:

Code: Select all

Until Event = 0 Or Event = #PB_Event_CloseWindow

Re: Changes to mousecontrols in PB 6 ?

Posted: Fri Jul 07, 2023 4:44 pm
by mrw
Aha! Thanks! That did the trick!
But since this worked in v5.70 I assume something regarding this was changed in v.6? But perhaps is was not related to the Mouse-command itself but rather other stuff?

I also tried a similar test-code that uses just about the same loops and has the exact same problem, but this fix didn´t help there.
But I will look into that more thoroughly. That code is larger and uses some resource-files so I can´t easily show it here.
It might help if I knew what was changed in PB v6.

Anyway, superthanks!

//Andreas..