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