Moving a camera along a Pivot

Blitz3D Forums/Blitz3D Programming/Moving a camera along a Pivot

Here ya go :) The camera pivot is used for smooth camera turning and movement. The spheres are used as visual waypoint markers :o)

Graphics3D 800,600
SetBuffer BackBuffer()


Global cam = CreateCamera()

Global cam_piv = CreatePivot()

Global waypoint_number = 1

light = CreateLight()

Type waypoint
	Field x#,y#,z#
	Field ent
	Field num
End Type


Global no_of_waypoints = 20 ; number of way points you want
For loop = 1 To no_of_waypoints ; set up random waypoints
	w.waypoint = New waypoint
	w\x = Rnd(-50,50)
	w\y = Rnd(-10,10)
	w\z = Rnd(-50,50)
	w\ent = CreateSphere()
	PositionEntity w\ent,w\x,w\y,w\z
	EntityColor w\ent,200,200,200
	w\num = loop
Next


While Not KeyHit(1)



	update_waypoints() ; call the function to update the cameras position
	UpdateWorld
	RenderWorld
	Text 0,0,waypoint_number
	Flip
	
Wend
End

Function update_waypoints()
	For w.waypoint = Each waypoint
	
		If waypoint_number = w\num Then ; if the waypoint number in the type object is the same as the current waypoint then continue
			PointEntity cam_piv,w\ent ; point the camera pivot at the waypoint
			MoveEntity cam_piv,0,0,0.1 ; move the camera pivot at a speed. increase for faster tracking
			
			PointEntity cam,cam_piv ; point the camera at the camera pivot
			MoveEntity cam,0,0,EntityDistance#(cam,cam_piv)/40 ; move the camera based on the distance between the camera pivot and the camera

			If EntityDistance#(cam_piv,w\ent)<1 Then ; if the camera pivot gets close to a waypoint, move it onto the next waypoint
				waypoint_number = waypoint_number + 1
				If waypoint_number > no_of_waypoints Then waypoint_number = 1
			End If
		End If
		
	Next
End Function