mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
More work on converting the old InteractionHandler to new methods
This commit is contained in:
@@ -25,6 +25,11 @@
|
||||
#ifndef __CONTROLLER_H__
|
||||
#define __CONTROLLER_H__
|
||||
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
@@ -32,20 +37,98 @@ class InteractionHandler;
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
Controller() :
|
||||
_handler(nullptr)
|
||||
{}
|
||||
|
||||
void setHandler(InteractionHandler* handler) {
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
protected:
|
||||
SceneGraphNode* focusNode() const {
|
||||
assert(_handler);
|
||||
return _handler->_focusNode;
|
||||
}
|
||||
|
||||
Camera* camera() const {
|
||||
assert(_handler);
|
||||
return _handler->_camera;
|
||||
}
|
||||
|
||||
|
||||
double deltaTime() const {
|
||||
assert(_handler);
|
||||
return _handler->_deltaTime;
|
||||
}
|
||||
|
||||
void orbitDelta(const glm::quat& rotation) {
|
||||
assert(_handler);
|
||||
_handler->lockControls();
|
||||
|
||||
// the camera position
|
||||
psc relative = _handler->_camera->position();
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_handler->_focusNode) {
|
||||
origin = _handler->_focusNode->worldPosition();
|
||||
}
|
||||
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
//glm::mat4 rotation_matrix = glm::mat4_cast(glm::inverse(rotation));
|
||||
//relative_origin_coordinate = relative_origin_coordinate.vec4() * glm::inverse(rotation);
|
||||
relative_origin_coordinate = glm::inverse(rotation) * relative_origin_coordinate.vec4();
|
||||
relative = relative_origin_coordinate + origin;
|
||||
|
||||
_handler->_camera->setPosition(relative);
|
||||
//camera_->rotate(rotation);
|
||||
//camera_->setRotation(glm::mat4_cast(rotation));
|
||||
|
||||
glm::mat4 la = glm::lookAt(_handler->_camera->position().vec3(), origin.vec3(), glm::rotate(rotation, _handler->_camera->lookUpVector()));
|
||||
_handler->_camera->setRotation(la);
|
||||
//camera_->setLookUpVector();
|
||||
|
||||
_handler->unlockControls();
|
||||
}
|
||||
|
||||
void rotateDelta(const glm::quat& rotation) {
|
||||
assert(_handler);
|
||||
_handler->lockControls();
|
||||
_handler->_camera->rotate(rotation);
|
||||
_handler->unlockControls();
|
||||
}
|
||||
|
||||
void distanceDelta(const PowerScaledScalar& distance) {
|
||||
assert(_handler);
|
||||
_handler->lockControls();
|
||||
|
||||
psc relative = _handler->_camera->position();
|
||||
const psc origin = (_handler->_focusNode) ? _handler->_focusNode->worldPosition() : psc();
|
||||
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
const glm::vec3 dir(relative_origin_coordinate.direction());
|
||||
glm:: vec3 newdir = dir * distance[0];
|
||||
relative_origin_coordinate = newdir;
|
||||
relative_origin_coordinate[3] = distance[1];
|
||||
relative = relative + relative_origin_coordinate;
|
||||
|
||||
relative_origin_coordinate = relative - origin;
|
||||
newdir = relative_origin_coordinate.direction();
|
||||
|
||||
// update only if on the same side of the origin
|
||||
if(glm::angle(newdir, dir) < 90.0f)
|
||||
_handler->_camera->setPosition(relative);
|
||||
|
||||
_handler->unlockControls();
|
||||
}
|
||||
|
||||
void lookAt(const glm::quat& rotation) {
|
||||
assert(_handler);
|
||||
}
|
||||
|
||||
void setRotation(const glm::quat& rotation) {
|
||||
assert(_handler);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user