2014-09-18 15:38:37 +00:00
|
|
|
#include "ModelerCameras.h"
|
|
|
|
|
|
|
|
#include "MainModelerWindow.h"
|
|
|
|
#include "OpenGLRenderer.h"
|
|
|
|
#include "Scenery.h"
|
|
|
|
#include "CameraDefinition.h"
|
|
|
|
|
|
|
|
ModelerCameras::ModelerCameras(MainModelerWindow *parent):
|
|
|
|
QObject(parent), parent(parent)
|
|
|
|
{
|
|
|
|
render = new CameraDefinition();
|
|
|
|
topdown = new CameraDefinition();
|
|
|
|
current = new CameraDefinition();
|
|
|
|
active = render;
|
|
|
|
|
|
|
|
// Watch GUI choice
|
|
|
|
QObject *widget = parent->findQmlObject("camera_choice");
|
|
|
|
connect(widget, SIGNAL(stateChanged(QString)), this, SLOT(changeActiveCamera(QString)));
|
|
|
|
|
2015-08-18 20:47:18 +00:00
|
|
|
// Validate to apply initial camera to scenery
|
|
|
|
validate();
|
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
// Start update timer
|
|
|
|
startTimer(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelerCameras::~ModelerCameras()
|
|
|
|
{
|
|
|
|
delete current;
|
|
|
|
delete render;
|
|
|
|
delete topdown;
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:46:39 +00:00
|
|
|
void ModelerCameras::processZoom(double value)
|
|
|
|
{
|
|
|
|
active->strafeForward(value);
|
2015-07-22 16:05:24 +00:00
|
|
|
|
|
|
|
validate();
|
2014-09-26 15:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelerCameras::processScroll(double xvalue, double yvalue)
|
|
|
|
{
|
|
|
|
active->strafeRight(xvalue);
|
|
|
|
active->strafeUp(yvalue);
|
2015-07-22 16:05:24 +00:00
|
|
|
|
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelerCameras::processPanning(double xvalue, double yvalue)
|
|
|
|
{
|
|
|
|
active->rotateYaw(xvalue);
|
|
|
|
active->rotatePitch(yvalue);
|
|
|
|
|
|
|
|
validate();
|
2014-09-26 15:46:39 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
void ModelerCameras::timerEvent(QTimerEvent *)
|
|
|
|
{
|
2014-09-26 15:46:39 +00:00
|
|
|
current->transitionToAnother(active, 0.3);
|
2015-08-18 23:18:16 +00:00
|
|
|
parent->getScenery()->keepCameraAboveGround(current);
|
2015-08-18 20:47:18 +00:00
|
|
|
parent->getRenderer()->setCamera(current);
|
2014-09-18 15:38:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 16:05:24 +00:00
|
|
|
void ModelerCameras::validate()
|
|
|
|
{
|
2015-07-22 16:39:46 +00:00
|
|
|
parent->getScenery()->keepCameraAboveGround(active);
|
|
|
|
|
2015-08-18 23:18:16 +00:00
|
|
|
parent->getScenery()->keepCameraAboveGround(current);
|
|
|
|
parent->getRenderer()->setCamera(current);
|
|
|
|
|
2015-07-22 16:05:24 +00:00
|
|
|
if (active == render) {
|
|
|
|
parent->getScenery()->setCamera(active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
void ModelerCameras::changeActiveCamera(const QString &name)
|
|
|
|
{
|
|
|
|
if (name == "Render camera")
|
|
|
|
{
|
|
|
|
active = render;
|
|
|
|
}
|
|
|
|
else if (name == "Top-down camera")
|
|
|
|
{
|
2015-08-19 23:30:46 +00:00
|
|
|
topdown->setLocation(render->getLocation());
|
|
|
|
topdown->setTarget(render->getTarget());
|
|
|
|
|
|
|
|
topdown->strafeForward(-10.0);
|
|
|
|
topdown->strafeUp(25.0);
|
|
|
|
topdown->rotatePitch(-0.8);
|
|
|
|
|
|
|
|
topdown->validate();
|
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
active = topdown;
|
|
|
|
}
|
|
|
|
}
|