Skip to content

feature: default orbit in given time #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{"camera-zoom-factor", "", "Camera zoom factor (non-zero)", "<factor>", ""},
{"camera-azimuth-angle", "", "Camera azimuth angle (in degrees), performed after other camera options", "<angle>", ""},
{"camera-elevation-angle", "", "Camera elevation angle (in degrees), performed after other camera options", "<angle>", ""},
{"camera-orthographic", "", "Use an orthographic camera", "<bool>", "1"} } },
{"camera-orthographic", "", "Use an orthographic camera", "<bool>", "1"},
{"camera-orbit", "", "Specify the time to complete a camera orbit", "<seconds>", ""} } },

#if F3D_MODULE_RAYTRACING
{"Raytracing",
Expand Down
1 change: 1 addition & 0 deletions library/private/animationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef f3d_animationManager_h
#define f3d_animationManager_h

#include <vtkCamera.h>
#include <vtkNew.h>
#include <vtkProgressBarWidget.h>
#include <vtkSmartPointer.h>
Expand Down
3 changes: 3 additions & 0 deletions library/private/camera_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class camera_impl : public camera
camera& setState(const camera_state_t& state) override;
camera_state_t getState() override;
void getState(camera_state_t& state) override;
camera& setOrbitTime(double time) override;
double getOrbitTime() const override;

camera& dolly(double val) override;
camera& pan(double right, double up, double forward) override;
Expand Down Expand Up @@ -82,6 +84,7 @@ class camera_impl : public camera
private:
class internals;
std::unique_ptr<internals> Internals;
double orbit_time = 0.0;
};
}

Expand Down
3 changes: 3 additions & 0 deletions library/public/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class F3D_EXPORT camera
virtual camera& setState(const camera_state_t& state) = 0;
[[nodiscard]] virtual camera_state_t getState() = 0;
virtual void getState(camera_state_t& state) = 0;
virtual camera& setOrbitTime(double time) = 0;
[[nodiscard]] virtual double getOrbitTime() const = 0;
// virtual void setOrbitTime(time) = 0;
///@}

///@{ @name Manipulation
Expand Down
7 changes: 7 additions & 0 deletions library/public/options.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public:
// clang-format on
};

namespace options {
namespace scene {
struct camera {
double orbit_time = 0.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that not how you add an option, look at options.json :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

};
}
}
}

// Certain options types are not trivially streamable
Expand Down
18 changes: 18 additions & 0 deletions library/src/animationManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ void animationManager::Tick()
{
this->Window.render();
}

// Check if camera orbit option is enabled
if (this->Options.scene.camera.getOrbitTime() > 0)
{
double orbitTime = this->Options.scene.camera.getOrbitTime();
double angle = 360.0 * (this->CurrentTime / orbitTime);

// Calculate new camera position based on orbit
double radius = 10.0; // Just Example Radius, can be adjusted later
double x = radius * cos(vtkMath::RadiansFromDegrees(angle));
double y = radius * sin(vtkMath::RadiansFromDegrees(angle));

// Update camera position
vtkCamera* camera =
this->Window.GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
camera->SetPosition(x, y, camera->GetPosition()[2]);
camera->SetFocalPoint(0, 0, 0); // Example focal point, can be adjusted
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions library/src/camera_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@ void camera_impl::SetVTKRenderer(vtkRenderer* renderer)
this->Internals->VTKRenderer = renderer;
}

//----------------------------------------------------------------------------
camera& camera_impl::setOrbitTime(double time)
{
this->orbit_time = time;
return *this;
}

double camera_impl::getOrbitTime() const
{
return this->orbit_time;
}

//----------------------------------------------------------------------------
vtkCamera* camera_impl::GetVTKCamera()
{
Expand Down
35 changes: 35 additions & 0 deletions library/testing/TestCameraOrbit.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "PseudoUnitTest.h"

#include <engine.h>
#include <interactor.h>
#include <scene.h>

int TestCameraOrbit(int argc, char* argv[])
{
PseudoUnitTest test;
f3d::engine eng = f3d::engine::create(true);
f3d::scene& sce = eng.getScene();
f3d::interactor& inter = eng.getInteractor();
sce.add(std::string(argv[1]) + "/data/f3d.glb");

// Set camera orbit time
eng.getOptions().scene.camera.orbit_time = 5.0; // 5 seconds for a full orbit

inter.startAnimation();
test("isPlaying after start", inter.isPlayingAnimation());

// Simulate some time passing
sce.loadAnimationTime(2.5); // Halfway through the orbit

// Check camera position
vtkCamera* camera =
sce.getWindow().getRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
double* position = camera->GetPosition();
test("camera x position", std::abs(position[0] - 0.0) < 0.1); // Expect near zero x position
test("camera y position", std::abs(position[1] - 10.0) < 0.1); // Expect near radius y position

inter.stopAnimation();
test("isPlaying after stop", !inter.isPlayingAnimation());

return test.result();
}
Loading