Start changing camera write and restore functions.

This commit is contained in:
Kalle Bladin
2016-06-29 10:45:26 -04:00
parent 9256f79e48
commit 5807919ac7
4 changed files with 61 additions and 2 deletions

View File

@@ -196,6 +196,7 @@ public:
void saveCameraPosition(const std::string& filepath = "");
void restoreCameraPosition(const std::string& filepath = "");
void setCameraState(const ghoul::Dictionary& cameraDict);
private:
void setInteractionMode(std::shared_ptr<InteractionMode> interactionMode);

View File

@@ -123,10 +123,12 @@ namespace openspace {
void preSynchronization();
void serialize(SyncBuffer* syncBuffer);
void deserialize(SyncBuffer* syncBuffer);
void serialize(std::ostream& os) const;
void deserialize(std::istream& is);
void setStateFromDictionary(const ghoul::Dictionary& cameraDict);
ghoul::Dictionary getStateDictionary();
/**
Handles SGCT's internal matrices. Also caches a calculated viewProjection
matrix. This is the data that is different for different cameras within

View File

@@ -738,16 +738,35 @@ void InteractionHandler::keyboardCallback(Key key, KeyModifier modifier, KeyActi
}
void InteractionHandler::saveCameraPosition(const std::string& filepath) {
if (!filepath.empty()) {
auto fullpath = absPath(filepath);
LDEBUG("Saving camera position: " << fullpath);
ghoul::Dictionary cameraDict = _camera->getStateDictionary();
auto file = ghoul::filesystem::File(fullpath.c_str());
std::ofstream ofs(fullpath.c_str());
_camera->serialize(ofs);
ofs.close();
}
}
void InteractionHandler::restoreCameraPosition(const std::string& filepath) {
/*
if (!FileSys.fileExists(filepath))
throw ghoul::FileNotFoundError(filepath, "CameraFilePath");
ghoul::Dictionary cameraDict = _camera->getStateDictionary();
ghoul::lua::loadDictionaryFromFile(filepath, cameraDict);
_camera->setStateFromDictionary(cameraDict);
*/
if (!filepath.empty()) {
auto fullpath = absPath(filepath);
LDEBUG("Reading camera position: " << fullpath);
@@ -767,6 +786,14 @@ void InteractionHandler::restoreCameraPosition(const std::string& filepath) {
_camera->setRotation(r);
_cameraUpdatedFromScript = true;
}
}
void InteractionHandler::setCameraState(const ghoul::Dictionary& cameraDict) {
glm::dvec3 cameraPosition;
glm::dvec4 cameraRotation;
cameraDict.getValue("CameraPosition", cameraPosition);
cameraDict.getValue("CameraRotation", cameraRotation);
}
void InteractionHandler::resetKeyBindings() {

View File

@@ -197,6 +197,7 @@ namespace openspace {
_cachedLookupVector.isDirty = true;
}
void Camera::serialize(std::ostream& os) const {
Vec3 p = positionVec3();
Quat q = rotationQuaternion();
@@ -212,6 +213,34 @@ namespace openspace {
setPositionVec3(p);
setRotation(q);
}
void Camera::setStateFromDictionary(const ghoul::Dictionary& cameraDict) {
glm::dvec3 cameraPosition;
glm::dvec4 cameraRotation;
cameraDict.getValue("CameraPosition", cameraPosition);
cameraDict.getValue("CameraRotation", cameraRotation);
setPositionVec3(cameraPosition);
setRotation(glm::dquat(
cameraRotation.x, cameraRotation.y, cameraRotation.z, cameraRotation.w));
}
ghoul::Dictionary Camera::getStateDictionary() {
glm::dvec3 cameraPosition;
glm::dquat quat;
glm::dvec4 cameraRotation;
cameraPosition = positionVec3();
quat = rotationQuaternion();
cameraRotation = glm::dvec4(quat.x, quat.y, quat.z, quat.w);
ghoul::Dictionary cameraDict;
cameraDict.setValue("CameraPosition", cameraPosition);
cameraDict.setValue("CameraRotation", cameraRotation);
return cameraDict;
}
void Camera::preSynchronization() {
std::lock_guard<std::mutex> _lock(_mutex);