mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-28 06:49:32 -05:00
Remove local, shared, synced Camera members, and keep one source of truth
This commit is contained in:
@@ -178,30 +178,23 @@ namespace openspace {
|
||||
const glm::mat4& viewProjectionMatrix() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
Class encapsulating data that needs to be synched between SGCT nodes.
|
||||
Are all three variables (i.e. local, shared, synced) really neccessary? /EB
|
||||
*/
|
||||
template <typename T>
|
||||
struct SyncData {
|
||||
SyncData() {}
|
||||
SyncData(const SyncData& d)
|
||||
: local(d.local), shared(d.shared), synced(d.synced) {}
|
||||
void serialize(SyncBuffer* syncBuffer) {
|
||||
syncBuffer->encode(position);
|
||||
syncBuffer->encode(rotation);
|
||||
syncBuffer->encode(scaling);
|
||||
}
|
||||
void deserialize(SyncBuffer* syncBuffer) {
|
||||
syncBuffer->decode(position);
|
||||
syncBuffer->decode(rotation);
|
||||
syncBuffer->decode(scaling);
|
||||
}
|
||||
|
||||
Vec3 position;
|
||||
Quat rotation;
|
||||
glm::vec2 scaling;
|
||||
} syncData;
|
||||
|
||||
void serialize(SyncBuffer* syncBuffer) { syncBuffer->encode(shared); }
|
||||
void deserialize(SyncBuffer* syncBuffer) { syncBuffer->decode(shared); }
|
||||
void postSynchronizationPreDraw() { synced = shared; }
|
||||
void preSynchronization() { shared = local; }
|
||||
|
||||
T local;
|
||||
T shared;
|
||||
T synced;
|
||||
};
|
||||
|
||||
// State of the camera
|
||||
SyncData<Vec3> _position;
|
||||
SyncData<Quat> _rotation;
|
||||
SyncData<glm::vec2> _scaling;
|
||||
|
||||
// _focusPosition to be removed
|
||||
Vec3 _focusPosition;
|
||||
|
||||
+22
-36
@@ -50,10 +50,11 @@ namespace openspace {
|
||||
: _maxFov(0.f)
|
||||
, _focusPosition()
|
||||
{
|
||||
_scaling.local = glm::vec2(1.f, 0.f);
|
||||
_position.local = Vec3(1.0, 1.0, 1.0);
|
||||
|
||||
syncData.scaling= glm::vec2(1.f, 0.f);
|
||||
syncData.position = Vec3(1.0, 1.0, 1.0);
|
||||
Vec3 eulerAngles(1.0, 1.0, 1.0);
|
||||
_rotation.local = Quat(eulerAngles);
|
||||
syncData.rotation = Quat(eulerAngles);
|
||||
}
|
||||
|
||||
Camera::Camera(const Camera& o)
|
||||
@@ -61,9 +62,7 @@ namespace openspace {
|
||||
, _focusPosition(o._focusPosition)
|
||||
, _cachedViewDirection(o._cachedViewDirection)
|
||||
, _cachedLookupVector(o._cachedLookupVector)
|
||||
, _rotation(o._rotation)
|
||||
, _scaling(o._scaling)
|
||||
, _position(o._position)
|
||||
, syncData(o.syncData)
|
||||
, _maxFov(o._maxFov)
|
||||
{ }
|
||||
|
||||
@@ -72,7 +71,7 @@ namespace openspace {
|
||||
// Mutators
|
||||
void Camera::setPositionVec3(Vec3 pos) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_position.local = pos;
|
||||
syncData.position = pos;
|
||||
|
||||
_cachedCombinedViewMatrix.isDirty = true;
|
||||
}
|
||||
@@ -84,7 +83,7 @@ namespace openspace {
|
||||
|
||||
void Camera::setRotation(Quat rotation) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_rotation.local = rotation;
|
||||
syncData.rotation = rotation;
|
||||
_cachedViewDirection.isDirty = true;
|
||||
_cachedLookupVector.isDirty = true;
|
||||
_cachedViewRotationMatrix.isDirty = true;
|
||||
@@ -93,7 +92,7 @@ namespace openspace {
|
||||
|
||||
void Camera::setScaling(glm::vec2 scaling) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_scaling.local = std::move(scaling);
|
||||
syncData.scaling = std::move(scaling);
|
||||
}
|
||||
|
||||
void Camera::setMaxFov(float fov) {
|
||||
@@ -105,7 +104,7 @@ namespace openspace {
|
||||
// Relative mutators
|
||||
void Camera::rotate(Quat rotation) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_rotation.local = rotation * _rotation.local;
|
||||
syncData.rotation = rotation * syncData.rotation;
|
||||
|
||||
_cachedViewDirection.isDirty = true;
|
||||
_cachedLookupVector.isDirty = true;
|
||||
@@ -115,11 +114,11 @@ namespace openspace {
|
||||
|
||||
// Accessors
|
||||
const Camera::Vec3& Camera::positionVec3() const {
|
||||
return _position.synced;
|
||||
return syncData.position;
|
||||
}
|
||||
|
||||
const Camera::Vec3& Camera::unsynchedPositionVec3() const {
|
||||
return _position.local;
|
||||
return syncData.position;
|
||||
}
|
||||
|
||||
const Camera::Vec3& Camera::focusPositionVec3() const {
|
||||
@@ -129,7 +128,7 @@ namespace openspace {
|
||||
const Camera::Vec3& Camera::viewDirectionWorldSpace() const {
|
||||
if (_cachedViewDirection.isDirty) {
|
||||
_cachedViewDirection.datum =
|
||||
_rotation.synced * Vec3(_VIEW_DIRECTION_CAMERA_SPACE);
|
||||
syncData.rotation * Vec3(_VIEW_DIRECTION_CAMERA_SPACE);
|
||||
_cachedViewDirection.datum = glm::normalize(_cachedViewDirection.datum);
|
||||
_cachedViewDirection.isDirty = true;
|
||||
}
|
||||
@@ -143,7 +142,7 @@ namespace openspace {
|
||||
const Camera::Vec3& Camera::lookUpVectorWorldSpace() const {
|
||||
if (_cachedLookupVector.isDirty) {
|
||||
_cachedLookupVector.datum =
|
||||
_rotation.synced * Vec3(_LOOKUP_VECTOR_CAMERA_SPACE);
|
||||
syncData.rotation * Vec3(_LOOKUP_VECTOR_CAMERA_SPACE);
|
||||
_cachedLookupVector.datum = glm::normalize(_cachedLookupVector.datum);
|
||||
_cachedLookupVector.isDirty = true;
|
||||
}
|
||||
@@ -151,7 +150,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
const glm::vec2& Camera::scaling() const {
|
||||
return _scaling.synced;
|
||||
return syncData.scaling;
|
||||
}
|
||||
|
||||
float Camera::maxFov() const {
|
||||
@@ -168,19 +167,19 @@ namespace openspace {
|
||||
|
||||
const Camera::Mat4& Camera::viewRotationMatrix() const {
|
||||
if (_cachedViewRotationMatrix.isDirty) {
|
||||
_cachedViewRotationMatrix.datum = glm::mat4_cast(glm::inverse(_rotation.synced));
|
||||
_cachedViewRotationMatrix.datum = glm::mat4_cast(glm::inverse(syncData.rotation));
|
||||
}
|
||||
return _cachedViewRotationMatrix.datum;
|
||||
}
|
||||
|
||||
const Camera::Quat& Camera::rotationQuaternion() const {
|
||||
return _rotation.synced;
|
||||
return syncData.rotation;
|
||||
}
|
||||
|
||||
const Camera::Mat4& Camera::combinedViewMatrix() const {
|
||||
if (_cachedCombinedViewMatrix.isDirty) {
|
||||
Mat4 cameraTranslation =
|
||||
glm::inverse(glm::translate(Mat4(1.0), _position.synced));
|
||||
glm::inverse(glm::translate(Mat4(1.0), syncData.position));
|
||||
_cachedCombinedViewMatrix.datum =
|
||||
Mat4(sgctInternal.viewMatrix()) *
|
||||
Mat4(viewRotationMatrix()) *
|
||||
@@ -193,27 +192,17 @@ namespace openspace {
|
||||
// Synchronization
|
||||
void Camera::serialize(SyncBuffer* syncBuffer) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
|
||||
_rotation.serialize(syncBuffer);
|
||||
_position.serialize(syncBuffer);
|
||||
_scaling.serialize(syncBuffer);
|
||||
syncData.serialize(syncBuffer);
|
||||
}
|
||||
|
||||
void Camera::deserialize(SyncBuffer* syncBuffer) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
|
||||
_rotation.deserialize(syncBuffer);
|
||||
_position.deserialize(syncBuffer);
|
||||
_scaling.deserialize(syncBuffer);
|
||||
syncData.deserialize(syncBuffer);
|
||||
}
|
||||
|
||||
void Camera::postSynchronizationPreDraw() {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
|
||||
_rotation.postSynchronizationPreDraw();
|
||||
_position.postSynchronizationPreDraw();
|
||||
_scaling.postSynchronizationPreDraw();
|
||||
|
||||
_cachedViewDirection.isDirty = true;
|
||||
_cachedLookupVector.isDirty = true;
|
||||
_cachedViewRotationMatrix.isDirty = true;
|
||||
@@ -240,9 +229,6 @@ namespace openspace {
|
||||
void Camera::preSynchronization() {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
|
||||
_rotation.preSynchronization();
|
||||
_position.preSynchronization();
|
||||
_scaling.preSynchronization();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -287,7 +273,7 @@ namespace openspace {
|
||||
// Deprecated
|
||||
void Camera::setPosition(psc pos) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_position.local = pos.dvec3();
|
||||
syncData.position = pos.dvec3();
|
||||
}
|
||||
|
||||
void Camera::setFocusPosition(psc pos) {
|
||||
@@ -296,11 +282,11 @@ namespace openspace {
|
||||
}
|
||||
|
||||
psc Camera::position() const {
|
||||
return psc(_position.synced);
|
||||
return psc(syncData.position);
|
||||
}
|
||||
|
||||
psc Camera::unsynchedPosition() const {
|
||||
return psc(_position.local);
|
||||
return psc(syncData.position);
|
||||
}
|
||||
|
||||
psc Camera::focusPosition() const {
|
||||
|
||||
Reference in New Issue
Block a user