camera01=CreateCamera()
camera02=CreateCamera(camera02)
TurnEntity camera02,0,180,0
HideEntity camera02
in the main loop :
; disable parent, to hide camera01 without the 02
entityparent camera02,0
hideentity camera01
ShowEntity camera02
renderworld
=> Copyrect from the camera02 to a texturebuffer, and apply the texture to a mesh that have UV coord form 1 to 0 instead of 0 to 1 .
entityparent camera02,camera01
Hideentity camera02
then make your renderworld:flip etc...
Notice your rear view will be view with a quad that you'll parent to the camera01
Something like this :
;============== TEMPLATE ===================
; <! CONST ===================================
Const C_GW# = 1024
Const C_GH# = 768
Const C_GD% = 0
Const C_GM% = 2
Const C_Key_ESC% = 1
Const C_Key_WIR% = 17
Const C_Key_LF% = 203
Const C_Key_RT% = 205
Const C_Key_UP% = 200
Const C_Key_DN% = 208
; ================================= /! CONST >
Graphics3D C_GW,C_GH,C_GD,C_GM
SetBuffer BackBuffer()
; <! const user =================================
Const C_PivH# = 1.8 ; metres
; ===================================/! const >
world = CreatePivot ()
Piv = CreatePivot (world)
cam = CreateCamera(Piv)
CameraClsColor cam,180,220,255
CameraRange cam,.1,100
; <! Rear View ===================================
RearViewSize = 256
RearQuad= CreateMesh (cam)
s = CreateSurface (RearQuad)
v0 = AddVertex (s, -1.0,.75,1.01,+1,+0)
AddVertex (s, -.25,.75,1.01,+0,+0)
AddVertex (s, -.25,.00,1.01,+0,+1)
AddVertex (s, -1.0,.00,1.01,+1,+1)
AddTriangle s,v0+0,v0+1,v0+2
AddTriangle s,v0+0,v0+2,v0+3
RearTex = CreateTexture(RearViewSize,RearViewSize,1)
RearBuffer= TextureBuffer(RearTex)
EntityTexture RearQuad,RearTex
EntityFX RearQuad,1+8
RearCam = CreateCamera(cam)
TurnEntity RearCam,0,180,0
HideEntity RearCam
CameraViewport rearCam,0,0,RearViewSize,RearViewSize
; ================================= /! Rear View >
; <! Insert Scene ================================
Plan = CreatePlane(1,world)
EntityColor plan,30,80,20
For i = 1 To 10
c = CreateCube(world)
MoveEntity c,Rand(-50,50),1,Rand(-50,50)
Next
redCube=CreateCube()
PositionEntity redCube,-10,1,-10
EntityColor redCube,255,0,0
blueCube=CreateCube()
PositionEntity blueCube,+10,1,+10
EntityColor blueCube,0,0,255
; ===================================/! Insert >
; <! LOOP ===================================
st% = MilliSecs()
lt% = 0
Repeat
; <! Time based Movement ===========
mt% = MilliSecs()
rdt% = mt-(lt+st)
dt# = Float(rdt)
If rdt<2 rdt=2
If rdt>60 rdt=60
lt = lt+dt
; ==========/! Time based Movement >
CAM_Maj_Cam (Piv,cam,dt,0)
; <! Update Rear View ============
EntityParent RearCam,0
HideEntity cam
ShowEntity RearCam
RenderWorld
CopyRect 0,0,RearViewSize,RearViewSize,0,0,BackBuffer(),RearBuffer
EntityParent RearCam,Cam
HideEntity RearCam
ShowEntity Cam
; ============/! Update Rear View >
UpdateWorld (dt#/30)
RenderWorld
; <! Insert Post render =============
Text 10,10,"fps :"+FPS_GetFps(lt)
; =============/!Insert Post render >
; Touche sortie + touche "fil de fer"
If KeyHit(C_Key_ESC) Exit
If KeyHit(C_Key_WIR) wire=1-wire:WireFrame wire
Flip
Forever
; ===================================/! LOOP >
FreeEntity world
ClearWorld 1,1,1
EndGraphics()
End
Function CAM_Maj_Cam(Pivot%,Camera%,dt#,Methode%=0,Ground$="",Gravity#=0,Entity%=0)
If camera<>0 And pivot<>0
Select methode
Case 0 ; fps like
mx# = C_GW/2-MouseX()
my# = C_GH/2-MouseY()
MoveMouse C_GW/2,C_GH/2
Camrx# = EntityPitch (Camera,1)-my#/4
Camry# = EntityYaw (Pivot,1)+mx#/4
camdx# = (KeyDown(C_Key_RT)-KeyDown(C_Key_LF))*DT#/50
camdz# = (KeyDown(C_Key_UP)-KeyDown(C_Key_DN))*DT#/50
Case 1 ; mode libre
camdz# = (KeyDown(C_Key_UP)-KeyDown(C_Key_DN))*DT#/50
End Select
RotateEntity Pivot,0,Camry#,0
RotateEntity camera,Camrx#,0,0
MoveEntity Pivot,camdx,0,camdz
Select Upper(Ground)
Case ""
PositionEntity Pivot,EntityX(Pivot,1),C_PivH,EntityZ(Pivot,1)
Case "TERRAIN"
Terr_y# = TerrainY(entity,EntityX(Pivot,1),0,EntityZ(Pivot,1))
PositionEntity camera,EntityX(camera,1),Terr_y+C_PivH,EntityZ(Pivot,1)
Case "PICK"
LinePick (EntityX(Pivot,1),EntityY(Pivot,1),EntityZ(Pivot,1),0,-2*C_PivH,0)
If PickedEntity()<>0
PositionEntity Pivot,EntityX(Pivot,1),PickedY()+C_PivH,EntityZ(Pivot,1)
Else
If Gravity>0
MoveEntity Pivot,0,-Gravity*dt#/60,0
EndIf
EndIf
End Select
EndIf
End Function
Type Fps_Counter
Field FpsT%
Field FpsCur%
Field FpsRate%
End Type
Function FPS_GetFps(Time%)
fps.FPS_Counter=Last FPS_Counter
If fps=Null fps.FPS_Counter=New FPS_Counter
If time>fps\FpsT
fps\FpsT=Time+1000
fps\FpsRate=fps\FpsCur
fps\FpsCur=0
Else
fps\FpsCur=fps\FpsCur+1
EndIf
Return fps\FpsRate
End Function