improved camera controls
This commit is contained in:
parent
9352a30bdf
commit
bae68db6b8
|
|
@ -92,6 +92,7 @@ void Window::free(float* data) {
|
||||||
|
|
||||||
|
|
||||||
void Window::tick() {
|
void Window::tick() {
|
||||||
|
std::cout << "tick tick\n";
|
||||||
// manually track time diff
|
// manually track time diff
|
||||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||||
float diff = (float) std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_frame).count();
|
float diff = (float) std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_frame).count();
|
||||||
|
|
@ -100,10 +101,12 @@ void Window::tick() {
|
||||||
// input
|
// input
|
||||||
this->widget->tick(1000.0/diff);
|
this->widget->tick(1000.0/diff);
|
||||||
|
|
||||||
|
std::cout << "setting tick render\n";
|
||||||
// tick render
|
// tick render
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
std::cout << "blabla\n";
|
||||||
if (!this->widget->paused) this->quad->render();
|
if (!this->widget->paused) this->quad->render();
|
||||||
this->shader->use();
|
this->shader->use();
|
||||||
glBindVertexArray(this->quad->VAO);
|
glBindVertexArray(this->quad->VAO);
|
||||||
|
|
@ -111,11 +114,14 @@ void Window::tick() {
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6); // draw current frame to texture
|
glDrawArrays(GL_TRIANGLES, 0, 6); // draw current frame to texture
|
||||||
|
|
||||||
// render ImGui context
|
// render ImGui context
|
||||||
|
std::cout << "rendering\n";
|
||||||
this->widget->render();
|
this->widget->render();
|
||||||
|
std::cout << "done rendering\n";
|
||||||
|
|
||||||
// check for events
|
// check for events
|
||||||
glfwSwapBuffers(this->window);
|
glfwSwapBuffers(this->window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
std::cout << "done tick tick\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
Widget::Widget(GLFWwindow* window) {
|
Widget::Widget(GLFWwindow* window) {
|
||||||
|
|
@ -13,9 +14,17 @@ Widget::Widget(GLFWwindow* window) {
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
ImGui_ImplOpenGL3_Init();
|
ImGui_ImplOpenGL3_Init();
|
||||||
|
|
||||||
this->cameraPos = Point3::init(64.0f, 42.5f, 250.0f); // Camera for partially trimmed data set
|
// this->cameraPos = Point3::init(64.0f, 42.5f, 250.0f); // Camera for partially trimmed data set
|
||||||
|
this->cameraPos = Point3::init(59.0f, 77.5f, -18.0f); // Camera for partially trimmed data set
|
||||||
// this->cameraPos = Point3::init(300.0f, 200.0f, -700.0f); // Camera for full data set
|
// this->cameraPos = Point3::init(300.0f, 200.0f, -700.0f); // Camera for full data set
|
||||||
this->cameraDir = Point3::init(0.074f, -0.301f, -2.810f);
|
// this->pitch = -1.7;
|
||||||
|
// this->yaw = 1.475;
|
||||||
|
// this->roll = 0;
|
||||||
|
this->pitch = 0.7;
|
||||||
|
this->yaw = 4.85;
|
||||||
|
this->roll = -0.010;
|
||||||
|
this->cameraDir = Vec3::getDirectionFromEuler(pitch, yaw, roll);
|
||||||
|
// this->cameraDir = Point3::init(0.074f, -0.301f, -2.810f);
|
||||||
|
|
||||||
// Vec3 h_center = Vec3::init((float)VOLUME_WIDTH/2.0f, (float)VOLUME_HEIGHT/2.0f, (float)VOLUME_DEPTH/2.0f);
|
// Vec3 h_center = Vec3::init((float)VOLUME_WIDTH/2.0f, (float)VOLUME_HEIGHT/2.0f, (float)VOLUME_DEPTH/2.0f);
|
||||||
// this->cameraDir = (h_center - this->cameraPos).normalize();
|
// this->cameraDir = (h_center - this->cameraPos).normalize();
|
||||||
|
|
@ -119,11 +128,22 @@ void Widget::tick(double fps) {
|
||||||
ImGui::DragScalar("X position", ImGuiDataType_Double, &this->cameraPos.x, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("X position", ImGuiDataType_Double, &this->cameraPos.x, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Y position", ImGuiDataType_Double, &this->cameraPos.z, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("Y position", ImGuiDataType_Double, &this->cameraPos.z, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Z position", ImGuiDataType_Double, &this->cameraPos.y, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("Z position", ImGuiDataType_Double, &this->cameraPos.y, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("X direction", ImGuiDataType_Double, &this->cameraDir.x, 0.005f, &min, &max, "%.3f");
|
// ImGui::DragScalar("X direction", ImGuiDataType_Double, &this->cameraDir.x, 0.005f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Y direction", ImGuiDataType_Double, &this->cameraDir.z, 0.005f, &min, &max, "%.3f");
|
// ImGui::DragScalar("Y direction", ImGuiDataType_Double, &this->cameraDir.z, 0.005f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Z direction", ImGuiDataType_Double, &this->cameraDir.y, 0.005f, &min, &max, "%.3f");
|
// ImGui::DragScalar("Z direction", ImGuiDataType_Double, &this->cameraDir.y, 0.005f, &min, &max, "%.3f");
|
||||||
|
ImGui::DragScalar("Pitch", ImGuiDataType_Double, &this->pitch, 0.005f, &min, &max, "%.3f");
|
||||||
|
ImGui::DragScalar("Yaw", ImGuiDataType_Double, &this->yaw, 0.005f, &min, &max, "%.3f");
|
||||||
|
ImGui::DragScalar("Roll", ImGuiDataType_Double, &this->roll, 0.005f, &min, &max, "%.3f");
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
this->cameraDir.setDirectionFromEuler(pitch, yaw, roll);
|
||||||
|
|
||||||
|
// Calculate upCamera
|
||||||
|
Vec3 arbitraryVector = Vec3::init(1, 0, 0);
|
||||||
|
cameraUp = arbitraryVector.cross(cameraDir);
|
||||||
|
cameraUp.normalize();
|
||||||
|
cameraUp.rotateAroundAxis(cameraDir, roll);
|
||||||
|
|
||||||
copyToDevice();
|
copyToDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,6 +154,7 @@ void Widget::render() {
|
||||||
|
|
||||||
void Widget::copyToDevice() {
|
void Widget::copyToDevice() {
|
||||||
cudaMemcpyToSymbol(&d_cameraPos, &this->cameraPos, sizeof(Point3));
|
cudaMemcpyToSymbol(&d_cameraPos, &this->cameraPos, sizeof(Point3));
|
||||||
|
cudaMemcpyToSymbol(&d_cameraUp, &this->cameraUp, sizeof(Point3));
|
||||||
cudaMemcpyToSymbol(&d_cameraDir, &this->cameraDir, sizeof(Vec3));
|
cudaMemcpyToSymbol(&d_cameraDir, &this->cameraDir, sizeof(Vec3));
|
||||||
cudaMemcpyToSymbol(&d_lightPos, &this->lightPos, sizeof(Point3));
|
cudaMemcpyToSymbol(&d_lightPos, &this->lightPos, sizeof(Point3));
|
||||||
cudaMemcpyToSymbol(&d_backgroundColor, &this->bgColor, sizeof(Color3));
|
cudaMemcpyToSymbol(&d_backgroundColor, &this->bgColor, sizeof(Color3));
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
class Widget {
|
class Widget {
|
||||||
public:
|
public:
|
||||||
Point3 cameraDir;
|
double pitch, yaw, roll;
|
||||||
Vec3 cameraPos;
|
Vec3 cameraUp;
|
||||||
|
Vec3 cameraDir;
|
||||||
|
Point3 cameraPos;
|
||||||
Point3 lightPos;
|
Point3 lightPos;
|
||||||
Color3 bgColor; // TODO: widget
|
Color3 bgColor; // TODO: widget
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer, const
|
||||||
u *= tanHalfFov;
|
u *= tanHalfFov;
|
||||||
v *= tanHalfFov;
|
v *= tanHalfFov;
|
||||||
|
|
||||||
// Find ray direction
|
|
||||||
Vec3 cameraRight = (d_cameraDir.cross(d_cameraUp)).normalize();
|
Vec3 cameraRight = (d_cameraDir.cross(d_cameraUp)).normalize();
|
||||||
d_cameraUp = (cameraRight.cross(d_cameraDir)).normalize();
|
d_cameraUp = (cameraRight.cross(d_cameraDir)).normalize();
|
||||||
Vec3 rayDir = (d_cameraDir + cameraRight*u + d_cameraUp*v).normalize();
|
Vec3 rayDir = (d_cameraDir + cameraRight*u + d_cameraUp*v).normalize();
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,8 @@ __device__ float4 transferFunction(float density, const Vec3& grad, const Point3
|
||||||
result.x = 0.0f;
|
result.x = 0.0f;
|
||||||
result.y = 0.0f;
|
result.y = 0.0f;
|
||||||
result.z = 0.0f;
|
result.z = 0.0f;
|
||||||
result.w = alpha;
|
// result.w = alpha;
|
||||||
|
result.w = d_opacityConst;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,33 @@ struct Vec3 {
|
||||||
__host__ __device__ Vec3 cross(const Vec3& b) const { return Vec3::init(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); }
|
__host__ __device__ Vec3 cross(const Vec3& b) const { return Vec3::init(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); }
|
||||||
__host__ __device__ Vec3 normalize() const { double len = sqrt(x * x + y * y + z * z); return Vec3::init(x / len, y / len, z / len); }
|
__host__ __device__ Vec3 normalize() const { double len = sqrt(x * x + y * y + z * z); return Vec3::init(x / len, y / len, z / len); }
|
||||||
__host__ __device__ double length() const { return sqrt(x * x + y * y + z * z); }
|
__host__ __device__ double length() const { return sqrt(x * x + y * y + z * z); }
|
||||||
|
|
||||||
|
__host__ __device__ void setDirectionFromEuler(double pitch, double yaw, double roll) {
|
||||||
|
// Compute the direction vector using the Euler angles in radians
|
||||||
|
double cosPitch = cos(pitch);
|
||||||
|
double sinPitch = sin(pitch);
|
||||||
|
double cosYaw = cos(yaw);
|
||||||
|
double sinYaw = sin(yaw);
|
||||||
|
|
||||||
|
// Direction vector components
|
||||||
|
x = cosPitch * cosYaw;
|
||||||
|
y = cosPitch * sinYaw;
|
||||||
|
z = sinPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __host__ __device__ Vec3 getDirectionFromEuler(double pitch, double yaw, double roll) {
|
||||||
|
Vec3 v = Vec3::init(1,0,0);
|
||||||
|
v.setDirectionFromEuler(pitch, yaw, roll);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ void rotateAroundAxis(const Vec3& axis, double angle) {
|
||||||
|
double cosA = cos(angle);
|
||||||
|
double sinA = sin(angle);
|
||||||
|
|
||||||
|
Vec3 rotated = *this * cosA + axis.cross(*this) * sinA + axis * axis.dot(*this) * (1 - cosA);
|
||||||
|
*this = rotated;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Vec3 Point3;
|
typedef Vec3 Point3;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue