Just a small tip to detect camera moves on a scene with Nova script. We may think that PropertyChanged event on NovaCamera can do it, but not...
Indeed for rendering performance reasons, it's not possible to track every properties changes on NovaCamera (see wiki). So here it is a little script to track camera moves on a Nova scene.
The tip is quite simple: at the scene creation, we store initial coordinates and on every rendering we check current coordinates with the previous one (since we work on floating real, we calculate the daifference according an epsilon). After the calcultation, if there is a difference, the camera moved. Since this check is done on every rendering (ie: 30 fps), the result of differential remains true during this time. We can work on the epsilon value to reduce somewhat the sensitivity, but to reduce it further, it should be considered a lapse of time during which the audit should not take place (using a stopwath as an example).
Here is the code Code:
Private myScene As NovaScene
Private epsilon As Single = 0.0001
Private cameraLastGlobalPosition As Vector3
Private cameraLastRotationPosition As Vector3
Private camera As NovaCamera
Public Sub New(ByVal scene As NovaScene)
myScene = scene
camera = myScene.GetCamera("MainCamera")
StoreCameraPostion()
AddHandler myScene.AfterRender, AddressOf manageAfterRender
End Sub
Private Sub manageAfterRender
If Math.Abs(CType((camera.GlobalPosition - cameraLastGlobalPosition).Length, Single))
> epsilon OrElse Math.Abs(CType((camera.Rotation - cameraLastRotationPosition).Length, Single))
> epsilon Then
StoreCameraPostion()
PluginHelper.LogInfo("it moves!")
End If
End Sub
Public Sub StoreCameraPostion()
cameraLastGlobalPosition = camera.GlobalPosition
cameraLastRotationPosition = camera.Rotation
End Sub
Protected Overrides Sub Finalize()
RemoveHandler myScene.AfterRender, AddressOf ManageAfterRender
End Sub
End Class