mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-01 09:08:49 -06:00
changed camera update (for object following) is now done in orbit function of interactionhandler
This commit is contained in:
@@ -552,26 +552,35 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
|
||||
transform = glm::rotate(dy * 10, cameraRight) * transform;
|
||||
transform = glm::rotate(dz * 10, _camera->viewDirection()) * transform;
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
|
||||
//get "old" focus position
|
||||
psc focus = _camera->focusPosition();
|
||||
|
||||
// get camera position
|
||||
psc relative = _camera->position();
|
||||
//get relative vector
|
||||
psc relative_focus_coordinate = relative - focus;
|
||||
//rotate relative vector
|
||||
relative_focus_coordinate = glm::inverse(transform) * relative_focus_coordinate.vec4();
|
||||
|
||||
//get new new position of focus node
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
_camera->setFocusPosition(origin);
|
||||
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
relative_origin_coordinate = glm::inverse(transform) * relative_origin_coordinate.vec4();
|
||||
relative = origin + relative_origin_coordinate; //relative_origin_coordinate + origin;
|
||||
//new camera position
|
||||
relative = origin + relative_focus_coordinate;
|
||||
|
||||
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f);
|
||||
|
||||
psc target = relative + relative_origin_coordinate * dist;// *fmaxf(bounds, (1.f - d));
|
||||
psc target = relative + relative_focus_coordinate * dist;
|
||||
//don't fly into objects
|
||||
if ((target - origin).length() < bounds){
|
||||
target = relative;
|
||||
}
|
||||
|
||||
_camera->setFocusPosition(origin);
|
||||
_camera->setPosition(target);
|
||||
_camera->rotate(glm::quat_cast(transform));
|
||||
|
||||
@@ -866,7 +875,8 @@ void InteractionHandler::keyboardCallback(int key, int action) {
|
||||
_validKeyLua = true;
|
||||
auto ret = _keyLua.equal_range(key);
|
||||
for (auto it = ret.first; it != ret.second; ++it) {
|
||||
OsEng.scriptEngine().runScript(it->second);
|
||||
//OsEng.scriptEngine().runScript(it->second);
|
||||
OsEng.scriptEngine().queueScript(it->second);
|
||||
if (!_validKeyLua) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -223,13 +223,13 @@ void OrbitalMouseController::scrollWheel(int pos) {
|
||||
|
||||
void OrbitalMouseController::update(const double& dt){
|
||||
|
||||
if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
|
||||
//if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
|
||||
_handler->orbit(
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed,
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed,
|
||||
static_cast<float>(_middleMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonMiddle].x * _rotationSpeed,
|
||||
static_cast<float>(_rightMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
|
||||
}
|
||||
//}
|
||||
|
||||
// if (_leftMouseButtonDown){
|
||||
// _handler->orbit(static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed, static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed, 0.f);
|
||||
|
||||
@@ -306,7 +306,7 @@ void RenderEngine::postSynchronizationPreDraw()
|
||||
if (_mainCamera){
|
||||
_mainCamera->postSynchronizationPreDraw();
|
||||
}
|
||||
|
||||
|
||||
sgct_core::SGCTNode * thisNode = sgct_core::ClusterManager::instance()->getThisNodePtr();
|
||||
bool updateAbuffer = false;
|
||||
for (unsigned int i = 0; i < thisNode->getNumberOfWindows(); i++) {
|
||||
@@ -330,6 +330,7 @@ void RenderEngine::postSynchronizationPreDraw()
|
||||
Time::ref().deltaTime(),
|
||||
_doPerformanceMeasurements
|
||||
});
|
||||
|
||||
_sceneGraph->evaluate(_mainCamera);
|
||||
|
||||
// clear the abuffer before rendering the scene
|
||||
@@ -337,9 +338,9 @@ void RenderEngine::postSynchronizationPreDraw()
|
||||
|
||||
//Allow focus node to update camera (enables camera-following)
|
||||
//FIX LATER: THIS CAUSES MASTER NODE TO BE ONE FRAME AHEAD OF SLAVES
|
||||
if (const SceneGraphNode* node = OsEng.ref().interactionHandler().focusNode()){
|
||||
/*if (const SceneGraphNode* node = OsEng.ref().interactionHandler().focusNode()){
|
||||
node->updateCamera(_mainCamera);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user