Creating ViewPort

Blitz3D Forums/Blitz3D Programming/Creating ViewPort

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

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.

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.

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:

For p.pl=Each pl

;gravity
TranslateEntity p\cam,0,grav#,0

If p\cont$="Mouse"
;If p\num=1

mouserotatex#=MouseXSpeed()
mouserotate#=mouserotate#+mouserotatex#
RotateEntity p\cam,0,mouserotate#,0
 
If MouseDown(1)
MoveEntity p\cam,0,0,move#
Else If MouseDown( 2 ) And MouseDown(1)
MoveEntity p\cam,0,0,-move#
EndIf 

If MouseHit(2)
PlaySound shoot
b.bullet=New bullet
If p\powbul=0
b\sprite=CopyEntity(spark)
Else 
b\sprite=CopyEntity(spark2)
EndIf     
RotateEntity b\sprite,0,EntityYaw(p\cam),0 
PositionEntity b\sprite,EntityX(p\cam),EntityY(p\cam)+.4,EntityZ(p\cam)
b\angle=0
b\from=1
EntityType b\sprite,TYPE_BULLET
EndIf   

If MouseZ()>0 Then attack1=attack1+1
If MouseZ()<0 Then attack1=attack1-1
attack1=MouseZ()
Select attack1
Case 0
at1$="mine"
Case 1 
at1$="detonater"
Case 2
at1$="flag"
End Select  

If MouseHit(3)

Select at1$ ;find weapon

Case "mine"
m.mine=New mine
m\model=CopyEntity(min) 
PositionEntity m\model,EntityX(p\cam),EntityY(p\cam)-1.4,EntityZ(p\cam)
m\time=0
m\from=1
m\kind=0

Case "detonater"
If mineplaced1=0 
mineplaced1=1
m.mine=New mine
m\model=CopyEntity(min2) 
PositionEntity m\model,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
m\time=0
m\from=1
m\kind=1
EndIf 

Case "flag"
If polep1=0
pole1=LoadMesh("polered.b3d")
PositionEntity pole1,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
EntityColor pole1,255,0,0
ScaleMesh pole1,.1,.1,.1
RotateMesh pole1,0,90,0
polep1=1
EndIf 

End Select 
EndIf 

If MouseDown(1) And MouseDown(2) And MouseDown(3) Then  ;zoom
If zoom#<3
zoom#=zoom#+0.2
EndIf 
Else 
If zoom#>0
zoom#=zoom#-0.2
EndIf 
EndIf 

If zoom#<1 Then zoom#=1
CameraZoom p\cam,zoom#

EndIf
;EndIf 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If p\cont$="Keys"
;If p\num=2

If KeyDown( 205 )
TurnEntity p\cam,0,-2,0
EndIf 
If KeyDown( 203 ) 
TurnEntity p\cam,0,2,0
EndIf 
If KeyDown( 208 )
MoveEntity p\cam,0,0,-move#
Else If KeyDown( 200 )
MoveEntity p\cam,0,0,move#
EndIf 
If KeyHit(157)
b.bullet=New bullet
If p\powbul=0
b\sprite=CopyEntity(spark)
Else 
b\sprite=CopyEntity(spark2)
EndIf  
RotateEntity b\sprite,0,EntityYaw(p\cam),0 
PositionEntity b\sprite,EntityX(p\cam),EntityY(p\cam)+.4,EntityZ(p\cam)
b\angle=0
b\from=2
EntityType b\sprite,TYPE_BULLET
EndIf   
If KeyHit(29)
attack2=attack2+1
Select attack2
Case 0
at2$="mine"
Case 1 
at2$="detonater"
Case 2
at2$="flag"
End Select 
EndIf 
If KeyHit(56)
attack2=attack2-1
Select attack2
Case 0
at2$="mine"
Case 1 
at2$="detonater"
Case 2
at2$="flag"
End Select 
EndIf 

If KeyHit(57)

Select at2$

Case "mine"
m.mine=New mine
m\model=CopyEntity(min) 
PositionEntity m\model,EntityX(p\cam),EntityY(p\cam)-1.4,EntityZ(p\cam)
m\time=0
m\from=2

Case "detonator"
If mineplaced2=0 
mineplaced2=1
m.mine=New mine
m\model=CopyEntity(min2) 
PositionEntity m\model,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
m\time=0
m\from=2
m\kind=1
EndIf 
   
Case "flag"
If polep2=0
pole2=LoadMesh("poleblue.b3d")
PositionEntity pole2,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
EntityColor pole2,0,0,200
ScaleMesh pole2,.1,.1,.1
RotateMesh pole2,0,90,0
polep2=1
EndIf 

End Select 
 
EndIf 

If KeyDown(58) ;zoom
If zoom2#<3
zoom2#=zoom2#+0.2
EndIf 
Else 
If zoom2#>0
zoom2#=zoom2#-0.2
EndIf 
EndIf 

If zoom2#<1 Then zoom2#=1
CameraZoom p\cam,zoom2#

EndIf 

;JOYSTICK;;;;;;;;;;;;;;;;;;;;
If p\cont$="Joy"

If JoyXDir()=1 Then TurnEntity p\cam,0,2,0
If JoyXDir()=-1 Then TurnEntity p\cam,0,-2,0

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

If JoyHit(2)
PlaySound shoot
b.bullet=New bullet
If p\powbul=0
b\sprite=CopyEntity(spark)
Else 
b\sprite=CopyEntity(spark2)
EndIf     
RotateEntity b\sprite,0,EntityYaw(p\cam),0 
PositionEntity b\sprite,EntityX(p\cam),EntityY(p\cam)+.4,EntityZ(p\cam)
b\angle=0
b\from=1
EntityType b\sprite,TYPE_BULLET
EndIf   

If JoyU()<>0 Then attack1=attack1+1
If JoyV()<>0 Then attack1=attack1-1
attack1=MouseZ()
Select attack1
Case 0
at1$="mine"
Case 1 
at1$="detonater"
Case 2
at1$="flag"
End Select  

If JoyHit(3)

Select at1$ ;find weapon

Case "mine"
m.mine=New mine
m\model=CopyEntity(min) 
PositionEntity m\model,EntityX(p\cam),EntityY(p\cam)-1.4,EntityZ(p\cam)
m\time=0
m\from=1
m\kind=0

Case "detonater"
If mineplaced1=0 
mineplaced1=1
m.mine=New mine
m\model=CopyEntity(min2) 
PositionEntity m\model,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
m\time=0
m\from=1
m\kind=1
EndIf 

Case "flag"
If polep1=0
pole1=LoadMesh("polered.b3d")
PositionEntity pole1,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
EntityColor pole1,255,0,0
ScaleMesh pole1,.1,.1,.1
RotateMesh pole1,0,90,0
polep1=1
EndIf 

End Select 
EndIf 

If JoyDown(1) And JoyDown(2) And JoyDown(3) Then  ;zoom
If zoom#<3
zoom#=zoom#+0.2
EndIf 
Else 
If zoom#>0
zoom#=zoom#-0.2
EndIf 
EndIf 

If zoom#<1 Then zoom#=1
CameraZoom p\cam,zoom#

EndIf 

Next 


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.

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 



rats, I forgot to fix that. But none of the control methods work.