Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the camera controller to use the project's camera or a given one #2112

Merged
merged 2 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/appleseed.studio/mainwindow/rendering/cameracontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ namespace studio {
// controller target if the user wishes so (by pressing 'f').
//

CameraController::CameraController(QWidget* widget, Project& project)
: m_widget(widget)
, m_project(project)
, m_custom_camera(nullptr)
, m_custom_camera_enabled(false)
, m_enabled(true)
{
configure_controller();
m_widget->installEventFilter(this);
}

CameraController::CameraController(QWidget* widget, Project& project, Camera* camera)
: m_widget(widget)
, m_project(project)
, m_camera(camera)
, m_custom_camera(camera)
, m_custom_camera_enabled(true)
, m_enabled(true)
{
configure_controller();
Expand All @@ -102,20 +114,22 @@ Transformd CameraController::get_transform() const

void CameraController::update_camera_transform()
{
if (m_camera != nullptr)
if (Camera* camera = fetch_camera())
{
// Moving the camera kills camera motion blur.
m_camera->transform_sequence().clear();
camera->transform_sequence().clear();

// Set the scene camera orientation and position based on the controller.
m_camera->transform_sequence().set_transform(0.0f, get_transform());
camera->transform_sequence().set_transform(0.0f, get_transform());
}
}

void CameraController::save_camera_target()
{
if (m_camera != nullptr)
m_camera->get_parameters().insert("controller_target", m_controller.get_target());
if (Camera* camera = fetch_camera())
{
camera->get_parameters().insert("controller_target", m_controller.get_target());
}
}

void CameraController::slot_entity_picked(ScenePicker::PickingResult result)
Expand Down Expand Up @@ -170,17 +184,27 @@ bool CameraController::eventFilter(QObject* object, QEvent* event)
return QObject::eventFilter(object, event);
}

Camera* CameraController::fetch_camera()
{
if (m_custom_camera_enabled)
return m_custom_camera;
else
return m_project.get_uncached_active_camera();
}

void CameraController::configure_controller()
{
// By default, the pivot point is the scene's center.
m_pivot = Vector3d(m_project.get_scene()->compute_bbox().center());

Camera* camera = fetch_camera();

// Set the controller orientation and position.
if (m_camera != nullptr)
if (camera != nullptr)
{
// Use the scene's camera.
m_controller.set_transform(
m_camera->transform_sequence().get_earliest_transform().get_local_to_parent());
camera->transform_sequence().get_earliest_transform().get_local_to_parent());
}
else
{
Expand All @@ -194,16 +218,16 @@ void CameraController::configure_controller()

// Check whether the camera has a controller target.
const bool has_target =
m_camera != nullptr &&
m_camera->get_parameters().strings().exist("controller_target");
camera != nullptr &&
camera->get_parameters().strings().exist("controller_target");

// Retrieve the controller target from the camera.
Vector3d controller_target;
if (has_target)
{
// The scene's camera has a controller target, retrieve it.
controller_target =
m_camera->get_parameters().get<Vector3d>("controller_target");
camera->get_parameters().get<Vector3d>("controller_target");
}
else
{
Expand Down
13 changes: 12 additions & 1 deletion src/appleseed.studio/mainwindow/rendering/cameracontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class CameraController
public:
// Constructor.
// The camera controller is disabled by default.
// The camera controller controls the project's camera.
CameraController(
QWidget* widget,
renderer::Project& project);

// Constructor.
// The camera controller is disabled by default.
// The camera controller controls the given camera.
CameraController(
QWidget* widget,
renderer::Project& project,
Expand Down Expand Up @@ -91,7 +99,8 @@ class CameraController

QWidget* m_widget;
renderer::Project& m_project;
renderer::Camera* m_camera;
renderer::Camera* m_custom_camera;
const bool m_custom_camera_enabled;
bool m_enabled;

ControllerType m_controller;
Expand All @@ -101,6 +110,8 @@ class CameraController

bool eventFilter(QObject* object, QEvent* event) override;

renderer::Camera* fetch_camera();

bool handle_mouse_button_press_event(const QMouseEvent* event);
bool handle_mouse_button_release_event(const QMouseEvent* event);
bool handle_mouse_move_event(const QMouseEvent* event);
Expand Down
3 changes: 1 addition & 2 deletions src/appleseed.studio/mainwindow/rendering/rendertab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ void RenderTab::recreate_handlers()
m_camera_controller.reset(
new CameraController(
m_render_widget,
m_project,
m_project.get_uncached_active_camera()));
m_project));
connect(
m_camera_controller.get(), SIGNAL(signal_camera_change_begin()),
SIGNAL(signal_camera_change_begin()));
Expand Down