mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-28 07:59:37 -06:00
Added serialize / deserialize functions for camera.
Added proper mutex protected shared versions of synced variables for camera class. Added a post sync function for camera class (and a call to it in render engine post sync function)
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#ifndef __CAMERA_H__
|
||||
#define __CAMERA_H__
|
||||
|
||||
#include <mutex>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
@@ -88,6 +90,8 @@ namespace openspace {
|
||||
// mutable bool _viewMatrixIsDirty;
|
||||
//};
|
||||
|
||||
class SyncBuffer;
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
Camera();
|
||||
@@ -121,8 +125,8 @@ public:
|
||||
void setRotation(glm::mat4 rotation);
|
||||
|
||||
const glm::vec3& viewDirection() const;
|
||||
|
||||
const float& maxFov() const;
|
||||
|
||||
const float& maxFov() const;
|
||||
const float& sinMaxFov() const;
|
||||
void setMaxFov(float fov);
|
||||
void setScaling(glm::vec2 scaling);
|
||||
@@ -131,6 +135,10 @@ public:
|
||||
void setLookUpVector(glm::vec3 lookUp);
|
||||
const glm::vec3& lookUpVector() const;
|
||||
|
||||
void postSynchronizationPreDraw();
|
||||
void serialize(SyncBuffer* syncBuffer);
|
||||
void deserialize(SyncBuffer* syncBuffer);
|
||||
|
||||
private:
|
||||
float _maxFov;
|
||||
float _sinMaxFov;
|
||||
@@ -146,6 +154,12 @@ private:
|
||||
glm::mat4 _viewRotationMatrix; // compiled from the quaternion
|
||||
|
||||
glm::vec3 _lookUp;
|
||||
|
||||
//cluster variables
|
||||
glm::vec2 _sharedScaling;
|
||||
psc _sharedPosition;
|
||||
glm::mat4 _sharedViewRotationMatrix;
|
||||
std::mutex _syncMutex;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -297,6 +297,10 @@ bool RenderEngine::initializeGL()
|
||||
|
||||
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++) {
|
||||
@@ -541,23 +545,13 @@ void RenderEngine::setSceneGraph(SceneGraph* sceneGraph)
|
||||
|
||||
void RenderEngine::serialize(SyncBuffer* syncBuffer) {
|
||||
if (_mainCamera){
|
||||
syncBuffer->encode(_mainCamera->scaling());
|
||||
syncBuffer->encode(_mainCamera->position());
|
||||
syncBuffer->encode(_mainCamera->viewRotationMatrix());
|
||||
_mainCamera->serialize(syncBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::deserialize(SyncBuffer* syncBuffer) {
|
||||
if (_mainCamera){
|
||||
glm::vec2 scaling;
|
||||
psc position;
|
||||
glm::mat4 viewRotation;
|
||||
syncBuffer->decode(scaling);
|
||||
syncBuffer->decode(position);
|
||||
syncBuffer->decode(viewRotation);
|
||||
_mainCamera->setScaling(scaling);
|
||||
_mainCamera->setPosition(position);
|
||||
_mainCamera->setViewRotationMatrix(viewRotation);
|
||||
_mainCamera->deserialize(syncBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
// sgct includes
|
||||
#include "sgct.h"
|
||||
@@ -47,6 +48,9 @@ Camera::Camera()
|
||||
, _scaling(1.f, 0.f)
|
||||
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
, _viewRotationMatrix(1.f)
|
||||
, _sharedPosition()
|
||||
, _sharedScaling(1.f, 0.f)
|
||||
, _sharedViewRotationMatrix(1.f)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -193,6 +197,34 @@ const glm::vec3& Camera::lookUpVector() const
|
||||
return _lookUp;
|
||||
}
|
||||
|
||||
void Camera::serialize(SyncBuffer* syncBuffer){
|
||||
_syncMutex.lock();
|
||||
_sharedViewRotationMatrix = _viewRotationMatrix;
|
||||
_sharedPosition = _position;
|
||||
_sharedScaling = _scaling;
|
||||
syncBuffer->encode(_sharedViewRotationMatrix);
|
||||
syncBuffer->encode(_sharedPosition);
|
||||
syncBuffer->encode(_sharedScaling);
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Camera::deserialize(SyncBuffer* syncBuffer){
|
||||
_syncMutex.lock();
|
||||
syncBuffer->decode(_sharedViewRotationMatrix);
|
||||
syncBuffer->decode(_sharedPosition);
|
||||
syncBuffer->decode(_sharedScaling);
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Camera::postSynchronizationPreDraw(){
|
||||
_syncMutex.lock();
|
||||
_viewRotationMatrix = _sharedViewRotationMatrix;
|
||||
_position = _sharedPosition;
|
||||
_scaling = _sharedScaling;
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Camera::Camera()
|
||||
// : _position(0.f, 0.f, 1.f, 0.f)
|
||||
|
||||
Reference in New Issue
Block a user