Skip to content

Commit 3ce4aa3

Browse files
committed
IMGUI window visible now
1 parent 33c5af9 commit 3ce4aa3

File tree

8 files changed

+189
-23
lines changed

8 files changed

+189
-23
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"cmake.configureOnOpen": false
2+
"cmake.configureOnOpen": false,
3+
"files.associations": {
4+
"algorithm": "cpp"
5+
}
36
}

RenderingToolkit/Tutorial/apps/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# return()
88
# endif()
99

10-
add_all_subdirectories_except("")
10+
add_all_subdirectories_except("arcball_camera")

RenderingToolkit/Tutorial/apps/ospExamples/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# prefer libGL over libOpenGl for better compatibility with SWR
99
set(OpenGL_GL_PREFERENCE "LEGACY")
10-
10+
add_subdirectory(arcball_camera)
1111
add_executable(ospExamples
1212
${OSPRAY_RESOURCE}
1313
GLFWOSPRayWindow.cpp
@@ -16,11 +16,10 @@ add_executable(ospExamples
1616
)
1717

1818
target_link_libraries(ospExamples
19-
PUBLIC
20-
arcball_camera
21-
ospray_testing
22-
imgui
23-
glfw
19+
PUBLIC arcball_camera
20+
PUBLIC ospray_testing
21+
PUBLIC imgui
22+
PUBLIC glfw
2423
${OPENGL_LIBRARIES}
2524
)
2625

RenderingToolkit/Tutorial/apps/ospExamples/GLFWOSPRayWindow.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ GLFWOSPRayWindow::GLFWOSPRayWindow(const vec2i &windowSize, bool denoiser)
136136
glfwSetErrorCallback(error_callback);
137137

138138
// initialize GLFW
139+
std::cout << "initialize GLFW" << std::endl;
140+
139141
if (!glfwInit()) {
140142
throw std::runtime_error("Failed to initialize GLFW!");
141143
}
@@ -150,6 +152,8 @@ GLFWOSPRayWindow::GLFWOSPRayWindow(const vec2i &windowSize, bool denoiser)
150152
throw std::runtime_error("Failed to create GLFW window!");
151153
}
152154

155+
std::cout << " make the window's context current" << std::endl;
156+
153157
// make the window's context current
154158
glfwMakeContextCurrent(glfwWindow);
155159

@@ -158,6 +162,7 @@ GLFWOSPRayWindow::GLFWOSPRayWindow(const vec2i &windowSize, bool denoiser)
158162
// set initial OpenGL state
159163
glEnable(GL_TEXTURE_2D);
160164
glDisable(GL_LIGHTING);
165+
std::cout << " create OpenGL frame buffer texture" << std::endl;
161166

162167
// create OpenGL frame buffer texture
163168
glGenTextures(1, &framebufferTexture);
@@ -862,17 +867,17 @@ void GLFWOSPRayWindow::commitOutstandingHandles()
862867

863868
void GLFWOSPRayWindow::refreshScene(bool resetCamera)
864869
{
865-
auto builder = testing::newBuilder(scene);
866-
testing::setParam(builder, "rendererType", rendererTypeStr);
867-
if (scene == "curves") {
868-
testing::setParam(builder, "curveVariant", curveVariant);
869-
} else if (scene == "unstructured_volume") {
870-
testing::setParam(builder, "showCells", showUnstructuredCells);
871-
}
872-
testing::commit(builder);
873-
874-
world = testing::buildWorld(builder);
875-
testing::release(builder);
870+
// auto builder = testing::newBuilder(scene);
871+
// testing::setParam(builder, "rendererType", rendererTypeStr);
872+
// if (scene == "curves") {
873+
// testing::setParam(builder, "curveVariant", curveVariant);
874+
// } else if (scene == "unstructured_volume") {
875+
// testing::setParam(builder, "showCells", showUnstructuredCells);
876+
// }
877+
// testing::commit(builder);
878+
879+
// world = testing::buildWorld(builder);
880+
// testing::release(builder);
876881

877882
switch (rendererType) {
878883
case OSPRayRendererType::PATHTRACER: {
@@ -897,7 +902,7 @@ void GLFWOSPRayWindow::refreshScene(bool resetCamera)
897902
renderer->setParam("backgroundColor", bgColor);
898903
addObjectToCommit(renderer->handle());
899904

900-
world.commit();
905+
// world.commit();
901906

902907
if (resetCamera) {
903908
// create the arcball camera model
@@ -907,8 +912,8 @@ void GLFWOSPRayWindow::refreshScene(bool resetCamera)
907912

908913
// init camera
909914
camera.setParam("position", vec3f(0.0f, 0.0f, 1.0f));
910-
updateCamera();
911-
camera.commit();
915+
// updateCamera();
916+
// camera.commit();
912917
}
913918
}
914919

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2017 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#include "ArcballCamera.h"
5+
6+
ArcballCamera::ArcballCamera(const rkcommon::math::box3f &worldBounds,
7+
const rkcommon::math::vec2i &windowSize)
8+
: zoomSpeed(1),
9+
invWindowSize(
10+
rkcommon::math::vec2f(1.0) / rkcommon::math::vec2f(windowSize)),
11+
centerTranslation(rkcommon::math::one),
12+
translation(rkcommon::math::one),
13+
rotation(rkcommon::math::one)
14+
{
15+
rkcommon::math::vec3f diag = worldBounds.size();
16+
zoomSpeed = rkcommon::math::max(length(diag) / 150.0, 0.001);
17+
diag = rkcommon::math::max(diag, rkcommon::math::vec3f(0.3f * length(diag)));
18+
19+
centerTranslation =
20+
rkcommon::math::AffineSpace3f::translate(-worldBounds.center());
21+
translation = rkcommon::math::AffineSpace3f::translate(
22+
rkcommon::math::vec3f(0, 0, length(diag)));
23+
updateCamera();
24+
}
25+
26+
void ArcballCamera::rotate(
27+
const rkcommon::math::vec2f &from, const rkcommon::math::vec2f &to)
28+
{
29+
rotation = screenToArcball(to) * screenToArcball(from) * rotation;
30+
updateCamera();
31+
}
32+
33+
void ArcballCamera::zoom(float amount)
34+
{
35+
amount *= zoomSpeed;
36+
translation = rkcommon::math::AffineSpace3f::translate(
37+
rkcommon::math::vec3f(0, 0, amount))
38+
* translation;
39+
updateCamera();
40+
}
41+
42+
void ArcballCamera::pan(const rkcommon::math::vec2f &delta)
43+
{
44+
const rkcommon::math::vec3f t = rkcommon::math::vec3f(
45+
-delta.x * invWindowSize.x, delta.y * invWindowSize.y, 0);
46+
const rkcommon::math::vec3f worldt =
47+
translation.p.z * xfmVector(invCamera, t);
48+
centerTranslation =
49+
rkcommon::math::AffineSpace3f::translate(worldt) * centerTranslation;
50+
updateCamera();
51+
}
52+
53+
rkcommon::math::vec3f ArcballCamera::eyePos() const
54+
{
55+
return xfmPoint(invCamera, rkcommon::math::vec3f(0, 0, 1));
56+
}
57+
58+
rkcommon::math::vec3f ArcballCamera::center() const
59+
{
60+
return -centerTranslation.p;
61+
}
62+
63+
rkcommon::math::vec3f ArcballCamera::lookDir() const
64+
{
65+
return xfmVector(invCamera, rkcommon::math::vec3f(0, 0, 1));
66+
}
67+
68+
rkcommon::math::vec3f ArcballCamera::upDir() const
69+
{
70+
return xfmVector(invCamera, rkcommon::math::vec3f(0, 1, 0));
71+
}
72+
73+
rkcommon::math::AffineSpace3f ArcballCamera::transform() const
74+
{
75+
return invCamera;
76+
}
77+
78+
void ArcballCamera::updateCamera()
79+
{
80+
const rkcommon::math::AffineSpace3f rot =
81+
rkcommon::math::LinearSpace3f(rotation);
82+
const rkcommon::math::AffineSpace3f camera =
83+
translation * rot * centerTranslation;
84+
invCamera = rcp(camera);
85+
}
86+
87+
void ArcballCamera::setRotation(rkcommon::math::quatf q)
88+
{
89+
rotation = q;
90+
updateCamera();
91+
}
92+
93+
void ArcballCamera::updateWindowSize(const rkcommon::math::vec2i &windowSize)
94+
{
95+
invWindowSize = rkcommon::math::vec2f(1) / rkcommon::math::vec2f(windowSize);
96+
}
97+
98+
rkcommon::math::quatf ArcballCamera::screenToArcball(
99+
const rkcommon::math::vec2f &p)
100+
{
101+
const float dist = dot(p, p);
102+
// If we're on/in the sphere return the point on it
103+
if (dist <= 1.f) {
104+
return rkcommon::math::quatf(0, p.x, p.y, std::sqrt(1.f - dist));
105+
} else {
106+
// otherwise we project the point onto the sphere
107+
const rkcommon::math::vec2f unitDir = normalize(p);
108+
return rkcommon::math::quatf(0, unitDir.x, unitDir.y, 0);
109+
}
110+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2017 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#pragma once
5+
6+
#include "rkcommon/math/AffineSpace.h"
7+
8+
class ArcballCamera
9+
{
10+
public:
11+
ArcballCamera(const rkcommon::math::box3f &worldBounds,
12+
const rkcommon::math::vec2i &windowSize);
13+
14+
// All mouse positions passed should be in [-1, 1] normalized screen coords
15+
void rotate(
16+
const rkcommon::math::vec2f &from, const rkcommon::math::vec2f &to);
17+
void zoom(float amount);
18+
void pan(const rkcommon::math::vec2f &delta);
19+
20+
rkcommon::math::vec3f eyePos() const;
21+
rkcommon::math::vec3f center() const;
22+
rkcommon::math::vec3f lookDir() const;
23+
rkcommon::math::vec3f upDir() const;
24+
rkcommon::math::AffineSpace3f transform() const;
25+
26+
void setRotation(rkcommon::math::quatf);
27+
28+
void updateWindowSize(const rkcommon::math::vec2i &windowSize);
29+
30+
protected:
31+
void updateCamera();
32+
33+
// Project the point in [-1, 1] screen space onto the arcball sphere
34+
rkcommon::math::quatf screenToArcball(const rkcommon::math::vec2f &p);
35+
36+
float zoomSpeed;
37+
rkcommon::math::vec2f invWindowSize;
38+
rkcommon::math::AffineSpace3f centerTranslation, translation, invCamera;
39+
rkcommon::math::quatf rotation;
40+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Copyright 2009 Intel Corporation
2+
## SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(arcball_camera STATIC ArcballCamera.cpp)
5+
target_link_libraries(arcball_camera PUBLIC rkcommon::rkcommon)
6+
target_include_directories(arcball_camera INTERFACE ${CMAKE_CURRENT_LIST_DIR})

RenderingToolkit/Tutorial/apps/ospExamples/ospExample.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ int main(int argc, const char *argv[])
1212
initializeOSPRay(argc, argv, false);
1313

1414
bool denoiser = ospLoadModule("denoiser") == OSP_NO_ERROR;
15+
std::cout << "Creating oSPRray window" << std::endl;
1516

1617
auto glfwOSPRayWindow =
1718
make_unique<GLFWOSPRayWindow>(vec2i(1024, 768), denoiser);
19+
20+
std::cout << "Created oSPRray window" << std::endl;
1821
glfwOSPRayWindow->mainLoop();
19-
glfwOSPRayWindow.reset();
22+
// glfwOSPRayWindow.reset();
2023

2124
ospShutdown();
2225

0 commit comments

Comments
 (0)