Test program:
GLOBAL dim playerCamera(MAXPLAYERS) as _PLAYERCAMERA
global screenInfo as _SCREENINFO
resetAllCameras()
getScreenSize()
createViewPort(1,ONEPLAYER_HALFSCREEN)
make object cube 1,500.0
position object 1,0.0,0.0,0.0
position camera playerCamera(PLAYER1).camNum,-100.0,-100,-1000.0
`position camera playerCamera(PLAYER2).camNum,-100.0,-100,-1000.0
`position camera playerCamera(PLAYER3).camNum,-100.0,-100,-1000.0
`position camera playerCamera(PLAYER4).camNum,-100.0,-100,-1000.0
a#=0.0
do
rotate object 1,a#,0.0,0.0
inc a#,2.0
sync
loop
Main Functions:
Rem *** Include File: C:\Program Files\Dark Basic Software\Dark Basic Professional\Routines\MultiCamera.dba ***
Rem Created: 19/10/2003 13:43:16
Rem Included in Project: C:\Program Files\Dark Basic Software\Dark Basic Professional\Projects\TestMultiCamera\TestMultiCamera.dbpro
type _SCREENINFO
screenWidth as DWORD
screenHeight as DWORD
halfX as DWORD
halfY as DWORD
thirdX as DWORD
thirdY as DWORD
endtype
type _PLAYERCAMERA
camNum as DWORD
viewX as DWORD
viewY as DWORD
viewDX as DWORD
viewDY as DWORD
endtype
#constant MAXPLAYERS 4
#constant PLAYER1CAMERA 1
#constant PLAYER2CAMERA 2
#constant PLAYER3CAMERA 3
#constant PLAYER4CAMERA 4
#constant PLAYER1 1
#constant PLAYER2 2
#constant PLAYER3 3
#constant PLAYER4 4
#constant NOCAMERA 0
#constant ONEPLAYER_FULLSCREEN 1<<0
#constant ONEPLAYER_HALFSCREEN 1<<1
#constant ONEPLAYER_169RATIO 1<<2
#constant TWOPLAYER_HORZSPLIT 1<<3
#constant TWOPLAYER_VERTSPLIT 1<<4
#constant THREEPLAYER_HORZSPLIT 1<<5
#constant THREEPLAYER_VERTSPLIT 1<<6
#constant THREEPLAYER_GROUP 1<<7
function getScreenSize
screenInfo.screenWidth=screen width()
screenInfo.screenHeight=screen height()
screenInfo.halfX=screenInfo.screenWidth>>1
screenInfo.halfY=screenInfo.screenHeight>>1
screenInfo.thirdX=screenInfo.screenWidth/3
screenInfo.thirdY=screenInfo.screenHeight/3
endfunction
function resetAllCameras
local l as DWORD
for l=1 to MAXPLAYERS:playerCamera(l).camNum=NOCAMERA:next l
endfunction
function clearAllCameras
local l as DWORD
for l=1 to MAXPLAYERS
if playerCamera(l).camNum<>NOCAMERA
delete camera playerCamera(l).camNum
playerCamera(l).camNum=NOCAMERA
endif
next l
endfunction
function createViewPort(numPlayers as DWORD,flags as DWORD)
local l as DWORD
playerCamera(PLAYER1).camNum=PLAYER1CAMERA
if numPlayers>=2 then playerCamera(PLAYER2).camNum=PLAYER2CAMERA
if numPlayers>=3 then playerCamera(PLAYER3).camNum=PLAYER3CAMERA
if numPlayers=4 then playerCamera(PLAYER4).camNum=PLAYER4CAMERA
select numPlayers
case 1 : REM One player
if flags && ONEPLAYER_FULLSCREEN
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.screenWidth
playerCamera(PLAYER1).viewDY=screenInfo.screenHeight
else
if flags && ONEPLAYER_HALFSCREEN
playerCamera(PLAYER1).viewX=screenInfo.halfX>>1
playerCamera(PLAYER1).viewY=screenInfo.halfY>>1
playerCamera(PLAYER1).viewDX=playerCamera(PLAYER1).viewX+screenInfo.halfX
playerCamera(PLAYER1).viewDY=playerCamera(PLAYER1).viewY+screenInfo.halfY
else
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=screenInfo.halfY>>1
playerCamera(PLAYER1).viewDX=screenInfo.screenWidth
playerCamera(PLAYER1).viewDY=playerCamera(PLAYER1).viewY+screenInfo.halfY
endif
endif
endcase
case 2 : REM Two players
if flags && TWOPLAYER_HORZSPLIT
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.halfX-1
playerCamera(PLAYER1).viewDY=screenInfo.screenHeight
playerCamera(PLAYER2).viewX=screenInfo.halfX+1
playerCamera(PLAYER2).viewY=0
playerCamera(PLAYER2).viewDX=screenInfo.screenWidth
playerCamera(PLAYER2).viewDY=screenInfo.screenHeight
else
if flags && TWOPLAYER_VERTSPLIT
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.screenWidth
playerCamera(PLAYER1).viewDY=screenInfo.halfY-1
playerCamera(PLAYER2).viewX=0
playerCamera(PLAYER2).viewY=screenInfo.halfY+1
playerCamera(PLAYER2).viewDX=screenInfo.screenWidth
playerCamera(PLAYER2).viewDY=screenInfo.screenHeight
endif
endif
endcase
case 3 : REM Three players
if flags && THREEPLAYER_HORZSPLIT
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.thirdX
playerCamera(PLAYER1).viewDY=screenInfo.screenHeight
playerCamera(PLAYER2).viewX=screenInfo.thirdX+1
playerCamera(PLAYER2).viewY=0
playerCamera(PLAYER2).viewDX=(screenInfo.thirdX*2)-1
playerCamera(PLAYER2).viewDY=screenInfo.screenHeight
playerCamera(PLAYER3).viewX=(screenInfo.thirdX*2)+1
playerCamera(PLAYER3).viewY=0
playerCamera(PLAYER3).viewDX=screenInfo.screenWidth
playerCamera(PLAYER3).viewDY=screeninfo.screenHeight
else
if flags && THREEPLAYER_VERTSPLIT
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.screenWidth
playerCamera(PLAYER1).viewDY=screenInfo.thirdY-1
playerCamera(PLAYER2).viewX=0
playerCamera(PLAYER2).viewY=screenInfo.thirdY+1
playerCamera(PLAYER2).viewDX=screenInfo.screenWidth
playerCamera(PLAYER2).viewDY=(screenInfo.thirdY*2)-1
playerCamera(PLAYER3).viewX=0
playerCamera(PLAYER3).viewY=(screenInfo.thirdY*2)+1
playerCamera(PLAYER3).viewDX=screenInfo.screenWidth
playerCamera(PLAYER3).viewDY=screeninfo.screenHeight
else
if flags && THREEPLAYER_GROUP
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.halfX-1
playerCamera(PLAYER1).viewDY=screenInfo.halfY-1
playerCamera(PLAYER2).viewX=screenInfo.halfX+1
playerCamera(PLAYER2).viewY=0
playerCamera(PLAYER2).viewDX=screenInfo.screenWidth
playerCamera(PLAYER2).viewDY=screenInfo.halfY-1
playerCamera(PLAYER3).viewX=0
playerCamera(PLAYER3).viewY=screenInfo.halfY+1
playerCamera(PLAYER3).viewDX=screenInfo.screenWidth
playerCamera(PLAYER3).viewDY=screeninfo.screenHeight
endif
endif
endif
endcase
case 4 : REM 4 players
playerCamera(PLAYER1).viewX=0
playerCamera(PLAYER1).viewY=0
playerCamera(PLAYER1).viewDX=screenInfo.halfX-1
playerCamera(PLAYER1).viewDY=screenInfo.halfY-1
playerCamera(PLAYER2).viewX=screenInfo.halfX+1
playerCamera(PLAYER2).viewY=0
playerCamera(PLAYER2).viewDX=screenInfo.screenWidth
playerCamera(PLAYER2).viewDY=screenInfo.halfY-1
playerCamera(PLAYER3).viewX=0
playerCamera(PLAYER3).viewY=screenInfo.halfY+1
playerCamera(PLAYER3).viewDX=screenInfo.halfX-1
playerCamera(PLAYER3).viewDY=screenInfo.screenHeight
playerCamera(PLAYER4).viewX=screenInfo.halfX+1
playerCamera(PLAYER4).viewY=screenInfo.halfY+1
playerCamera(PLAYER4).viewDX=screenInfo.screenWidth
playerCamera(PLAYER4).viewDY=screenInfo.screenHeight
endcase
endselect
for l=PLAYER1 to PLAYER1+(numPlayers-1)
if playerCamera(l).camNum<>0
make camera playerCamera(l).camNum
set camera view playerCamera(l).camNum,_
playerCamera(l).viewX,playerCamera(l).viewY,_
playerCamera(l).viewDX,playerCamera(l).viewDY
endif
next l
endfunction
The main
createViewPort function is designed to create cameras & viewports for up to 4 cameras, with different styles for up to 3 people :
ONEPLAYER_FULLSCREEN - Creates a full width viewport for one player
ONEPLAYER_HALFSCREEN - Creates a half width and height viewport for one player, centered to the width of the screen.
ONEPLAYER_169RATIO - Creates a full width, but half height viewport for one player, centred to the screen. Emulates the 16:9 TV format.
TWOPLAYER_HORZSPLIT - Creates a two player horizontally split screen
TWOPLAYER_VERTSPLIT - Creates a two player vertically split screen
THREEPLAYER_HORZSPLIT - Creates a three player horizontally split screen
THREEPLAYER_VERTSPLIT - Creates a three player vertically split screen
THREEPLAYER_GROUP - Creates two sections : The top half is split in two horizontally, whilst the bottom half isn't
Avatar & Logo by Indi. Insert witty comment here...