Volume 3D correction test

Everything related to 3D programming
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Volume 3D correction test

Post by falsam »

PB 5.73 (x64)

Hello. This code is a 3D perspective correction test.

I wanted to use the CameraProjectionMode() function but it doesn't work, so I used the ResizeCamera() function to correct the 3D perspective.

Code: Select all

Enumeration window
  #mf  
EndEnumeration


; Window
Global Event, ww = 1024, wh = 768

; 3D
Global Camera, Entity0, Entity1

; Summary
Declare Start()
Declare Render()
Declare Resize()
Declare Exit()

;-
InitEngine3D()
InitSprite()
InitKeyboard()

Start()

Procedure Start()
  OpenWindow(#mf,  0,  0, ww, wh, "Volume 3D correction", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
  OpenWindowedScreen(WindowID(#mf), 0, 0, ww, wh, #True, 0, 0)
    
  Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  CameraBackColor(Camera, RGB(245, 222, 179))
  MoveCamera(Camera, 5, 5, 10)
  CameraLookAt(Camera, 0, 0, 0)
  
  CreateLight(#PB_Any, RGB(255, 255, 255), 0, 10, 10)
  
  Entity0 = CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 2)), #PB_Material_None, 0, 2, 0)
  Entity1 = CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 2)), #PB_Material_None, 0, -2, 0)
  
  BindEvent(#PB_Event_CloseWindow, @Exit())
  BindEvent(#PB_Event_SizeWindow, @Resize())
  
  Render()
EndProcedure

Procedure Render()
  Repeat
    Repeat
      Event = WindowEvent()
    Until Event = 0
    
    RenderWorld()
    FlipBuffers()
    
    If ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Escape)
        Exit()
      EndIf   
    EndIf
    
    RotateEntity(Entity0, 0.5, 0.5, 0.5, #PB_Relative)
    RotateEntity(Entity1, 0.3, 0.3, 0.3, #PB_Relative)
    
    ClearScreen(RGB(128, 128, 128))      
  ForEver
EndProcedure

Procedure Resize()
  ;Not work with ScreenWidth() & ScreenHeight() 
  ;Protected sw = ScreenWidth()
  ;Protected sh = ScreenHeight()

  Protected sw = WindowWidth(#mf, #PB_Window_InnerCoordinate)
  Protected sh = WindowHeight(#mf, #PB_Window_InnerCoordinate)
  
  ; Not work
  ; CameraProjectionMode(Camera, #PB_Camera_Perspective, sw, sh) 
  
  ; Workaround
  ResizeCamera(Camera, 0, 0, 100 - (1 - sw/ww), 100 - (1 - sh/wh))
EndProcedure

Procedure Exit()
  End  
EndProcedure

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Volume 3D correction test

Post by Olli »

Hello falsam,

I remember CameraProjectioMode() seemed to be ok.

Orthographic/perspective switch mode is ok anyway. For width and height, I did not test. What I can read is, this is for plotting range.

In this way, I remember there is 3 modes :
- plots mode
- lines mode
- textured mode

2 solving aspects :
1) only the plots mode is modified by CameraProjectionMode width and height
2) or maybe CameraProjectionMode() must be placed before RenderWorld() every loops...
Post Reply