Skip to content

Commit

Permalink
Fixed default camera orientation.
Browse files Browse the repository at this point in the history
  • Loading branch information
diharaw committed Dec 19, 2020
1 parent c661a50 commit 511480f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/editor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void PopDisabled()

namespace helios
{
std::vector<std::string> node_types = {
static const std::vector<std::string> node_types = {
"Mesh",
"Camera",
"Directional Light",
Expand All @@ -40,12 +40,12 @@ std::vector<std::string> node_types = {
"IBL"
};

std::vector<std::string> tone_map_operators = {
static const std::vector<std::string> tone_map_operators = {
"ACES",
"Reinhard"
};

std::vector<std::string> output_buffers = {
static const std::vector<std::string> output_buffers = {
"Albedo",
"Normals",
"Roughness",
Expand Down
2 changes: 1 addition & 1 deletion src/engine/resource/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void CameraNode::update(RenderState& render_state)
TransformNode::update(render_state);

m_projection_matrix = glm::perspective(glm::radians(m_fov), float(render_state.viewport_width()) / float(render_state.viewport_height()), m_near_plane, m_far_plane);
m_view_matrix = glm::inverse(m_model_matrix_without_scale);
m_view_matrix = glm::inverse(global_transform_without_scale());

if (!render_state.m_camera)
render_state.m_camera = this;
Expand Down
35 changes: 33 additions & 2 deletions src/viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace helios
{
std::vector<std::string> tone_map_operators = {
static const std::vector<std::string> tone_map_operators = {
"ACES",
"Reinhard"
};

std::vector<std::string> output_buffers = {
static const std::vector<std::string> output_buffers = {
"Albedo",
"Normals",
"Roughness",
Expand Down Expand Up @@ -51,6 +51,8 @@ class Viewer : public Application

if (!m_scene)
return false;

set_default_camera_orientation();
}
else
return false;
Expand Down Expand Up @@ -119,6 +121,9 @@ class Viewer : public Application
m_vk_backend->queue_object_deletion(m_scene);

m_scene = m_resource_manager->load_scene(path, true);

if (m_scene)
set_default_camera_orientation();
}
}
}
Expand Down Expand Up @@ -314,6 +319,32 @@ class Viewer : public Application
// -----------------------------------------------------------------------------------------------------------------------------------

private:
void set_default_camera_orientation()
{
CameraNode::Ptr camera = m_scene->find_camera();

glm::vec3 euler_rad = glm::eulerAngles(camera->orientation());
glm::vec3 euler_degrees = glm::vec3(glm::degrees(euler_rad.x), glm::degrees(euler_rad.y), glm::degrees(euler_rad.z));

if (euler_degrees.z == 180.0f || euler_degrees.z == -180.0f)
{
m_camera_pitch = -(180.0f + euler_degrees.x);
m_camera_yaw = 180.0f + euler_degrees.y;

glm::quat frame_rotation = glm::angleAxis(glm::radians(-m_camera_yaw), glm::vec3(0.0f, 1.0f, 0.0f));
frame_rotation = frame_rotation * glm::angleAxis(glm::radians(-m_camera_pitch), glm::vec3(1.0f, 0.0f, 0.0f));

camera->set_orientation(frame_rotation);
}
else
{
m_camera_pitch = -glm::degrees(euler_rad.x);
m_camera_yaw = -glm::degrees(euler_rad.y);
}
}

// -----------------------------------------------------------------------------------------------------------------------------------

void update_camera()
{
if (m_scene)
Expand Down

0 comments on commit 511480f

Please sign in to comment.