summaryrefslogtreecommitdiff
path: root/tangle
diff options
context:
space:
mode:
authorAdrian Kummerlaender2021-06-20 11:52:06 +0200
committerAdrian Kummerlaender2021-06-20 11:52:06 +0200
commite657cd65bccc0c60f5666386409a5f4ae02df626 (patch)
tree8355a7f2ebd6fecfdc8b5338bb9716d9d215bca6 /tangle
parent0f0a35339723e5dc67d2e519f606e5854cfb9e96 (diff)
downloadLiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.tar
LiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.tar.gz
LiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.tar.bz2
LiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.tar.lz
LiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.tar.xz
LiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.tar.zst
LiterateLB-e657cd65bccc0c60f5666386409a5f4ae02df626.zip
Improve camera, volumetric example sections
Diffstat (limited to 'tangle')
-rw-r--r--tangle/sampler/sampler.h1
-rw-r--r--tangle/util/camera.h152
-rw-r--r--tangle/util/volumetric_example.h23
3 files changed, 92 insertions, 84 deletions
diff --git a/tangle/sampler/sampler.h b/tangle/sampler/sampler.h
index ccc50b1..a631bae 100644
--- a/tangle/sampler/sampler.h
+++ b/tangle/sampler/sampler.h
@@ -1,5 +1,4 @@
#pragma once
-
#include <LLBM/base.h>
class RenderWindow;
diff --git a/tangle/util/camera.h b/tangle/util/camera.h
index 4f31489..aa334d9 100644
--- a/tangle/util/camera.h
+++ b/tangle/util/camera.h
@@ -1,85 +1,95 @@
+#pragma once
#include <cuda-samples/Common/helper_math.h>
#include <glm/gtx/quaternion.hpp>
#include "SFML/Window/Event.hpp"
+glm::vec3 apply(glm::quat q, glm::vec3 v) {
+ return glm::axis(q * glm::quat(0, v) * glm::conjugate(q));
+}
+
class Camera {
private:
- glm::quat _rotation;
- glm::vec3 _target;
- glm::vec3 _position;
- glm::vec3 _forward;
- glm::vec3 _right;
- glm::vec3 _up;
- float _distance;
- bool _dragging;
- bool _moving;
- float2 _lastMouse;
+glm::quat _rotation;
+
+glm::vec3 _target;
+glm::vec3 _position;
+glm::vec3 _forward;
+glm::vec3 _right;
+glm::vec3 _up;
+float _distance;
+
+float2 _lastMouse;
+bool _dragging;
+bool _moving;
+
+void update() {
+ _position = _target + apply(_rotation, glm::vec3(0, _distance, 0));
+ _forward = glm::normalize(_target - _position);
+ _right = apply(_rotation, glm::vec3(-1, 0, 0));
+ _up = apply(_rotation, glm::cross(glm::vec3(0, 1, 0), glm::vec3(-1, 0, 0)));
+}
public:
- Camera(float3 target, float distance):
- _distance(distance),
- _target(target.x, target.y, target.z),
- _dragging(false),
- _moving(false) {
- update();
- }
+Camera(float3 target, float distance):
+ _distance(distance),
+ _target(target.x, target.y, target.z),
+ _dragging(false),
+ _moving(false) {
+ update();
+}
- void update() {
- _position = _target + glm::axis(_rotation * glm::quat(0, 0, _distance, 0) * glm::conjugate(_rotation));
- _forward = glm::normalize(_target - _position);
- _right = glm::axis(_rotation * glm::quat(0, -1, 0, 0) * glm::conjugate(_rotation));
- _up = glm::axis(_rotation * glm::quat(0, glm::cross(glm::vec3(0, 1, 0), glm::vec3(-1, 0, 0))) * glm::conjugate(_rotation));
- }
+void handle(sf::Event& event) {
+ switch (event.type) {
+ case sf::Event::MouseButtonPressed:
+ if (event.mouseButton.button == sf::Mouse::Left) {
+ _dragging = true;
+ _lastMouse = make_float2(event.mouseButton.x, event.mouseButton.y);
+ } else if (event.mouseButton.button == sf::Mouse::Right) {
+ _moving = true;
+ _lastMouse = make_float2(event.mouseButton.x, event.mouseButton.y);
+ }
+ break;
+ case sf::Event::MouseButtonReleased:
+ if (event.mouseButton.button == sf::Mouse::Left) {
+ _dragging = false;
+ } else if (event.mouseButton.button == sf::Mouse::Right) {
+ _moving = false;
+ }
+ break;
- void handle(sf::Event& event) {
- switch (event.type) {
- case sf::Event::MouseWheelMoved:
- _distance -= event.mouseWheel.delta * 10;
- break;
- case sf::Event::MouseButtonPressed:
- if (event.mouseButton.button == sf::Mouse::Left) {
- _dragging = true;
- _lastMouse = make_float2(event.mouseButton.x, event.mouseButton.y);
- } else if (event.mouseButton.button == sf::Mouse::Right) {
- _moving = true;
- _lastMouse = make_float2(event.mouseButton.x, event.mouseButton.y);
- }
- break;
- case sf::Event::MouseButtonReleased:
- if (event.mouseButton.button == sf::Mouse::Left) {
- _dragging = false;
- } else if (event.mouseButton.button == sf::Mouse::Right) {
- _moving = false;
- }
- break;
- case sf::Event::MouseMoved:
- float2 mouse = make_float2(event.mouseMove.x, event.mouseMove.y);
- if (_dragging) {
- float2 delta = 0.005 * (mouse - _lastMouse);
- glm::quat rotation_z = glm::vec3(0,0,delta.x);
- glm::quat rotation_x = glm::vec3(delta.y,0,0);
- _rotation *= glm::cross(rotation_x, rotation_z);
- }
- if (_moving) {
- float2 delta = 0.04 * (mouse - _lastMouse);
- _target += _right*delta.x + _up*delta.y;
- }
- _lastMouse = mouse;
- break;
+ case sf::Event::MouseWheelMoved:
+ _distance -= event.mouseWheel.delta * 10;
+ break;
+
+ case sf::Event::MouseMoved:
+ float2 mouse = make_float2(event.mouseMove.x, event.mouseMove.y);
+ if (_dragging) {
+ float2 delta = 0.005 * (mouse - _lastMouse);
+ glm::quat rotation_z = glm::vec3(0,0,delta.x);
+ glm::quat rotation_x = glm::vec3(delta.y,0,0);
+ _rotation *= glm::cross(rotation_x, rotation_z);
}
- update();
- }
- float3 getPosition() const {
- return make_float3(_position.x, _position.y, _position.z);
- }
- float3 getForward() const {
- return make_float3(_forward.x, _forward.y, _forward.z);
- }
- float3 getRight() const {
- return make_float3(_right.x, _right.y, _right.z);
- }
- float3 getUp() const {
- return make_float3(_up.x, _up.y, _up.z);
+ if (_moving) {
+ float2 delta = 0.04 * (mouse - _lastMouse);
+ _target += _right*delta.x + _up*delta.y;
+ }
+ _lastMouse = mouse;
+ break;
}
+ update();
+}
+
+float3 getPosition() const {
+ return make_float3(_position.x, _position.y, _position.z);
+}
+float3 getForward() const {
+ return make_float3(_forward.x, _forward.y, _forward.z);
+}
+float3 getRight() const {
+ return make_float3(_right.x, _right.y, _right.z);
+}
+float3 getUp() const {
+ return make_float3(_up.x, _up.y, _up.z);
+}
};
diff --git a/tangle/util/volumetric_example.h b/tangle/util/volumetric_example.h
index cbcb2d2..3310655 100644
--- a/tangle/util/volumetric_example.h
+++ b/tangle/util/volumetric_example.h
@@ -1,6 +1,5 @@
#pragma once
#include <LLBM/volumetric.h>
-
#include "camera.h"
#include "texture.h"
#include "colormap.h"
@@ -22,17 +21,6 @@ int _steps_per_second = 100;
int _samples_per_second = 30;
public:
-VolumetricExample(descriptor::CuboidD<3> cuboid):
- RenderWindow("LiterateLB"),
- _camera(make_float3(cuboid.nX/2,cuboid.nY/2,cuboid.nZ/2), cuboid.nX),
- _config(cuboid),
- _palette(_config.palette),
- _noise(_config.noise)
-{
- _config.canvas = this->getRenderSurface();
- this->setBlur(_config.apply_blur);
-}
-
template <template<typename...> class SAMPLER, typename... ARGS>
void add(ARGS&&... args) {
_sampler.emplace_back(new SAMPLER(std::forward<ARGS>(args)...));
@@ -120,4 +108,15 @@ void run(TIMESTEP step) {
simulation.wait();
}
+VolumetricExample(descriptor::CuboidD<3> cuboid):
+ RenderWindow("LiterateLB"),
+ _camera(make_float3(cuboid.nX/2,cuboid.nY/2,cuboid.nZ/2), cuboid.nX),
+ _config(cuboid),
+ _palette(_config.palette),
+ _noise(_config.noise)
+{
+ _config.canvas = this->getRenderSurface();
+ this->setBlur(_config.apply_blur);
+}
+
};