Hermite Spline

Blitz3D Forums/Blitz3D Programming/Hermite Spline

Akat(Posted 2003) [#1]
how to implement hermite spline for camera movement from point to point, but the second point was randomly generate...

lets say - point A is current position for the camera. when player hit key 'A' then computer will generate position for point B. then hermite spline will be generated and the camera will move smoothly to the new position. the camera will still there and Point B become point A (current position) until player hit 'A' key again for random Point B and thing go on and on...


Ross C(Posted 2003) [#2]
Hey, Try this. I wrote it up while i'm in college so i can't run it to see if it works, but it seems ok. Press the 1 key to generate a new point for the camera to goto. Press keys 2 and 3 to change the movement mode. I don't know anything about Hermite Spline, but this might do what you want it to :D. Loosely based around Dr Av's cam system.

[EDIT] Got home now, and made changes so it works :)

Graphics3D 800,600
SetBuffer BackBuffer()

Dim cubes(80)
For loop=0 To 80
   cubes(loop)=CreateCube()
   PositionEntity cubes(loop),Rnd(-15,15),Rnd(-15,15),Rnd(-15,15)
   ScaleEntity cubes(loop),0.3,0.3,0.3
Next

Global camera=CreateCamera()
PositionEntity camera,0,2,0

Global light=CreateLight()

Global dest_piv=CreateSphere()
EntityColor dest_piv,100,100,255
EntityAlpha dest_piv,0.4
ScaleEntity dest_piv,0.2,0.2,0.2
Global move_piv=CreatePivot()



Global cam_speed#=100; increase to slow the camera down
Global cam_point=0; if this is set to 0 then the camera will move to the next point, but continue facing the way it is facing. Set to 1 and the camera will face the point.


While Not KeyHit(1)

   If KeyHit(2) Then generate_point( Rnd(-10,10),Rnd(2,5),Rnd(-10,10) )
   If KeyHit(3) Then cam_point=0
   If KeyHit(4) Then cam_point=1


   update_camera(cam_point)
   UpdateWorld
   RenderWorld
   Text 0,0," Press 2 and 3 to change point mode. Current:"+cam_point
Flip
Wend
End

Function generate_point(x#,y#,z#)
   PositionEntity dest_piv,x,y,z
   RotateEntity move_piv,EntityPitch(camera,True),EntityYaw(camera,True),EntityRoll(camera,True)
   PositionEntity move_piv,EntityX(camera),EntityY(camera),EntityZ(camera)
   MoveEntity move_piv,0,0,5
End Function

Function update_camera(point)
   If point=0 Then
      tempx=EntityPitch(camera,True); puts the cam rotations in temp variables
      tempy=EntityYaw(camera,True);same
      tempz=EntityRoll(camera,True);same
      PointEntity camera,dest_piv; point the camera at the destination
      MoveEntity  camera,0,0,EntityDistance(camera,dest_piv)/cam_speed; move the camera the way it's facing,
                                                                      ;based on the distance remaining from the destination
      PositionEntity move_piv,EntityX(camera),EntityY(camera),EntityZ(camera); take the move pivot along so it can be used whenever point mode 1 is needed
      RotateEntity camera,tempx,tempy,tempz; rotate the camera back to its orginal rotations
   ElseIf point=1 Then
      PointEntity camera,dest_piv
      MoveEntity camera,0,0,EntityDistance(camera,dest_piv)/cam_speed
      PointEntity move_piv,dest_piv
      MoveEntity move_piv,0,0,EntityDistance(move_piv,dest_piv)/(cam_speed*0.5); move the move pivot along twice as quick as the camera
      PointEntity camera,move_piv; point the camera at the move pivot, for smooth turning
   End If
End Function



Al Mackey(Posted 2003) [#3]
Correct me if I'm wrong, but I've always thought that splines needed to know the points and timing they're going to travel well in advance. Generally, you can't predict this all that well in a game. You're probably better off going with a smooth camera system that doesn't rely on splines, like the one above.


Akat(Posted 2003) [#4]
yup... quite similar method, but hermite spline will produce slow-out and slow-in graph base on bias and tension (but Ross doing it in fast-out slow-in) - i made something like in-game FMV using hermite spline coz it was an easy thing to retrieve the position data instead generate it randomly - Al Mackey... i think u were right -it is so hard to implement hermite spline in random number (it'll slow the game i think)