Skip to content

Commit

Permalink
UI: Add proper delta time configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Dec 12, 2024
1 parent b89455d commit 9f6b417
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "vtkF3DInteractorStyle.h"
#include "vtkF3DRenderer.h"
#include "vtkF3DUIObserver.h"
#include "vtkF3DUIActor.h"

#include <vtkCallbackCommand.h>
#include <vtkCellPicker.h>
Expand Down Expand Up @@ -1136,6 +1137,11 @@ void interactor_impl::start(double loopTime, std::function<void()> userCallBack)
this->Internals->EventLoopUserCallBack = std::move(userCallBack);
}

vtkRenderWindow* renWin = this->Internals->Window.GetRenderWindow();
vtkF3DRenderer* ren =
vtkF3DRenderer::SafeDownCast(renWin->GetRenderers()->GetFirstRenderer());
ren->SetUIDeltaTime(loopTime);

this->Internals->AnimationManager->SetInteractorEventLoopTime(loopTime);
this->Internals->EventLoopTimerId = this->createTimerCallBack(loopTime, [this]() { this->EventLoop(); });
this->Internals->VTKInteractor->Start();
Expand Down
7 changes: 7 additions & 0 deletions vtkext/private/module/vtkF3DImguiActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,10 @@ void vtkF3DImguiActor::EndFrame(vtkOpenGLRenderWindow* renWin)
ImGui::Render();
this->Pimpl->RenderDrawData(renWin, ImGui::GetDrawData());
}

//----------------------------------------------------------------------------
void vtkF3DImguiActor::SetDeltaTime(double time)
{
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = time / 1000;
}
5 changes: 5 additions & 0 deletions vtkext/private/module/vtkF3DImguiActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class vtkF3DImguiActor : public vtkF3DUIActor
*/
void ReleaseGraphicsResources(vtkWindow* w) override;

/**
* Set imgui::DeltaTime, with time in ms
*/
void SetDeltaTime(double time) override;

protected:
vtkF3DImguiActor();
~vtkF3DImguiActor() override;
Expand Down
6 changes: 6 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2621,3 +2621,9 @@ void vtkF3DRenderer::SetCheatSheetConfigured(bool flag)
{
this->CheatSheetConfigured = flag;
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::SetUIDeltaTime(double time)
{
this->UIActor->SetDeltaTime(time);
}
5 changes: 5 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
*/
void SetCheatSheetConfigured(bool flag);

/**
* Set the UI delta time (time between frame being rendered) in ms
*/
void SetUIDeltaTime(double time);

private:
vtkF3DRenderer();
~vtkF3DRenderer() override;
Expand Down
5 changes: 5 additions & 0 deletions vtkext/private/module/vtkF3DUIActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class vtkF3DUIActor : public vtkProp
*/
int RenderOverlay(vtkViewport* vp) override;

/**
* Set the delta time (time between UI frames) in ms
*/
virtual void SetDeltaTime(double time) {}

protected:
vtkF3DUIActor();
~vtkF3DUIActor() override;
Expand Down

0 comments on commit 9f6b417

Please sign in to comment.