inteligent cameras

Blitz3D Forums/Blitz3D Beginners Area/inteligent cameras

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.

Yo, tiler. Try this out. Arrow keys to move the guy. Most of the code sets up the scene :)

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera=CreateCamera()
PositionEntity camera,0,0,-10

Global light=CreateLight()

Global camera_distance=10; set distance camera will be
Global camera_speed#=30; speed the camera moves at. Lower values will move the camera faster!

Global player=CreateSphere()
ScaleEntity player,0.5,0.5,1

Global player_pivot=CreatePivot(player); pivot the camera uses for smooth moving
PositionEntity player_pivot,0,5,-camera_distance ; position the point you want the camera to be at

; create some cube to base movement on
Dim cube(10)
For loop=0 To 10
	cube(loop)=CreateCube()
	PositionEntity cube(loop),Rnd(-10,10),0,Rnd(-10,10)
	EntityColor cube(loop),Rnd(10,110),Rnd(10,110),210
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
	

	update_camera(camera,player_pivot,player,camera_speed) ; update the camera
	
	UpdateWorld
	RenderWorld
	Flip
Wend
End

Function update_camera(cam,pivot,player,speed)

	PointEntity cam,pivot
	If EntityDistance#(cam,pivot) >0.5 Then
		MoveEntity cam,0,0,EntityDistance(cam,pivot)/speed
	End If
	
	PointEntity cam,player
End Function