Moving a camera along a Pivot

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

Clyde(Posted 2004) [#1]
Hiya!

Picture the scene, I am about to make a program that creates mesh sections (A Cave / Tunnel - where it'll have bends and kinks, so it wont be a straight shape and the camera will pass through), which has a pivot for use as the center point / axis for which I'd like the camera to follow and turn where appropriate. Thats the plan anyhow.

I'll be having one function that draws the entire Object in all it's glory and another that hopefully will control the camera movement.

What I'd love to know is, how on I'd get the camera to follow and align it's self to the pivot, and travel in a forward motion; from beginning to the end. Im using Types for this too.

Many many thanks for your help,
-Mikey F :)


Ross C(Posted 2004) [#2]
How is the pivot moving? Or do you have multiple pivots, like way points you want to camera to move along?


Clyde(Posted 2004) [#3]
Exactly like camera waypoints, which the cam travels aligned and rotated to the center of the mesh section

it's multiple pivots as the pivot isn't moving , as For each section there is a pivot parented to that particular part of the mesh with the type field.

Thanks Bud!


Ross C(Posted 2004) [#4]
What to do then is... Have a pivot moving towards each waypoint in turn. Simply point the pivot at the the waypoint. And move it at a constant rate. Now, have the camera follow the moving pivot, a distance behind it, depending on how smooth you want it. The camera will always be pointing at the moving pivot and moving towards it. I'll put together some code :o)


Ross C(Posted 2004) [#5]
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



Ross C(Posted 2004) [#6]
Try messing around with the lines in the function to do with speeds. In particular:

MoveEntity cam,0,0,EntityDistance#(cam,cam_piv)/100


Try that value, smoother moving, but a little slower :o)

Also, try making the cam_piv into a sphere, to see whats going on a little better :o)


Clyde(Posted 2004) [#7]
Thanks a million buddy; terrific and fab :)

Is there another way, in which it would work quicker and more smoother. As this method, is extremely cool for waypoints that are positioned more further away from each other, but for closer points it's a tad slow in updating.

Cheers and many thanks,
Mikey F :)


Clyde(Posted 2004) [#8]
Is there any way to make this smoother and quicker?

Cheers,
Mikey F