There is no camera aspect ratio implemented in Pb, but you can maintain it by clipping the viewport with the resizecamera command.
I'm always prototyping when I answer questions, so my codes here are never clean or errorproof. I'm thinking something like this:
Edit2: I don't think it behaves the same in both directions. If someone finds better solution, would not mind a better example.
Code: Select all
Global.i camerawidth,cameraheight,targetwindowwidth,targetwindowheight,cameraoffsetx,cameraoffsety,targetaspect.f,aspect.f
#MAINWINDOW = 0
#MAINCAMERA = 0
ExamineDesktops()
maxwidth.i=DesktopWidth(0)
maxheight.i=DesktopHeight(0)
targetwindowWidth=8
targetwindowHeight=6
targetaspect=targetwindowwidth/targetwindowheight
windowWidth=800
windowHeight=600
Procedure.f lerp(a.f,b.f,t.f)
ProcedureReturn(((1.0-t.f)*a) + (b*t))
EndProcedure
Procedure.f invlerp(a.f,b.f,v.f)
Define errorlimit.f=0.0001
If a = b : ProcedureReturn(1) : EndIf
ProcedureReturn (v-a)/(b-a)
EndProcedure
Procedure.f remap(iMin.f,iMax.f,oMin.f,oMax.f,v.f)
Define t.f
t.f=invlerp(iMin,iMax,v)
ProcedureReturn(lerp(oMin,oMax,t))
EndProcedure
Procedure checkwindowsizeforcamera()
aspect=WindowWidth(#mainwindow)/WindowHeight(#MAINWINDOW)
If WindowWidth(#MAINWINDOW)>WindowHeight(#MAINWINDOW)
camerawidth = remap(0,targetaspect*targetwindowwidth,0,100,aspect*WindowWidth(#MAINWINDOW))
cameraheight = 100
Else
camerawidth = 100
cameraheight = remap(0,targetaspect*targetwindowheight,0,100,aspect*WindowHeight(#MAINWINDOW))
EndIf
ResizeCamera(#MAINCAMERA,(100-camerawidth)/2,(100-cameraheight)/2,camerawidth,cameraheight)
EndProcedure
Procedure SizeWindow()
checkwindowsizeforcamera()
RenderWorld()
FlipBuffers()
EndProcedure
If InitEngine3D()=0 Or InitSprite() = 0
MessageRequester("Error", "Error with InitEngine3D!", 0)
End
EndIf
If OpenWindow(0, 0, 0, 800, 600, "Aspect Ratio Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, 800,600,1, 0, 0, 0)
EndIf
CreateCamera(#MAINCAMERA,0,0,100,100)
MoveCamera(#MAINCAMERA,0,150 ,-15, #PB_Absolute)
CameraLookAt(#MAINCAMERA,0,0,0)
BindEvent(#PB_Event_SizeWindow, @SizeWindow())
CreateIcoSphere(0,25,3)
CreateEntity(0,MeshID(0),0,50,0,0)
CreateCube(1,25)
CreateEntity(1,MeshID(1),0,-50,0,0)
CameraBackColor(0 , RGB(120,20,20))
Light1=CreateLight(#PB_Any, RGB(25, 25, 180), -500, 200, 199, #PB_Light_Point)
Light2=CreateLight(#PB_Any, RGB(180, 25, 25), 500, 200, 199, #PB_Light_Point)
Light3=CreateLight(#PB_Any, RGB(25, 180, 25), 0, -500, 0, #PB_Light_Point)
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
RenderWorld()
FlipBuffers()
Delay(1)
ForEver