Creating ViewPort

Blitz3D Forums/Blitz3D Programming/Creating ViewPort

Fuller(Posted 2006) [#1]
For players_creation_loop=1 To players
p.pl=New pl
p\cam=CreateCamera() 
PositionEntity p\cam,0,1,0
EntityRadius p\cam,1.5
EntityType p\cam,TYPE_PLAYER 
p\powbul=0
p\powmine=0
p\num=players_creation_loop
Print "Player "+p\num
If p\num=1 Then p\cont$=p1cont$
If p\num=2 Then p\cont$=p2cont$
If p\num=3 Then p\cont$=p3cont$
If p\num=4 Then p\cont$=p4cont$
If players=2 Then 
If p\num=1 Then CameraViewport p\cam,0,0,GraphicsWidth(),GraphicsHeight()/2 
If p\num=2 Then CameraViewport p\cam,0,GraphicsHeight()/2,GraphicsWidth(),GraphicsHeight() 
EndIf 
If players=3 Or players=4 Then 
If p\num=1 Then CameraViewport p\cam,0,0,GraphicsWidth()/2,GraphicsHeight()/2 
If p\num=2 Then CameraViewport p\cam,GraphicsWidth()/2,0,GraphicsWidth(),GraphicsHeight()/2
If p\num=3 Then CameraViewport p\cam,0,GraphicsHeight()/2,GraphicsWidth()/2,GraphicsHeight() 
If p\num=4 Then CameraViewport p\cam,GraphicsWidth()/2,GraphicsHeight()/2,GraphicsWidth(),GraphicsHeight()
EndIf 
p\health=100
Next 



What's wrong with this? It's supposed to create 4 cameras with four different viewports. Annoying the heck out of me!

It gives me the first viewport and the rest of the screen blank.

And even if players=2 then it gives me 4 viewports


Matty(Posted 2006) [#2]
Graphics3D 800,600,32,2
Type player
Field cam
Field num
End Type

players = 4
For players_creation_loop=1 To players
p.player=New player
p\cam=CreateCamera()
p\num=players_creation_loop
;position camera wherever you want...

If players=2 Then 
If p\num=1 Then CameraViewport p\cam,0,0,GraphicsWidth(),GraphicsHeight()/2
If p\num=2 Then CameraViewport p\cam,0,GraphicsHeight()/2,GraphicsWidth(),GraphicsHeight()/2

ElseIf players>2

Select p\num

Case 1
CameraViewport p\cam,0,0,GraphicsWidth()/2,GraphicsHeight()/2
Case 2
CameraViewport p\cam,GraphicsWidth()/2,0,GraphicsWidth()/2,GraphicsHeight()/2
Case 3
CameraViewport p\cam,0,GraphicsHeight()/2,GraphicsWidth()/2,GraphicsHeight()/2

Case 4
CameraViewport p\cam,GraphicsWidth()/2,GraphicsHeight()/2,GraphicsWidth()/2,GraphicsHeight()/2
End Select


EndIf 



Next


cube=CreateCube()
MoveEntity cube,0,0,10
Repeat

TurnEntity cube,1,2,3
UpdateWorld
RenderWorld
Flip

Until KeyDown(1)
End


..should work..you set the width/height of the 2nd/3rd/4th cameras incorrectly.


Fuller(Posted 2006) [#3]
I look over that about a hundred times and that was all it was... Thanks you, just took some eyes that haven't been looking over it a million times.


Fuller(Posted 2006) [#4]
I'm sorry about this but... I'm having trouble getting the movement. The code's really messy

Using the method above to create the players, here's movement/weapon switching code:



p\cont$ is the controller for your player (mouse,keys,joy)
Part of this is your switching weapons and detonating them.

Here's the code to choose your control type: (AlphaGUI)

If AlphaGetReleased$()="1"
start=1
players_to_find$=AlphaGetValue$("players")
If players_to_find$="0" Then players=2
If players_to_find$="1" Then players=3
If players_to_find$="2" Then players=4
p1cont_find$=AlphaGetValue$("P1cont")
If p1cont_find$="0" Then p1cont$="Mouse"
If p1cont_find$="1" Then p1cont$="Keys"
If p1cont_find$="2" Then p1cont$="Joy"
If p1cont_find$="3" Then p1cont$="XboxJoy"
p2cont_find$=AlphaGetValue$("P2cont")
If p2cont_find$="0" Then p2cont$="Mouse"
If p2cont_find$="1" Then p2cont$="Keys"
If p2cont_find$="2" Then p2cont$="Joy"
If p2cont_find$="3" Then p2cont$="XboxJoy"
p3cont_find$=AlphaGetValue$("P3cont")
If p3cont_find$="0" Then p3cont$="Mouse"
If p3cont_find$="1" Then p3cont$="Keys"
If p3cont_find$="2" Then p3cont$="Joy"
If p3cont_find$="3" Then p3cont$="XboxJoy"
p4cont_find$=AlphaGetValue$("P4cont")
If p4cont_find$="0" Then p4cont$="Mouse"
If p4cont_find$="1" Then p4cont$="Keys"
If p4cont_find$="2" Then p4cont$="Joy"
If p4cont_find$="3" Then p4cont$="XboxJoy"
Cls
Print "Players: "+players
Print "P1: "+p1cont$
Print "P2: "+p2cont$
Print "P3: "+p3cont$
Print "P4: "+p4cont$
EndIf


Sorry it's so messy. It's a project I've restarted after a year gap. Had to convert the whole thing to types.


Matty(Posted 2006) [#5]
Hi Fuller - I had a brief look at the code and your movement with mouse and joystick will not work - this is why:


If MouseDown(1)
MoveEntity p\cam,0,0,move#
Else If MouseDown( 2 ) And MouseDown(1)
MoveEntity p\cam,0,0,-move#
EndIf 

;The program will never execute the code under 'if mousedown(2) and mousedown(1) because if mousedown(1) is true only the top bit will execute.  The same goes for your joystick movement code.




Something like this would work okay:


if mousedown(1)<>0 and mousedown(2)=0 then 

;move forwards

else if mousedown(1)=0 and mousedown(2)<>0 then 

;move backwards

endif 




Fuller(Posted 2006) [#6]
rats, I forgot to fix that. But none of the control methods work.