camera AB blend

Blitz3D Forums/Blitz3D Programming/camera AB blend

OK here are my routines.

First is the Include file. Save this as "FaderInclude.bb"
Here are the functions:

FadeSetup (LockCameras,[FadeSpeed],[InitialCamera])

This routine will make 2 global cameras called Fade_Cam1 and Fade_Cam2

LockCameras when True will make Fade_Cam1 the parent entity to Fade_Cam2

FadeSpeed sets the speed of the fade.
This is stored in the global variable Fade_Speed
Default value is 10. Accepts any number>0

InitialCamera sets the first camera we will see in the scene.
Defaults to Fade_Cam1
Acceptable values are 1 and 2


RenderFade (DestinationCamera,[tween])

This routine will render your scene exactly like Blitz3D except that it will
fade to the destination camera every call. Should work with tweening as well.
Once the destination camera is reached the routine will only render this camera.

DestinationCamera is the camera we want to see. This can be changed anytime during
a fade.
Acceptable Values are 1 and 2

tween is the tween value passed to the standard RenderWorld.
This defaults To 1 like Blitz.

;Fader Include File

; FadeSetup (LockCameras,[FadeSpeed],[InitialCamera])
;
; This routine will make 2 global cameras called Fade_Cam1 and Fade_Cam2
;
; LockCameras when True will make Fade_Cam1 the parent entity to Fade_Cam2
;
; FadeSpeed sets the speed of the fade.
; This is stored in the global variable Fade_Speed
; Default value is 10. Accepts any number>0
;
; InitialCamera sets the first camera we will see in the scene.
; Defaults to Fade_Cam1
; Acceptable values are 1 and 2


; RenderFade (DestinationCamera,[tween])
; 
; This routine will render your scene exactly like Blitz3D except that it will
; fade to the destination camera every call. Should work with tweening as well.
; Once the destination camera is reached the routine will only render this camera.
;
; DestinationCamera is the camera we want to see. This can be changed anytime during
; a fade.
; Acceptable Values are 1 and 2
;
; tween is the tween value passed to the standard RenderWorld.
; This defaults To 1 like Blitz.

Global Fade_Cam1
Global Fade_Cam2
Global Fade_proj
Global Fade_projalpha#
Global Fade_Speed
Global Fade_Projector

Function FadeSetup(lock,speed=10,destcam=1)
	Fade_Speed=speed
	Fade_Cam1=CreateCamera()
	Fade_Cam2=CreateCamera()
	
	If lock Then EntityParent Fade_Cam2,Fade_Cam1
	
	Fade_Projector=CreateCube(Fade_Cam2)
	ScaleEntity Fade_Projector,1,1,0.01
	MoveEntity Fade_Projector,-0.001,-0.249,1.01
	CameraRange Fade_Cam2,0.1,1000
	
	Fade_proj=CreateTexture(1024,1024,1+256)
	ScaleTexture Fade_proj,1024.0/GraphicsWidth(),1024.0/GraphicsWidth()
	EntityTexture Fade_Projector,Fade_proj
	EntityFX Fade_Projector,1
	
	If destcam=2 Then HideEntity Fade_Projector Else Fade_projalpha#=1.0
	
End Function
	
Function RenderFade(destcam,tween#=1)
	If destcam<1 Or destcam>2 Then destcam=1
	If destcam=2 And Fade_projalpha>0 Then Fade_projalpha=Fade_projalpha-(Fade_Speed/1000.0)
	If destcam=1 And Fade_projalpha<1 Then Fade_projalpha=Fade_projalpha+(Fade_Speed/1000.0)
	
	HideEntity Fade_Projector

	If Fade_projalpha>0 Then
		CameraProjMode Fade_Cam2,0
		CameraProjMode Fade_Cam1,1
		RenderWorld tween
	End If	

	If Fade_projalpha<1 Then
	
		If Fade_projalpha >0 Then
			CopyRect 0,0,800,600,0,0,BackBuffer(),TextureBuffer(Fade_proj)
			EntityAlpha Fade_Projector,Fade_projalpha
			ShowEntity Fade_Projector
		End If
		
		CameraProjMode Fade_Cam2,1
		CameraProjMode Fade_Cam1,0
		RenderWorld
		
	End If
End Function



And here is my previous example now using the new functions.

;Camera Fade Demo

Include "FaderInclude.bb"

SeedRnd MilliSecs()
Graphics3D 800,600,32

dest=1
FadeSetup(True,10,dest)

MoveEntity Fade_Cam1,0,15,-5

lit=CreateLight(2)
MoveEntity lit,0,100,-300

;Just a random ground texture
ground=CreatePlane()
groundtex=CreateTexture(256,256)
SetBuffer TextureBuffer(groundtex)
ScaleTexture groundtex,50,50
For sq=1 To 100
	Color Rand(255),Rand(255),Rand(255)
	Rect Rand(256),Rand(256),Rand(256),Rand(256),True
Next
EntityTexture ground,groundtex

;And some stuff to look at
cube=CreateCube()
sphere=CreateSphere()

enttex=CreateTexture(128,128)
ClsColor 250,100,50
SetBuffer TextureBuffer(enttex)
Cls
Color 50,100,250
Oval 0,0,128,128,1
Color 50,250,100
Oval 44,44,40,40,1
EntityTexture cube,enttex
EntityTexture sphere,enttex
SetBuffer BackBuffer()

cubeflat=CopyEntity(cube)

ScaleEntity cube,3,3,3
MoveEntity cube,15,10,0
MoveEntity sphere,-15,10,0
MoveEntity cubeflat,-15,6,0
ScaleEntity cubeflat,5,2,5

;Camera 1 will look at the cube
;Camera 2 at the sphere
PointEntity Fade_Cam1,cube
PointEntity Fade_Cam2,sphere
	

While Not KeyHit(1)
	;Do some random rotation stuff
	pit#=pit#+(Rnd(2)-1)/10
	yaw#=yaw#+(Rnd(2)-1)/10
	roll#=roll#+(Rnd(2)-1)/10
	
	TurnEntity cube,pit,yaw,roll
	TurnEntity sphere,pit,yaw,roll
	TurnEntity cubeflat,0,-.2,0

If KeyDown(59) Then dest=1
If KeyDown(60) Then dest=2

RenderFade(dest)

Text 10,10,"F1 = Camera 1"
Text 10,20,"F2 = Camera 2"
Text 10,30,"Destination Camera = "+dest

Flip True
Wend
End