; Smooth camera movement
; 2003 Rob Farley
; http://www.mentalillusion.co.uk
;
; If you use this credit would be appreciated, cheers, Rob.
Graphics3D 640,480
SetBuffer BackBuffer()
; create scene
a=CreateMesh()
For n=0 To 199
b=CreateCube()
PositionMesh b,Rand(-20,20),Rand(-20,20),Rand(-20,20)
ScaleMesh b,Rnd(.1,2),Rnd(.1,2),Rnd(.1,2)
RotateMesh b,Rand(0,360),Rand(0,360),Rand(0,360)
AddMesh(b,a)
FreeEntity b
Next
; create camera and light
camera=CreateCamera()
light=CreateLight()
PositionEntity light,200,100,0
; a couple of pivots to control it
camera_pointer=CreatePivot()
target=CreatePivot()
camera_director=CreatePivot()
camera_target=CreatePivot()
; set up initial position
PositionEntity camera,0,0,-20
PositionEntity camera_pointer,0,0,0
Repeat
; this moves the bits around, the /100 is how much smoothing /10 for example would be much faster response
PointEntity camera_pointer,target
MoveEntity camera_pointer,0,0,EntityDistance(camera_pointer,target)/100 ;this is for the target
PositionEntity camera_director,EntityX(camera),EntityY(camera),EntityZ(camera)
PointEntity camera_director,camera_target
MoveEntity camera_director,0,0,(EntityDistance(camera_target,camera_director)/100) ; this for the camera
PositionEntity camera,EntityX(camera_director),EntityY(camera_director),EntityZ(camera_director)
PointEntity camera,camera_pointer
UpdateWorld
RenderWorld
; press space to randomize positions
Color 255,0,0
Text 320,0,"Press Space to Randomise Position, Esc to quit",True
Flip
If KeyHit(57)
PositionEntity target,Rand(-20,20),Rand(-20,20),Rand(-20,20)
PositionEntity camera_target,Rand(-20,20),Rand(-20,20),Rand(-20,20)
EndIf
Until KeyHit(1)
End
|