Skip to content

Commit d3bd610

Browse files
szellmannjeffamstutz
authored andcommitted
Add omnidirectional camera option to TSD viewport
1 parent dd835a5 commit d3bd610

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

tsd/apps/interactive/common/windows/Viewport.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void Viewport::setLibrary(const std::string &libName, bool doAsync)
172172

173173
m_perspCamera = anari::newObject<anari::Camera>(d, "perspective");
174174
m_orthoCamera = anari::newObject<anari::Camera>(d, "orthographic");
175+
m_omniCamera = anari::newObject<anari::Camera>(d, "omnidirectional");
175176

176177
tsd::logStatus("[viewport] populating render index...");
177178

@@ -226,12 +227,14 @@ void Viewport::teardownDevice()
226227

227228
anari::release(m_device, m_perspCamera);
228229
anari::release(m_device, m_orthoCamera);
230+
anari::release(m_device, m_omniCamera);
229231
for (auto &r : m_renderers)
230232
anari::release(m_device, r);
231233
anari::release(m_device, m_device);
232234

233235
m_perspCamera = nullptr;
234236
m_orthoCamera = nullptr;
237+
m_omniCamera = nullptr;
235238
m_renderers.clear();
236239
m_rendererObjects.clear();
237240
m_device = nullptr;
@@ -324,7 +327,12 @@ void Viewport::updateFrame()
324327
return;
325328

326329
m_rud.r = m_renderers[m_currentRenderer];
327-
m_anariPass->setCamera(m_useOrthoCamera ? m_orthoCamera : m_perspCamera);
330+
if (m_cameraModel == CameraModel::Orthographic)
331+
m_anariPass->setCamera(m_orthoCamera);
332+
else if (m_cameraModel == CameraModel::Omnidirectional)
333+
m_anariPass->setCamera(m_omniCamera);
334+
else
335+
m_anariPass->setCamera(m_perspCamera);
328336
m_anariPass->setRenderer(m_rud.r);
329337
m_anariPass->setWorld(m_rIdx->world());
330338
}
@@ -348,6 +356,10 @@ void Viewport::updateCamera(bool force)
348356
anari::setParameter(
349357
m_device, m_orthoCamera, "height", m_arcball->distance() * 0.75f);
350358

359+
anari::setParameter(m_device, m_omniCamera, "position", m_arcball->eye());
360+
anari::setParameter(m_device, m_omniCamera, "direction", m_arcball->dir());
361+
anari::setParameter(m_device, m_omniCamera, "up", m_arcball->up());
362+
351363
anari::setParameter(m_device,
352364
m_perspCamera,
353365
"aspect",
@@ -365,6 +377,7 @@ void Viewport::updateCamera(bool force)
365377

366378
anari::commitParameters(m_device, m_perspCamera);
367379
anari::commitParameters(m_device, m_orthoCamera);
380+
anari::commitParameters(m_device, m_omniCamera);
368381

369382
if (m_echoCameraConfig)
370383
echoCameraConfig();
@@ -504,7 +517,7 @@ void Viewport::ui_picking()
504517

505518
// Pick view center //
506519

507-
const bool shouldPickCenter = !m_useOrthoCamera
520+
const bool shouldPickCenter = m_cameraModel == CameraModel::Perspective
508521
&& ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)
509522
&& io.KeysDown[GLFW_KEY_LEFT_SHIFT];
510523
if (shouldPickCenter && ImGui::IsWindowHovered()) {
@@ -637,10 +650,15 @@ void Viewport::ui_contextMenu()
637650
ImGui::Text("Camera:");
638651
ImGui::Indent(INDENT_AMOUNT);
639652

640-
if (ImGui::Checkbox("orthographic", &m_useOrthoCamera))
653+
if (ImGui::RadioButton(
654+
"perspective", &m_cameraModel, CameraModel::Perspective)
655+
|| ImGui::RadioButton(
656+
"orthographic", &m_cameraModel, CameraModel::Orthographic)
657+
|| ImGui::RadioButton(
658+
"omnidirectional", &m_cameraModel, CameraModel::Omnidirectional))
641659
updateFrame();
642660

643-
ImGui::BeginDisabled(m_useOrthoCamera);
661+
ImGui::BeginDisabled(m_cameraModel != CameraModel::Perspective);
644662

645663
if (ImGui::SliderFloat("fov", &m_fov, 0.1f, 180.f))
646664
updateCamera(true);

tsd/apps/interactive/common/windows/Viewport.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525

2626
namespace tsd_viewer {
2727

28+
struct CameraModel
29+
{
30+
constexpr static int Perspective{0};
31+
constexpr static int Orthographic{1};
32+
constexpr static int Omnidirectional{2};
33+
};
34+
2835
struct Viewport : public anari_viewer::windows::Window
2936
{
3037
Viewport(
@@ -75,7 +82,7 @@ struct Viewport : public anari_viewer::windows::Window
7582
bool m_highlightSelection{true};
7683
bool m_showOnlySelected{false};
7784
int m_frameSamples{0};
78-
bool m_useOrthoCamera{false};
85+
int m_cameraModel{CameraModel::Perspective};
7986

8087
bool m_visualizeDepth{false};
8188
float m_depthVisualMaximum{1.f};
@@ -89,6 +96,7 @@ struct Viewport : public anari_viewer::windows::Window
8996
anari::Device m_device{nullptr};
9097
anari::Camera m_perspCamera{nullptr};
9198
anari::Camera m_orthoCamera{nullptr};
99+
anari::Camera m_omniCamera{nullptr};
92100

93101
std::vector<std::string> m_rendererNames;
94102
std::vector<anari::Renderer> m_renderers;

0 commit comments

Comments
 (0)