Send view scaling over parallel connection

This commit is contained in:
Emil Axelsson
2018-03-20 14:23:46 +01:00
parent 2eae7ac26d
commit 0fcd3d9fab
5 changed files with 24 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ public:
glm::dvec3 position;
glm::quat rotation;
std::string focusNode;
float scale;
bool followFocusNodeRotation;
};

View File

@@ -49,6 +49,7 @@ struct CameraKeyframe {
glm::dquat _rotation;
bool _followNodeRotation;
std::string _focusNode;
float _scale;
double _timestamp;
@@ -88,6 +89,12 @@ struct CameraKeyframe {
_focusNode.data() + nodeNameLength
);
buffer.insert(
buffer.end(),
reinterpret_cast<char*>(&_scale),
reinterpret_cast<char*>(&_scale) + sizeof(_scale)
);
// Add timestamp
buffer.insert(
buffer.end(),
@@ -124,6 +131,11 @@ struct CameraKeyframe {
_focusNode = std::string(buffer.data() + offset, buffer.data() + offset + size);
offset += size;
// Scale
size = sizeof(_scale);
memcpy(&_scale, buffer.data() + offset, size);
offset += size;
// Timestamp
size = sizeof(_timestamp);
memcpy(&_timestamp, buffer.data() + offset, size);

View File

@@ -116,6 +116,14 @@ void KeyframeNavigator::updateCamera(Camera& camera) {
camera.setRotation(
glm::slerp(prevKeyframeCameraRotation, nextKeyframeCameraRotation, t)
);
// We want to affect view scaling, such that we achieve
// logarithmic interpolation of distance to an imagined focus node.
// To do this, we interpolate the scale reciprocal logarithmically.
const float prevInvScaleExp = glm::log(1.0 / prevPose.scale);
const float nextInvScaleExp = glm::log(1.0 / nextPose.scale);
const float interpolatedInvScaleExp = prevInvScaleExp * (1 - t) + nextInvScaleExp * t;
camera.setScaling(1.0 / glm::exp(interpolatedInvScaleExp));
}
Timeline<KeyframeNavigator::CameraPose>& KeyframeNavigator::timeline() {

View File

@@ -27,7 +27,7 @@
#include <cstdint>
namespace {
const uint32_t ProtocolVersion = 3;
const uint32_t ProtocolVersion = 4;
const char* _loggerCat = "ParallelConnection";
} // namespace

View File

@@ -287,6 +287,7 @@ void ParallelPeer::dataMessageReceived(const std::vector<char>& messageContent)
pose.focusNode = kf._focusNode;
pose.position = kf._position;
pose.rotation = kf._rotation;
pose.scale = kf._scale;
pose.followFocusNodeRotation = kf._followNodeRotation;
OsEng.navigationHandler().keyframeNavigator().addKeyframe(kf._timestamp, pose);
@@ -539,6 +540,7 @@ void ParallelPeer::sendCameraKeyframe() {
}
kf._focusNode = focusNode->identifier();
kf._scale = OsEng.navigationHandler().camera()->scaling();
// Timestamp as current runtime of OpenSpace instance
kf._timestamp = OsEng.windowWrapper().applicationTime();