mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-02 16:59:37 -05:00
merge in changes from develop
This commit is contained in:
@@ -76,6 +76,7 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/util/boxgeometry.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/camera.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/factorymanager.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/keys.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/powerscaledcoordinate.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/powerscaledscalar.cpp
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace {
|
||||
const std::string RequestApplicationVersion = "application_version";
|
||||
|
||||
struct ProgressInformation {
|
||||
openspace::DownloadManager::FileFuture* future;
|
||||
std::shared_ptr<openspace::DownloadManager::FileFuture> future;
|
||||
std::chrono::system_clock::time_point startTime;
|
||||
const openspace::DownloadManager::DownloadProgressCallback* callback;
|
||||
};
|
||||
@@ -133,14 +133,14 @@ DownloadManager::DownloadManager(std::string requestURL, int applicationVersion,
|
||||
// TODO: Allow for multiple requestURLs
|
||||
}
|
||||
|
||||
DownloadManager::FileFuture* DownloadManager::downloadFile(
|
||||
std::shared_ptr<DownloadManager::FileFuture> DownloadManager::downloadFile(
|
||||
const std::string& url, const ghoul::filesystem::File& file, bool overrideFile,
|
||||
DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback)
|
||||
{
|
||||
if (!overrideFile && FileSys.fileExists(file))
|
||||
return nullptr;
|
||||
|
||||
FileFuture* future = new FileFuture(file.filename());
|
||||
std::shared_ptr<FileFuture> future = std::make_shared<FileFuture>(file.filename());
|
||||
FILE* fp = fopen(file.path().c_str(), "wb");
|
||||
|
||||
LDEBUG("Start downloading file: '" << url << "' into file '" << file.path() << "'");
|
||||
@@ -196,12 +196,12 @@ DownloadManager::FileFuture* DownloadManager::downloadFile(
|
||||
return future;
|
||||
}
|
||||
|
||||
std::vector<DownloadManager::FileFuture*> DownloadManager::downloadRequestFiles(
|
||||
std::vector<std::shared_ptr<DownloadManager::FileFuture>> DownloadManager::downloadRequestFiles(
|
||||
const std::string& identifier, const ghoul::filesystem::Directory& destination,
|
||||
int version, bool overrideFiles, DownloadFinishedCallback finishedCallback,
|
||||
DownloadProgressCallback progressCallback)
|
||||
{
|
||||
std::vector<FileFuture*> futures;
|
||||
std::vector<std::shared_ptr<FileFuture>> futures;
|
||||
FileSys.createDirectory(destination, ghoul::filesystem::FileSystem::Recursive::Yes);
|
||||
// TODO: Check s ---abock
|
||||
// TODO: Escaping is necessary ---abock
|
||||
@@ -232,7 +232,7 @@ std::vector<DownloadManager::FileFuture*> DownloadManager::downloadRequestFiles(
|
||||
|
||||
LDEBUG("\tLine: " << line << " ; Dest: " << destination.path() + "/" + file);
|
||||
|
||||
FileFuture* future = DlManager.downloadFile(
|
||||
std::shared_ptr<FileFuture> future = DlManager.downloadFile(
|
||||
line,
|
||||
destination.path() + "/" + file,
|
||||
overrideFiles,
|
||||
@@ -244,7 +244,7 @@ std::vector<DownloadManager::FileFuture*> DownloadManager::downloadRequestFiles(
|
||||
isFinished = true;
|
||||
};
|
||||
|
||||
FileFuture* f = downloadFile(
|
||||
std::shared_ptr<FileFuture> f = downloadFile(
|
||||
fullRequest,
|
||||
requestFile,
|
||||
true,
|
||||
@@ -261,7 +261,7 @@ void DownloadManager::downloadRequestFilesAsync(const std::string& identifier,
|
||||
AsyncDownloadFinishedCallback callback)
|
||||
{
|
||||
auto downloadFunction = [this, identifier, destination, version, overrideFiles, callback](){
|
||||
std::vector<FileFuture*> f = downloadRequestFiles(
|
||||
std::vector<std::shared_ptr<FileFuture>> f = downloadRequestFiles(
|
||||
identifier,
|
||||
destination,
|
||||
version,
|
||||
|
||||
@@ -35,96 +35,28 @@
|
||||
#include <ghoul/misc/interpolator.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "InteractionHandler";
|
||||
|
||||
openspace::Key stringToKey(std::string s) {
|
||||
// key only uppercase
|
||||
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
|
||||
|
||||
// default is unknown
|
||||
auto it = openspace::KeyMapping.find(s);
|
||||
if (it != openspace::KeyMapping.end())
|
||||
return it->second;
|
||||
else
|
||||
return openspace::Key::Unknown;
|
||||
}
|
||||
const std::string _loggerCat = "InteractionHandler";
|
||||
}
|
||||
|
||||
#include "interactionhandler_lua.inl"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
//InteractionHandler::InteractionHandler() {
|
||||
// // initiate pointers
|
||||
// _camera = nullptr;
|
||||
// _enabled = true;
|
||||
// _node = nullptr;
|
||||
// _dt = 0.0;
|
||||
// _lastTrackballPos = glm::vec3(0.0, 0.0, 0.5);
|
||||
// _leftMouseButtonDown = false;
|
||||
// _isMouseBeingPressedAndHeld = false;
|
||||
//}
|
||||
//
|
||||
//InteractionHandler::~InteractionHandler() {
|
||||
// for (size_t i = 0; i < _controllers.size(); ++i) {
|
||||
// delete _controllers[i];
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////void InteractionHandler::init() {
|
||||
//// assert( ! this_);
|
||||
//// this_ = new InteractionHandler();
|
||||
////}
|
||||
////
|
||||
////void InteractionHandler::deinit() {
|
||||
//// assert(this_);
|
||||
//// delete this_;
|
||||
//// this_ = nullptr;
|
||||
////}
|
||||
////
|
||||
////InteractionHandler& InteractionHandler::ref() {
|
||||
//// assert(this_);
|
||||
//// return *this_;
|
||||
////}
|
||||
//
|
||||
////bool InteractionHandler::isInitialized() {
|
||||
//// return this_ != nullptr;
|
||||
////}
|
||||
//
|
||||
//void InteractionHandler::enable() {
|
||||
// //assert(this_);
|
||||
// _enabled = true;
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::disable() {
|
||||
// //assert(this_);
|
||||
// _enabled = false;
|
||||
//}
|
||||
//
|
||||
//const bool InteractionHandler::isEnabled() const {
|
||||
// //assert(this_);
|
||||
// if (_camera)
|
||||
// return false;
|
||||
// return _enabled;
|
||||
//=======
|
||||
|
||||
//namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
InteractionHandler::InteractionHandler()
|
||||
: properties::PropertyOwner()
|
||||
, _camera(nullptr)
|
||||
, _focusNode(nullptr)
|
||||
, _camera(nullptr)
|
||||
, _focusNode(nullptr)
|
||||
, _deltaTime(0.0)
|
||||
, _validKeyLua(false)
|
||||
, _controllerSensitivity(1.f)
|
||||
, _invertRoll(false)
|
||||
, _invertRotation(false)
|
||||
, _keyboardController(nullptr)
|
||||
, _mouseController(nullptr)
|
||||
, _keyboardController(nullptr)
|
||||
, _mouseController(nullptr)
|
||||
, _origin("origin", "Origin", "")
|
||||
, _coordinateSystem("coordinateSystem", "Coordinate System", "")
|
||||
, _currentKeyframeTime(-1.0)
|
||||
, _currentKeyframeTime(-1.0)
|
||||
{
|
||||
setName("Interaction");
|
||||
|
||||
@@ -145,104 +77,51 @@ InteractionHandler::InteractionHandler()
|
||||
}
|
||||
|
||||
InteractionHandler::~InteractionHandler() {
|
||||
delete _keyboardController;
|
||||
delete _mouseController;
|
||||
for (size_t i = 0; i < _controllers.size(); ++i)
|
||||
delete _controllers[i];
|
||||
delete _keyboardController;
|
||||
delete _mouseController;
|
||||
for (size_t i = 0; i < _controllers.size(); ++i)
|
||||
delete _controllers[i];
|
||||
}
|
||||
|
||||
void InteractionHandler::setKeyboardController(KeyboardController* controller) {
|
||||
assert(controller);
|
||||
delete _keyboardController;
|
||||
_keyboardController = controller;
|
||||
_keyboardController->setHandler(this);
|
||||
assert(controller);
|
||||
delete _keyboardController;
|
||||
_keyboardController = controller;
|
||||
_keyboardController->setHandler(this);
|
||||
}
|
||||
|
||||
void InteractionHandler::setMouseController(MouseController* controller) {
|
||||
assert(controller);
|
||||
delete _mouseController;
|
||||
_mouseController = controller;
|
||||
_mouseController->setHandler(this);
|
||||
assert(controller);
|
||||
delete _mouseController;
|
||||
_mouseController = controller;
|
||||
_mouseController->setHandler(this);
|
||||
}
|
||||
|
||||
void InteractionHandler::addController(Controller* controller) {
|
||||
assert(controller);
|
||||
_controllers.push_back(controller);
|
||||
controller->setHandler(this);
|
||||
assert(controller);
|
||||
_controllers.push_back(controller);
|
||||
controller->setHandler(this);
|
||||
}
|
||||
|
||||
void InteractionHandler::lockControls() {
|
||||
_mutex.lock();
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
void InteractionHandler::unlockControls() {
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
//<<<<<<< HEAD
|
||||
//void InteractionHandler::addExternalControl(ExternalControl* controller) {
|
||||
// //assert(this_);
|
||||
// if (controller != nullptr) {
|
||||
// _controllers.push_back(controller);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::setCamera(Camera *camera) {
|
||||
// //assert(this_);
|
||||
// _camera = camera;
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::setOrigin(SceneGraphNode* node) {
|
||||
// if (node)
|
||||
// _node = node;
|
||||
//}
|
||||
//
|
||||
//Camera * InteractionHandler::getCamera() const {
|
||||
// //assert(this_);
|
||||
// if (_enabled) {
|
||||
// return _camera;
|
||||
// }
|
||||
// return nullptr;
|
||||
//}
|
||||
//
|
||||
//const psc InteractionHandler::getOrigin() const {
|
||||
// if (_node)
|
||||
// return _node->worldPosition();
|
||||
// return psc();
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::lockControls() {
|
||||
// //assert(this_);
|
||||
// _cameraGuard.lock();
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::unlockControls() {
|
||||
// //assert(this_);
|
||||
// _cameraGuard.unlock();
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::setFocusNode(SceneGraphNode *node) {
|
||||
// //assert(this_);
|
||||
// _node = node;
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::rotate(const glm::quat &rotation) {
|
||||
// //assert(this_);
|
||||
// lockControls();
|
||||
// _camera->rotate(rotation);
|
||||
// unlockControls();
|
||||
//=======
|
||||
void InteractionHandler::update(double deltaTime) {
|
||||
_deltaTime = deltaTime;
|
||||
_mouseController->update(deltaTime);
|
||||
_deltaTime = deltaTime;
|
||||
_mouseController->update(deltaTime);
|
||||
|
||||
bool hasKeys = false;
|
||||
psc pos;
|
||||
glm::quat q;
|
||||
|
||||
_keyframeMutex.lock();
|
||||
_keyframeMutex.lock();
|
||||
|
||||
if (_keyframes.size() > 4){ //wait until enough samples are buffered
|
||||
if (_keyframes.size() > 4){ //wait until enough samples are buffered
|
||||
hasKeys = true;
|
||||
|
||||
openspace::network::datamessagestructures::PositionKeyframe p0, p1, p2, p3;
|
||||
@@ -252,20 +131,20 @@ void InteractionHandler::update(double deltaTime) {
|
||||
p2 = _keyframes[2];
|
||||
p3 = _keyframes[3];
|
||||
|
||||
//interval check
|
||||
if (_currentKeyframeTime < p1._timeStamp){
|
||||
_currentKeyframeTime = p1._timeStamp;
|
||||
}
|
||||
//interval check
|
||||
if (_currentKeyframeTime < p1._timeStamp){
|
||||
_currentKeyframeTime = p1._timeStamp;
|
||||
}
|
||||
|
||||
double t0 = p1._timeStamp;
|
||||
double t1 = p2._timeStamp;
|
||||
double fact = (_currentKeyframeTime - t0) / (t1 - t0);
|
||||
double t0 = p1._timeStamp;
|
||||
double t1 = p2._timeStamp;
|
||||
double fact = (_currentKeyframeTime - t0) / (t1 - t0);
|
||||
|
||||
|
||||
|
||||
//glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4());
|
||||
//glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4());
|
||||
glm::dvec4 v = ghoul::interpolateLinear(fact, p1._position.dvec4(), p2._position.dvec4());
|
||||
|
||||
|
||||
pos = psc(v.x, v.y, v.z, v.w);
|
||||
q = ghoul::interpolateLinear(fact, p1._viewRotationQuat, p2._viewRotationQuat);
|
||||
|
||||
@@ -282,29 +161,29 @@ void InteractionHandler::update(double deltaTime) {
|
||||
_keyframeMutex.unlock();
|
||||
|
||||
if(hasKeys){
|
||||
_camera->setPosition(pos);
|
||||
_camera->setViewRotationMatrix(glm::mat4_cast(q));
|
||||
_camera->setPosition(pos);
|
||||
_camera->setViewRotationMatrix(glm::mat4_cast(q));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
|
||||
if (_focusNode == node){
|
||||
return;
|
||||
}
|
||||
|
||||
if (_focusNode == node){
|
||||
return;
|
||||
}
|
||||
|
||||
_focusNode = node;
|
||||
_focusNode = node;
|
||||
|
||||
//orient the camera to the new node
|
||||
psc focusPos = node->worldPosition();
|
||||
psc camToFocus = focusPos - _camera->position();
|
||||
glm::vec3 viewDir = glm::normalize(camToFocus.vec3());
|
||||
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
|
||||
//orient the camera to the new node
|
||||
psc focusPos = node->worldPosition();
|
||||
psc camToFocus = focusPos - _camera->position();
|
||||
glm::vec3 viewDir = glm::normalize(camToFocus.vec3());
|
||||
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
|
||||
//set new focus position
|
||||
_camera->setFocusPosition(node->worldPosition());
|
||||
float dot = glm::dot(viewDir, cameraView);
|
||||
@@ -313,25 +192,25 @@ void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
if (dot < 1.f && dot > -1.f) {
|
||||
//if (glm::length(viewDir - cameraView) < 0.001) {
|
||||
//if (viewDir != cameraView) {
|
||||
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
|
||||
float angle = glm::angle(viewDir, cameraView);
|
||||
glm::quat q = glm::angleAxis(angle, rotAxis);
|
||||
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
|
||||
float angle = glm::angle(viewDir, cameraView);
|
||||
glm::quat q = glm::angleAxis(angle, rotAxis);
|
||||
|
||||
//rotate view to target new focus
|
||||
_camera->rotate(q);
|
||||
//rotate view to target new focus
|
||||
_camera->rotate(q);
|
||||
}
|
||||
}
|
||||
|
||||
const SceneGraphNode* const InteractionHandler::focusNode() const {
|
||||
return _focusNode;
|
||||
return _focusNode;
|
||||
}
|
||||
|
||||
void InteractionHandler::setCamera(Camera* camera) {
|
||||
assert(camera);
|
||||
_camera = camera;
|
||||
assert(camera);
|
||||
_camera = camera;
|
||||
}
|
||||
const Camera* const InteractionHandler::camera() const {
|
||||
return _camera;
|
||||
return _camera;
|
||||
}
|
||||
|
||||
//void InteractionHandler::keyboardCallback(int key, int action) {
|
||||
@@ -344,71 +223,71 @@ const Camera* const InteractionHandler::camera() const {
|
||||
//}
|
||||
|
||||
void InteractionHandler::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
if (_mouseController)
|
||||
_mouseController->button(button, action);
|
||||
if (_mouseController)
|
||||
_mouseController->button(button, action);
|
||||
}
|
||||
|
||||
void InteractionHandler::mousePositionCallback(double x, double y) {
|
||||
if (_mouseController)
|
||||
// TODO Remap screen coordinates to [0,1]
|
||||
_mouseController->move(static_cast<float>(x), static_cast<float>(y));
|
||||
if (_mouseController)
|
||||
// TODO Remap screen coordinates to [0,1]
|
||||
_mouseController->move(static_cast<float>(x), static_cast<float>(y));
|
||||
}
|
||||
|
||||
void InteractionHandler::mouseScrollWheelCallback(double pos) {
|
||||
if (_mouseController)
|
||||
_mouseController->scrollWheel(static_cast<int>(pos));
|
||||
if (_mouseController)
|
||||
_mouseController->scrollWheel(static_cast<int>(pos));
|
||||
}
|
||||
|
||||
void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz, const float &dist){
|
||||
|
||||
lockControls();
|
||||
|
||||
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz();
|
||||
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
|
||||
lockControls();
|
||||
|
||||
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(glm::radians(dx * 100.f), cameraUp) * transform;
|
||||
transform = glm::rotate(glm::radians(dy * 100.f), cameraRight) * transform;
|
||||
transform = glm::rotate(glm::radians(dz * 100.f), _camera->viewDirection()) * transform;
|
||||
glm::mat4 transform;
|
||||
transform = glm::rotate(glm::radians(dx * 100.f), cameraUp) * transform;
|
||||
transform = glm::rotate(glm::radians(dy * 100.f), cameraRight) * transform;
|
||||
transform = glm::rotate(glm::radians(dz * 100.f), _camera->viewDirection()) * transform;
|
||||
|
||||
|
||||
//get "old" focus position
|
||||
psc focus = _camera->focusPosition();
|
||||
|
||||
//// get camera position
|
||||
//psc relative = _camera->position();
|
||||
|
||||
//get "old" focus position
|
||||
psc focus = _camera->focusPosition();
|
||||
|
||||
//// get camera position
|
||||
//psc relative = _camera->position();
|
||||
|
||||
// get camera position (UNSYNCHRONIZED)
|
||||
psc relative = _camera->unsynchedPosition();
|
||||
// get camera position (UNSYNCHRONIZED)
|
||||
psc relative = _camera->unsynchedPosition();
|
||||
|
||||
//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();
|
||||
}
|
||||
//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();
|
||||
}
|
||||
|
||||
//new camera position
|
||||
relative = origin + relative_focus_coordinate;
|
||||
//new camera position
|
||||
relative = origin + relative_focus_coordinate;
|
||||
|
||||
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
|
||||
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
|
||||
|
||||
psc target = relative + relative_focus_coordinate * dist;
|
||||
//don't fly into objects
|
||||
if ((target - origin).length() < bounds){
|
||||
target = relative;
|
||||
}
|
||||
psc target = relative + relative_focus_coordinate * dist;
|
||||
//don't fly into objects
|
||||
if ((target - origin).length() < bounds){
|
||||
target = relative;
|
||||
}
|
||||
|
||||
unlockControls();
|
||||
unlockControls();
|
||||
|
||||
_camera->setFocusPosition(origin);
|
||||
_camera->setPosition(target);
|
||||
_camera->rotate(glm::quat_cast(transform));
|
||||
|
||||
_camera->setPosition(target);
|
||||
_camera->rotate(glm::quat_cast(transform));
|
||||
|
||||
}
|
||||
|
||||
//void InteractionHandler::distance(const float &d){
|
||||
@@ -433,35 +312,35 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
|
||||
|
||||
void InteractionHandler::orbitDelta(const glm::quat& rotation)
|
||||
{
|
||||
lockControls();
|
||||
lockControls();
|
||||
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _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;
|
||||
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;
|
||||
glm::mat4 la = glm::lookAt(_camera->position().vec3(), origin.vec3(), glm::rotate(rotation, _camera->lookUpVector()));
|
||||
|
||||
unlockControls();
|
||||
|
||||
_camera->setPosition(relative);
|
||||
//camera_->rotate(rotation);
|
||||
//camera_->setRotation(glm::mat4_cast(rotation));
|
||||
_camera->setPosition(relative);
|
||||
//camera_->rotate(rotation);
|
||||
//camera_->setRotation(glm::mat4_cast(rotation));
|
||||
|
||||
|
||||
_camera->setRotation(la);
|
||||
//camera_->setLookUpVector();
|
||||
|
||||
_camera->setRotation(la);
|
||||
//camera_->setLookUpVector();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//<<<<<<< HEAD
|
||||
@@ -480,46 +359,46 @@ void InteractionHandler::orbitDelta(const glm::quat& rotation)
|
||||
//=======
|
||||
void InteractionHandler::rotateDelta(const glm::quat& rotation)
|
||||
{
|
||||
_camera->rotate(rotation);
|
||||
_camera->rotate(rotation);
|
||||
}
|
||||
|
||||
void InteractionHandler::distanceDelta(const PowerScaledScalar& distance, size_t iterations)
|
||||
{
|
||||
if (iterations > 5)
|
||||
return;
|
||||
//assert(this_);
|
||||
lockControls();
|
||||
|
||||
psc relative = _camera->position();
|
||||
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
|
||||
if (iterations > 5)
|
||||
return;
|
||||
//assert(this_);
|
||||
lockControls();
|
||||
|
||||
psc relative = _camera->position();
|
||||
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
|
||||
unlockControls();
|
||||
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
const glm::vec3 dir(relative_origin_coordinate.direction());
|
||||
glm::vec3 newdir = dir * distance[0];
|
||||
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 = newdir;
|
||||
relative_origin_coordinate[3] = distance[1];
|
||||
relative = relative + relative_origin_coordinate;
|
||||
|
||||
relative_origin_coordinate = relative - origin;
|
||||
if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f)
|
||||
// TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab)
|
||||
return;
|
||||
relative_origin_coordinate = relative - origin;
|
||||
if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f)
|
||||
// TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab)
|
||||
return;
|
||||
|
||||
newdir = relative_origin_coordinate.direction();
|
||||
newdir = relative_origin_coordinate.direction();
|
||||
|
||||
// update only if on the same side of the origin
|
||||
if (glm::angle(newdir, dir) < 90.0f) {
|
||||
_camera->setPosition(relative);
|
||||
}
|
||||
else {
|
||||
PowerScaledScalar d2 = distance;
|
||||
d2[0] *= 0.75f;
|
||||
d2[1] *= 0.85f;
|
||||
distanceDelta(d2, iterations + 1);
|
||||
}
|
||||
// update only if on the same side of the origin
|
||||
if (glm::angle(newdir, dir) < 90.0f) {
|
||||
_camera->setPosition(relative);
|
||||
}
|
||||
else {
|
||||
PowerScaledScalar d2 = distance;
|
||||
d2[0] *= 0.75f;
|
||||
d2[1] *= 0.85f;
|
||||
distanceDelta(d2, iterations + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::lookAt(const glm::quat& rotation)
|
||||
@@ -529,127 +408,93 @@ void InteractionHandler::lookAt(const glm::quat& rotation)
|
||||
void InteractionHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
// TODO package in script
|
||||
const float speed = _controllerSensitivity;
|
||||
const float dt = static_cast<float>(_deltaTime);
|
||||
const float dt = static_cast<float>(_deltaTime);
|
||||
if (action == KeyAction::Press || action == KeyAction::Repeat) {
|
||||
if ((key == Key::Right) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(0.0, speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(0.0, speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::Left) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(0.0, -speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(0.0, -speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::Down) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::Up) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::KeypadSubtract) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
if ((key == Key::KeypadAdd) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
|
||||
// iterate over key bindings
|
||||
_validKeyLua = true;
|
||||
auto ret = _keyLua.equal_range(key);
|
||||
for (auto it = ret.first; it != ret.second; ++it) {
|
||||
//OsEng.scriptEngine()->runScript(it->second);
|
||||
OsEng.scriptEngine().queueScript(it->second);
|
||||
if (!_validKeyLua) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// iterate over key bindings
|
||||
_validKeyLua = true;
|
||||
auto ret = _keyLua.equal_range({ key, modifier });
|
||||
for (auto it = ret.first; it != ret.second; ++it) {
|
||||
//OsEng.scriptEngine()->runScript(it->second);
|
||||
OsEng.scriptEngine().queueScript(it->second);
|
||||
if (!_validKeyLua) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//void InteractionHandler::mouseButtonCallback(int key, int action) {
|
||||
// //if(mouseControl_ != nullptr) {
|
||||
// // mouseControl_->mouseButtonCallback(key,action);
|
||||
// //}
|
||||
// if (key == SGCT_MOUSE_BUTTON_LEFT && action == SGCT_PRESS)
|
||||
// _leftMouseButtonDown = true;
|
||||
// else if (key == SGCT_MOUSE_BUTTON_LEFT && action == SGCT_RELEASE) {
|
||||
// _leftMouseButtonDown = false;
|
||||
// _isMouseBeingPressedAndHeld = false;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::mousePositionCallback(int x, int y) {
|
||||
// if (_leftMouseButtonDown)
|
||||
// trackballRotate(x,y);
|
||||
//
|
||||
// //if(mouseControl_ != nullptr) {
|
||||
// // mouseControl_->mousePosCallback(x,y);
|
||||
// //}
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::mouseScrollWheelCallback(int pos) {
|
||||
// //if(mouseControl_ != nullptr) {
|
||||
// // mouseControl_->mouseScrollCallback(pos);
|
||||
// //}
|
||||
// const float speed = 4.75f;
|
||||
// const float dt = static_cast<float>(_dt);
|
||||
// if(pos < 0) {
|
||||
// PowerScaledScalar dist(speed * dt, 0.0f);
|
||||
// distance(dist);
|
||||
// } else if(pos > 0) {
|
||||
// PowerScaledScalar dist(-speed * dt, 0.0f);
|
||||
// distance(dist);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
||||
void InteractionHandler::resetKeyBindings() {
|
||||
_keyLua.clear();
|
||||
_validKeyLua = false;
|
||||
_keyLua.clear();
|
||||
_validKeyLua = false;
|
||||
}
|
||||
|
||||
void InteractionHandler::bindKey(Key key, std::string lua) {
|
||||
_keyLua.insert(std::make_pair(key, lua));
|
||||
void InteractionHandler::bindKey(Key key, KeyModifier modifier, std::string lua) {
|
||||
_keyLua.insert({
|
||||
{key, modifier},
|
||||
lua
|
||||
});
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
|
||||
return {
|
||||
"",
|
||||
{
|
||||
{
|
||||
"clearKeys",
|
||||
&luascriptfunctions::clearKeys,
|
||||
"",
|
||||
"Clear all key bindings"
|
||||
},
|
||||
{
|
||||
"bindKey",
|
||||
&luascriptfunctions::bindKey,
|
||||
"string, string",
|
||||
"Binds a key by name to a lua string command"
|
||||
},
|
||||
{
|
||||
"dt",
|
||||
&luascriptfunctions::dt,
|
||||
"",
|
||||
"Get current frame time"
|
||||
},
|
||||
{
|
||||
"distance",
|
||||
&luascriptfunctions::distance,
|
||||
"number",
|
||||
"Change distance to origin",
|
||||
return {
|
||||
"",
|
||||
{
|
||||
{
|
||||
"clearKeys",
|
||||
&luascriptfunctions::clearKeys,
|
||||
"",
|
||||
"Clear all key bindings"
|
||||
},
|
||||
{
|
||||
"bindKey",
|
||||
&luascriptfunctions::bindKey,
|
||||
"string, string",
|
||||
"Binds a key by name to a lua string command"
|
||||
},
|
||||
{
|
||||
"dt",
|
||||
&luascriptfunctions::dt,
|
||||
"",
|
||||
"Get current frame time"
|
||||
},
|
||||
{
|
||||
"distance",
|
||||
&luascriptfunctions::distance,
|
||||
"number",
|
||||
"Change distance to origin",
|
||||
true
|
||||
},
|
||||
},
|
||||
{
|
||||
"setInteractionSensitivity",
|
||||
&luascriptfunctions::setInteractionSensitivity,
|
||||
@@ -687,18 +532,17 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
|
||||
"Returns the status of rotation movement inversion"
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//=======
|
||||
void InteractionHandler::setRotation(const glm::quat& rotation)
|
||||
{
|
||||
_camera->setRotation(rotation);
|
||||
_camera->setRotation(rotation);
|
||||
}
|
||||
|
||||
double InteractionHandler::deltaTime() const {
|
||||
return _deltaTime;
|
||||
return _deltaTime;
|
||||
}
|
||||
|
||||
void InteractionHandler::setInteractionSensitivity(float sensitivity) {
|
||||
@@ -726,15 +570,15 @@ bool InteractionHandler::invertRotation() const {
|
||||
}
|
||||
|
||||
void InteractionHandler::addKeyframe(const network::datamessagestructures::PositionKeyframe &kf){
|
||||
_keyframeMutex.lock();
|
||||
_keyframeMutex.lock();
|
||||
|
||||
//save a maximum of 10 samples (1 seconds of buffer)
|
||||
if (_keyframes.size() >= 10){
|
||||
_keyframes.erase(_keyframes.begin());
|
||||
}
|
||||
//save a maximum of 10 samples (1 seconds of buffer)
|
||||
if (_keyframes.size() >= 10){
|
||||
_keyframes.erase(_keyframes.begin());
|
||||
}
|
||||
_keyframes.push_back(kf);
|
||||
|
||||
_keyframeMutex.unlock();
|
||||
_keyframeMutex.unlock();
|
||||
}
|
||||
|
||||
void InteractionHandler::clearKeyframes(){
|
||||
|
||||
@@ -32,28 +32,28 @@ namespace luascriptfunctions {
|
||||
* Set the origin of the camera
|
||||
*/
|
||||
int setOrigin(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.setOrigin";
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.setOrigin";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING)
|
||||
return luaL_error(L, "Expected string, got %i", type);
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING)
|
||||
return luaL_error(L, "Expected string, got %i", type);
|
||||
|
||||
std::string s = luaL_checkstring(L, -1);
|
||||
std::string s = luaL_checkstring(L, -1);
|
||||
|
||||
SceneGraphNode* node = sceneGraphNode(s);
|
||||
if (!node) {
|
||||
LWARNING("Could not find a node in scenegraph called '" << s <<"'");
|
||||
return 0;
|
||||
}
|
||||
SceneGraphNode* node = sceneGraphNode(s);
|
||||
if (!node) {
|
||||
LWARNING("Could not find a node in scenegraph called '" << s <<"'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
OsEng.interactionHandler().setFocusNode(node);
|
||||
OsEng.interactionHandler().setFocusNode(node);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,31 +62,35 @@ int setOrigin(lua_State* L) {
|
||||
* Binds a key to Lua command
|
||||
*/
|
||||
int bindKey(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.bindKey";
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.bindKey";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
|
||||
|
||||
std::string key = luaL_checkstring(L, -2);
|
||||
std::string command = luaL_checkstring(L, -1);
|
||||
std::string key = luaL_checkstring(L, -2);
|
||||
std::string command = luaL_checkstring(L, -1);
|
||||
|
||||
if (command.empty())
|
||||
return luaL_error(L, "Command string is empty");
|
||||
if (command.empty())
|
||||
return luaL_error(L, "Command string is empty");
|
||||
|
||||
openspace::Key iKey = stringToKey(key);
|
||||
openspace::KeyWithModifier iKey = openspace::stringToKey(key);
|
||||
|
||||
if (iKey == openspace::Key::Unknown) {
|
||||
LERROR("Could not find key '"<< key <<"'");
|
||||
return 0;
|
||||
}
|
||||
if (iKey.key == openspace::Key::Unknown) {
|
||||
LERROR("Could not find key '"<< key <<"'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
OsEng.interactionHandler().bindKey(iKey, command);
|
||||
|
||||
return 0;
|
||||
OsEng.interactionHandler().bindKey(
|
||||
iKey.key,
|
||||
iKey.modifier,
|
||||
command
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,16 +99,16 @@ int bindKey(lua_State* L) {
|
||||
* Clears all key bindings
|
||||
*/
|
||||
int clearKeys(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.clearKeys";
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.clearKeys";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
OsEng.interactionHandler().resetKeyBindings();
|
||||
OsEng.interactionHandler().resetKeyBindings();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,12 +117,12 @@ int clearKeys(lua_State* L) {
|
||||
* Get current frame time
|
||||
*/
|
||||
int dt(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
lua_pushnumber(L,OsEng.interactionHandler().deltaTime());
|
||||
return 1;
|
||||
lua_pushnumber(L,OsEng.interactionHandler().deltaTime());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,15 +131,15 @@ int dt(lua_State* L) {
|
||||
* Change distance to origin
|
||||
*/
|
||||
int distance(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
|
||||
double d1 = luaL_checknumber(L, -2);
|
||||
double d2 = luaL_checknumber(L, -1);
|
||||
PowerScaledScalar dist(static_cast<float>(d1), static_cast<float>(d2));
|
||||
OsEng.interactionHandler().distanceDelta(dist);
|
||||
return 0;
|
||||
double d1 = luaL_checknumber(L, -2);
|
||||
double d2 = luaL_checknumber(L, -1);
|
||||
PowerScaledScalar dist(static_cast<float>(d1), static_cast<float>(d2));
|
||||
OsEng.interactionHandler().distanceDelta(dist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -736,6 +736,9 @@ void RenderEngine::changeViewPoint(std::string origin) {
|
||||
SceneGraphNode* newHorizonsNode = scene()->sceneGraphNode("NewHorizons");
|
||||
SceneGraphNode* newHorizonsPathNodeJ = scene()->sceneGraphNode("NewHorizonsPathJupiter");
|
||||
SceneGraphNode* newHorizonsPathNodeP = scene()->sceneGraphNode("NewHorizonsPathPluto");
|
||||
SceneGraphNode* cg67pNode = scene()->sceneGraphNode("67P");
|
||||
SceneGraphNode* rosettaNode = scene()->sceneGraphNode("Rosetta");
|
||||
|
||||
RenderablePath* nhPath;
|
||||
|
||||
SceneGraphNode* jupiterBarycenterNode = scene()->sceneGraphNode("JupiterBarycenter");
|
||||
@@ -744,14 +747,11 @@ void RenderEngine::changeViewPoint(std::string origin) {
|
||||
//SceneGraphNode* dawnNode = scene()->sceneGraphNode("Dawn");
|
||||
//SceneGraphNode* vestaNode = scene()->sceneGraphNode("Vesta");
|
||||
|
||||
if (solarSystemBarycenterNode == nullptr || plutoBarycenterNode == nullptr ||
|
||||
newHorizonsNode == nullptr || jupiterBarycenterNode == nullptr
|
||||
//|| dawnNode == nullptr
|
||||
//|| vestaNode == nullptr
|
||||
) {
|
||||
LERROR("Necessary nodes does not exist");
|
||||
return;
|
||||
}
|
||||
// if (solarSystemBarycenterNode == nullptr || plutoBarycenterNode == nullptr ||
|
||||
//jupiterBarycenterNode == nullptr) {
|
||||
// LERROR("Necessary nodes does not exist");
|
||||
//return;
|
||||
// }
|
||||
|
||||
if (origin == "Pluto") {
|
||||
if (newHorizonsPathNodeP) {
|
||||
@@ -1169,26 +1169,28 @@ void RenderEngine::renderInformation() {
|
||||
|
||||
glm::vec4 targetColor(0.00, 0.75, 1.00, 1);
|
||||
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
SpiceManager::ref().targetPosition("PLUTO", "NEW HORIZONS", "GALACTIC", {}, currentTime, lt);
|
||||
psc nhPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
float a, b, c;
|
||||
glm::dvec3 radii;
|
||||
SpiceManager::ref().getValue("PLUTO", "RADII", radii);
|
||||
a = radii.x;
|
||||
b = radii.y;
|
||||
c = radii.z;
|
||||
float radius = (a + b) / 2.f;
|
||||
float distToSurf = glm::length(nhPos.vec3()) - radius;
|
||||
|
||||
RenderFont(*_fontInfo,
|
||||
penPosition,
|
||||
"Distance to Pluto: % .1f (KM)",
|
||||
distToSurf
|
||||
);
|
||||
penPosition.y -= _fontInfo->height();
|
||||
try {
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
SpiceManager::ref().targetPosition("PLUTO", "NEW HORIZONS", "GALACTIC", {}, currentTime, lt);
|
||||
psc nhPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
float a, b, c;
|
||||
glm::dvec3 radii;
|
||||
SpiceManager::ref().getValue("PLUTO", "RADII", radii);
|
||||
a = radii.x;
|
||||
b = radii.y;
|
||||
c = radii.z;
|
||||
float radius = (a + b) / 2.f;
|
||||
float distToSurf = glm::length(nhPos.vec3()) - radius;
|
||||
|
||||
RenderFont(*_fontInfo,
|
||||
penPosition,
|
||||
"Distance to Pluto: % .1f (KM)",
|
||||
distToSurf
|
||||
);
|
||||
penPosition.y -= _fontInfo->height();
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - currentTime;
|
||||
float t = static_cast<float>(1.0 - remaining / openspace::ImageSequencer2::ref().getIntervalLength());
|
||||
|
||||
@@ -261,6 +261,8 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
}
|
||||
|
||||
node->node->setParent(parentNode);
|
||||
parentNode->addChild(node->node);
|
||||
|
||||
}
|
||||
|
||||
// Setup dependencies
|
||||
|
||||
@@ -155,10 +155,10 @@ bool SceneGraphNode::deinitialize() {
|
||||
delete _ephemeris;
|
||||
_ephemeris = nullptr;
|
||||
|
||||
for (SceneGraphNode* child : _children) {
|
||||
child->deinitialize();
|
||||
delete child;
|
||||
}
|
||||
// for (SceneGraphNode* child : _children) {
|
||||
// child->deinitialize();
|
||||
// delete child;
|
||||
//}
|
||||
_children.clear();
|
||||
|
||||
// reset variables
|
||||
@@ -283,6 +283,11 @@ void SceneGraphNode::setParent(SceneGraphNode* parent)
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
void SceneGraphNode::addChild(SceneGraphNode* child) {
|
||||
_children.push_back(child);
|
||||
}
|
||||
|
||||
|
||||
//not used anymore @AA
|
||||
//bool SceneGraphNode::abandonChild(SceneGraphNode* child) {
|
||||
// std::vector < SceneGraphNode* >::iterator it = std::find(_children.begin(), _children.end(), child);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Keys";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
KeyAction operator|(KeyAction lhs, KeyAction rhs) {
|
||||
return static_cast<KeyAction>(
|
||||
static_cast<std::underlying_type_t<KeyAction>>(lhs) |
|
||||
static_cast<std::underlying_type_t<KeyAction>>(rhs)
|
||||
);
|
||||
}
|
||||
|
||||
KeyAction operator|=(KeyAction& lhs, KeyAction rhs) {
|
||||
lhs = (lhs | rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
KeyModifier operator|(KeyModifier lhs, KeyModifier rhs) {
|
||||
return static_cast<KeyModifier>(
|
||||
static_cast<std::underlying_type_t<KeyModifier>>(lhs) |
|
||||
static_cast<std::underlying_type_t<KeyModifier>>(rhs)
|
||||
);
|
||||
}
|
||||
|
||||
KeyModifier operator|=(KeyModifier& lhs, KeyModifier rhs) {
|
||||
lhs = (lhs | rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
KeyWithModifier stringToKey(std::string str) {
|
||||
// key only uppercase
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
|
||||
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(str, '+');
|
||||
|
||||
// default is unknown
|
||||
Key k = Key::Unknown;
|
||||
auto it = KeyMapping.find(tokens.back());
|
||||
if (it != KeyMapping.end())
|
||||
k = it->second;
|
||||
|
||||
|
||||
KeyModifier m = KeyModifier::NoModifier;
|
||||
std::for_each(
|
||||
tokens.begin(),
|
||||
tokens.end() - 1,
|
||||
[&m](const std::string& s) {
|
||||
auto it = KeyModifierMapping.find(s);
|
||||
if (it != KeyModifierMapping.end())
|
||||
m |= it->second;
|
||||
else
|
||||
LERROR("Unknown modifier key '" << s << "'");
|
||||
}
|
||||
);
|
||||
|
||||
return { k, m };
|
||||
}
|
||||
|
||||
bool operator<(const KeyWithModifier& lhs, const KeyWithModifier& rhs) {
|
||||
if (lhs.modifier == rhs.modifier)
|
||||
return lhs.key < rhs.key;
|
||||
else
|
||||
return lhs.modifier < rhs.modifier;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
Reference in New Issue
Block a user