Simple Camera?

Blitz3D Forums/Blitz3D Beginners Area/Simple Camera?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Try this, you can also specify where the camera should point at, relative to the entity:
Graphics3D 800,600
SetBuffer BackBuffer()

player = CreateCube()

camera = CreateCamera()

Dim cubes(20) ; create some surroundings
For loop = 0 To 20
   cubes(loop) = CreateCube()
   EntityColor cubes(loop),Rand(0,255),Rand(0,255),Rand(0,255)
   PositionEntity cubes(loop),Rnd(-29,29),0,Rnd(-29,29)
Next

While Not KeyHit(1)

   If KeyDown(200) Then MoveEntity player,0,0,0.1
   If KeyDown(208) Then MoveEntity player,0,0,-0.1
   If KeyDown(203) Then TurnEntity player,0,1,0
   If KeyDown(205) Then TurnEntity player,0,-1,0

;   CameraUpdate(camera,player,0,5,-5,0,-4,0)
   CameraUpdate(camera,player,0,5,-5,0,2,0)
 
   RenderWorld
   Flip
Wend
End

Function CameraUpdate(camera,ent,camx#,camy#,camz#,aimx#=0,aimy#=0,aimz#=0,smoothcam#=0.1,roll#=0)
	
	TFormPoint camx#,camy#,camz#,ent,0
	
	dx#=(TFormedX()-EntityX(camera))*smoothcam#
	dy#=(TFormedY()-EntityY(camera))*smoothcam#
	dz#=(TFormedZ()-EntityZ(camera))*smoothcam#
	
	TranslateEntity camera,dx,dy,dz
	
	TFormPoint aimx#,aimy#,aimz#,ent,0
	
	dx# = EntityX(camera)-TFormedX()
	dy# = EntityY(camera)-TFormedY()
	dz# = EntityZ(camera)-TFormedZ()
	dist#=Sqr#((dx#*dx#)+(dz#*dz#))
	pitch#=ATan2(dy#,dist#)
	yaw#=ATan2(dx#,-dz#)
	
	RotateEntity camera,pitch#,yaw#,roll#
	
End Function