mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
Added call to update of MouseController in update function.
Added distance and orbit functions. modified setRotation function to actually set rotation of camera (was empty)
This commit is contained in:
@@ -118,6 +118,10 @@ public:
|
||||
|
||||
void orbitDelta(const glm::quat& rotation);
|
||||
|
||||
void orbit(const float &dx, const float &dy, const float &dz);
|
||||
|
||||
void distance(const float &d);
|
||||
|
||||
void rotateDelta(const glm::quat& rotation);
|
||||
|
||||
void distanceDelta(const PowerScaledScalar& distance, size_t iterations = 0);
|
||||
|
||||
@@ -475,6 +475,7 @@ void InteractionHandler::unlockControls() {
|
||||
//=======
|
||||
void InteractionHandler::update(double deltaTime) {
|
||||
_deltaTime = deltaTime;
|
||||
_mouseController->update(deltaTime);
|
||||
}
|
||||
|
||||
void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
@@ -518,6 +519,56 @@ void InteractionHandler::mouseScrollWheelCallback(int pos) {
|
||||
_mouseController->scrollWheel(pos);
|
||||
}
|
||||
|
||||
void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz){
|
||||
|
||||
lockControls();
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
|
||||
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz;
|
||||
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
|
||||
|
||||
glm::mat4 transform;
|
||||
transform = glm::rotate(dx, cameraUp) * transform;
|
||||
transform = glm::rotate(dy, cameraRight) * transform;
|
||||
transform = glm::rotate(dz, _camera->viewDirection()) * transform;
|
||||
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
relative_origin_coordinate = glm::inverse(transform) * relative_origin_coordinate.vec4();
|
||||
relative = relative_origin_coordinate + origin;
|
||||
|
||||
_camera->setPosition(relative);
|
||||
_camera->rotate(glm::quat_cast(transform));
|
||||
|
||||
unlockControls();
|
||||
}
|
||||
|
||||
void InteractionHandler::distance(const float &d){
|
||||
|
||||
lockControls();
|
||||
|
||||
psc relative = _camera->position();
|
||||
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
// addition 100% of bounds (fix later to something node specific?)
|
||||
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f);
|
||||
|
||||
psc target = relative + relative_origin_coordinate * d;// *fmaxf(bounds, (1.f - d));
|
||||
//don't fly into objects
|
||||
if ((target - origin).length() < bounds){
|
||||
target = relative;
|
||||
}
|
||||
_camera->setPosition(target);
|
||||
|
||||
unlockControls();
|
||||
}
|
||||
|
||||
void InteractionHandler::orbitDelta(const glm::quat& rotation)
|
||||
{
|
||||
lockControls();
|
||||
@@ -881,6 +932,7 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
|
||||
//=======
|
||||
void InteractionHandler::setRotation(const glm::quat& rotation)
|
||||
{
|
||||
_camera->setRotation(rotation);
|
||||
}
|
||||
|
||||
double InteractionHandler::deltaTime() const {
|
||||
|
||||
Reference in New Issue
Block a user