Follow camera


22-09-2010 02:00:06

i use this function, if someone has something better or any suggestions please reply
(written in visual basic)
This function is called every frame
-camera follows a specified node
-camera movement is restricted to the plane 2d
-camera increases / decreases the speed of movement depending on the distance
-camera points to the parent node of the specified node
-action is restricted to 10 milliseconds using a timer
-camera stops moving when you press the right mouse button (in this example uses a library created by me based on MOIS)
Note: to change angle, position of the camera, move _camnodo relative to parent

Public Sub MoverCam()

If _mtime + 10 > Nucleo.Ticks Then Exit Sub '_mtime is a global variable, Nucleo.Ticks is a Mogre.Timer
If InterGUI.Mouse.ButtonDown(MOIS.MouseButtonID.MB_Right) Then Exit Sub ' use MOIS here
_mtime = Nucleo.Ticks
Dim _origen As Mogre.Vector3
Dim _destino As Mogre.Vector3

_destino = _camnodo._getDerivedPosition
_origen = _camara.Position
_origen.y = 0
_destino.y = 0
Dim _speed as Single = 0

Dim v As Mogre.Vector3 = (_destino - _origen)
Dim v1 As Mogre.Vector3 = v
Dim i As Single = v.Normalise()
_speed = i / 20
If _speed > 0 Then

i = i / _speed
End If
If i > 1 Then
v = v1 / i
End If

msg.Text = i 'msg is a InterfazGUI.Caption (like Overlay) just for debbug purpose

End Sub

The following code is used to attach parent
Private Sub AttachCamaratoNodo(ByVal n As Mogre.SceneNode)
If Not _camnodo.ParentSceneNode Is Nothing Then

End If
_camnodo.Position = n.Position


_camnodo.SetPosition(0, 8, -10)
_camara.SetAutoTracking(True, n)

End Sub