Merge branch 'feature/globebrowsing' of github.com:OpenSpace/OpenSpace-Development into feature/globebrowsing

This commit is contained in:
Kalle Bladin
2016-04-14 20:27:58 -04:00
11 changed files with 300 additions and 418 deletions

View File

@@ -7,6 +7,7 @@ return {
Type = "RenderableGlobe",
Frame = "IAU_EARTH",
Body = "EARTH",
Radius = 6.316e6,
},
Ephemeris = {
Type = "Spice",

View File

@@ -3,7 +3,7 @@ return {
CommonFolder = "common",
Camera = {
Focus = "Earth",
Position = {1, 0, 0, 5},
-- Position = {1, 0, 0, 5},
},
Modules = {
"sun",

View File

@@ -29,6 +29,7 @@
// open space includes
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/rendering/renderengine.h>
// glm includes
#include <ghoul/glm.h>
@@ -38,144 +39,142 @@
namespace openspace {
//class Camera {
//public:
// enum class ProjectionMode {
// Perspective,
// Orthographic,
// Frustum,
// FixedPerspective
// };
//
// Camera();
//
// void setPosition(psc pos);
// const psc& position() const;
//
// void setFocus(psc focus);
// const psc& focus() const;
//
// void setUpVector(psc upVector);
// const psc& upVector() const;
//
// void setScaling(float scaling);
// float scaling() const;
//
// const glm::mat4& viewMatrix() const;
//
// void setProjectionMatrix(glm::mat4 projectionMatrix);
// const glm::mat4& projectionMatrix() const;
//
// void setMaxFox(float fov);
// float maxFov() const;
//
//
// // derived values
// psc lookVector() const;
//
//private:
// void invalidateViewMatrix();
// void updateViewMatrix() const; // has to be constant to be called from getter methods
//
// psc _position;
// psc _focus;
// psc _upVector;
//
// glm::mat4 _projectionMatrix;
// mutable glm::mat4 _viewMatrix;
// float _scaling;
//
// float _maxFov;
//
// mutable bool _viewMatrixIsDirty;
//};
class SyncBuffer;
class SyncBuffer;
class Camera {
public:
Camera();
~Camera();
Camera();
~Camera();
void setPosition(psc pos);
const psc& position() const;
// MUTATORS (SETTERS)
void setPosition(psc pos);
void setFocusPosition(psc pos);
void setRotation(glm::quat rotation);
void setLookUpVector(glm::vec3 lookUp);
void setScaling(glm::vec2 scaling);
void setMaxFov(float fov);
// RELATIVE MUTATORS
void rotate(const glm::quat& rotation);
// ACCESSORS (GETTERS)
const psc& position() const;
const psc& unsynchedPosition() const;
const psc& focusPosition() const;
const glm::vec3& viewDirection() const;
const glm::vec3& lookUpVector() const;
const glm::vec2& scaling() const;
float maxFov() const;
float sinMaxFov() const;
const glm::mat4& viewRotationMatrix() const;
void setModelMatrix(glm::mat4 modelMatrix);
const glm::mat4& modelMatrix() const;
void setViewMatrix(glm::mat4 viewMatrix);
//@TODO this should simply be called viewMatrix!
//Rename after removing deprecated methods
const glm::mat4& combinedViewMatrix() const;
// DEPRECATED ACCESSORS (GETTERS)
// @TODO use Camera::SgctInternal interface instead
[[deprecated("Replaced by Camera::SgctInternal::viewMatrix()")]]
const glm::mat4& viewMatrix() const;
void setProjectionMatrix(glm::mat4 projectionMatrix);
[[deprecated("Replaced by Camera::SgctInternal::projectionMatrix()")]]
const glm::mat4& projectionMatrix() const;
const glm::mat4& viewProjectionMatrix() const;
[[deprecated("Replaced by Camera::SgctInternal::viewProjectionMatrix()")]]
const glm::mat4& viewProjectionMatrix() const;
void setCameraDirection(glm::vec3 cameraDirection);
glm::vec3 cameraDirection() const;
void setFocusPosition(psc pos);
const psc& focusPosition() const;
void setViewRotationMatrix(glm::mat4 m);
const glm::mat4& viewRotationMatrix() const;
void compileViewRotationMatrix();
void rotate(const glm::quat& rotation);
void setRotation(glm::quat rotation);
// const glm::quat& rotation() const;
void setRotation(glm::mat4 rotation);
const glm::vec3& viewDirection() const;
const float& maxFov() const;
const float& sinMaxFov() const;
void setMaxFov(float fov);
void setScaling(glm::vec2 scaling);
const glm::vec2& scaling() const;
void setLookUpVector(glm::vec3 lookUp);
const glm::vec3& lookUpVector() const;
// SYNCHRONIZATION
void postSynchronizationPreDraw();
void preSynchronization();
void serialize(SyncBuffer* syncBuffer);
void deserialize(SyncBuffer* syncBuffer);
// Handles SGCT's internal matrices. Also caches a calculated viewProjection matrix.
class SgctInternal {
friend class Camera;
public:
void setViewMatrix(glm::mat4 viewMatrix);
void setProjectionMatrix(glm::mat4 projectionMatrix);
const glm::mat4& viewMatrix() const;
const glm::mat4& projectionMatrix() const;
const glm::mat4& viewProjectionMatrix() const;
private:
SgctInternal();
glm::mat4 _viewMatrix;
glm::mat4 _projectionMatrix;
mutable bool _dirtyViewProjectionMatrix;
mutable glm::mat4 _viewProjectionMatrix;
mutable std::mutex _mutex;
} sgctInternal;
private:
float _maxFov;
float _sinMaxFov;
mutable glm::mat4 _viewProjectionMatrix;
glm::mat4 _modelMatrix;
glm::mat4 _viewMatrix;
glm::mat4 _projectionMatrix;
mutable bool _dirtyViewProjectionMatrix;
glm::vec3 _viewDirection;
glm::vec3 _cameraDirection;
// Defines what direction in local camera space the camera is looking in.
const glm::vec3 _viewDirectionInCameraSpace;
psc _focusPosition;
// glm::quat _viewRotation;
glm::vec3 _lookUp;
glm::vec3 _viewDirection;
glm::vec3 _lookUp;
// Class encapsulating the synced data. Are all three variables
// (i.e. local, shared, synced) really neccessary? /EB
template <typename T>
struct 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;
};
SyncData<glm::mat4> _viewRotationMatrix;
SyncData<glm::vec2> _scaling;
SyncData<psc> _position;
float _maxFov;
float _sinMaxFov;
mutable std::mutex _mutex;
//local variables
glm::mat4 _localViewRotationMatrix;
glm::vec2 _localScaling;
psc _localPosition;
//shared copies of local variables
glm::vec2 _sharedScaling;
psc _sharedPosition;
glm::mat4 _sharedViewRotationMatrix;
//synced copies of local variables
glm::vec2 _syncedScaling;
psc _syncedPosition;
glm::mat4 _syncedViewRotationMatrix;
};
} // namespace openspace

View File

@@ -119,7 +119,7 @@ namespace openspace {
//LDEBUG("min distnace to camera: " << minDistToCamera);
Vec3 cameraPos = data.camera.position().dvec3();
//LDEBUG("cam pos x: " << cameraPos.x << " y: " << cameraPos.y << " z: " << cameraPos.z);
LDEBUG("cam pos x: " << cameraPos.x << " y: " << cameraPos.y << " z: " << cameraPos.z);
//LDEBUG("ChunkNode count: " << ChunkNode::instanceCount);
}

View File

@@ -95,16 +95,11 @@ namespace openspace {
using namespace glm;
// Get camera transform matrix
// TODO : Should only need to fetch the camera transform and use directly
// but this is not currently possible in the camera class.
vec3 cameraPosition = data.camera.unsynchedPosition().vec3();
mat4 viewTransform = inverse(translate(mat4(1.0), cameraPosition));
viewTransform = mat4(data.camera.viewRotationMatrix()) * viewTransform;
// TODO : Model transform should be fetched as a matrix directly.
mat4 modelTransform = translate(mat4(1), data.position.vec3());
mat4 viewTransform = data.camera.combinedViewMatrix();
mat4 modelViewProjectionTransform = data.camera.projectionMatrix()
* viewTransform * modelTransform;
@@ -166,14 +161,7 @@ namespace openspace {
_programObject->activate();
using namespace glm;
Vec3 cameraPos = data.camera.position().dvec3();
// Get camera transform matrix
// TODO : Should only need to fetch the camera transform and use directly
// but this is not currently possible in the camera class.
vec3 cameraPosition = data.camera.position().vec3();
mat4 viewTransform = inverse(translate(mat4(1.0), cameraPosition));
viewTransform = mat4(data.camera.viewRotationMatrix()) * viewTransform;
const mat4& viewTransform = data.camera.combinedViewMatrix();
// TODO : Model transform should be fetched as a matrix directly.
mat4 modelTransform = translate(mat4(1), data.position.vec3());

View File

@@ -71,8 +71,8 @@ namespace openspace {
// Mainly for debugging purposes @AA
addProperty(_rotation);
addSwitchValue(std::shared_ptr<ClipMapGlobe>(new ClipMapGlobe(dictionary)), 1e9);
//addSwitchValue(std::shared_ptr<ChunkLodGlobe>(new ChunkLodGlobe(dictionary)), 1e9);
//addSwitchValue(std::shared_ptr<ClipMapGlobe>(new ClipMapGlobe(dictionary)), 1e9);
addSwitchValue(std::shared_ptr<ChunkLodGlobe>(new ChunkLodGlobe(dictionary)), 1e9);
addSwitchValue(std::shared_ptr<GlobeMesh>(new GlobeMesh(dictionary)), 1e10);
}

View File

@@ -12,7 +12,7 @@ return {
-- Scene = "${SCENE}/default-modified.scene",
-- Scene = "${SCENE}/rosetta.scene",
-- Scene = "${SCENE}/dawn.scene",
Scene = "${SCENE}/globebrowsing.scene",
Scene = "${SCENE}/globebrowsing.scene",
Paths = {
SGCT = "${BASE_PATH}/config/sgct",

View File

@@ -283,7 +283,7 @@ void InteractionHandler::update(double deltaTime) {
if(hasKeys){
_camera->setPosition(pos);
_camera->setViewRotationMatrix(glm::mat4_cast(q));
_camera->setRotation(q);
}
@@ -395,7 +395,7 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
//new camera position
relative = origin + relative_focus_coordinate;
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
float bounds = _focusNode ? _focusNode->boundingSphere().lengthf() : 0.f;
psc target = relative + relative_focus_coordinate * dist;
//don't fly into objects

View File

@@ -283,7 +283,6 @@ bool RenderEngine::initializeGL() {
//_mainCamera->setCameraDirection(glm::normalize(-viewdir));
_mainCamera->setCameraDirection(glm::vec3(0.f, 0.f, -1.f));
//_mainCamera->setLookUpVector(glm::normalize(upVector));
_mainCamera->setLookUpVector(glm::vec3(0.f, 1.f, 0.f));
@@ -347,10 +346,6 @@ void RenderEngine::postSynchronizationPreDraw() {
ghoul::fontrendering::FontRenderer::defaultRenderer().setWindowSize(glm::vec2(res));
}
// converts the quaternion used to rotation matrices
if (_mainCamera)
_mainCamera->compileViewRotationMatrix();
// update and evaluate the scene starting from the root node
_sceneGraph->update({
Time::ref().currentTime(),
@@ -377,8 +372,8 @@ void RenderEngine::postSynchronizationPreDraw() {
}
void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) {
_mainCamera->setViewMatrix(viewMatrix);
_mainCamera->setProjectionMatrix(projectionMatrix);
_mainCamera->sgctInternal.setViewMatrix(viewMatrix);
_mainCamera->sgctInternal.setProjectionMatrix(projectionMatrix);
if (!(OsEng.isMaster() && _disableMasterRendering)) {

View File

@@ -204,6 +204,7 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
}
}
// update the position of all nodes
// TODO need to check this; unnecessary? (ab)
for (SceneGraphNode* node : _graph.nodes()) {
@@ -247,7 +248,7 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
glm::vec2 boundf = bound.vec2();
//glm::vec2 scaling{1.0f, -boundf[1]};
cameraScaling = glm::vec2(1.f, -boundf[1]);
boundf[0] *= 5.0f;
//boundf[0] *= 5.0f;
//psc cameraPosition = focusNode->position();
//cameraPosition += psc(glm::vec4(0.f, 0.f, boundf));
@@ -255,7 +256,7 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
//cameraPosition = psc(glm::vec4(0.f, 0.f, 1.f,0.f));
cameraPosition = focusNode->position();
cameraPosition += psc(glm::vec4(0.f, 0.f, boundf));
cameraPosition += psc(glm::vec4(boundf[0], 0.f, 0.f, boundf[1]));
//why this line? (JK)
//cameraPosition = psc(glm::vec4(0.f, 0.f, 1.f, 0.f));
@@ -292,7 +293,8 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
const SceneGraphNode* fn = OsEng.interactionHandler().focusNode();
// Check crash for when fn == nullptr
glm::mat4 la = glm::lookAt(cameraPosition.vec3(), fn->worldPosition().vec3(), c->lookUpVector());
glm::mat4 la = glm::lookAt(glm::vec3(0,0,0), fn->worldPosition().vec3() - cameraPosition.vec3(), c->lookUpVector());
c->setRotation(la);
c->setPosition(cameraPosition);

View File

@@ -30,211 +30,154 @@
#include <glm/gtx/vector_angle.hpp>
namespace openspace {
Camera::Camera()
: _maxFov(0.f)
, _sinMaxFov(0.f)
, _viewProjectionMatrix()
, _modelMatrix()
, _viewMatrix()
, _projectionMatrix()
, _dirtyViewProjectionMatrix(true)
, _viewDirection(0,0,-1)
, _cameraDirection(0.f, 0.f, 0.f)
, _focusPosition()
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
, _localViewRotationMatrix(1.f)
, _localScaling(1.f, 0.f)
, _localPosition()
, _sharedScaling(1.f, 0.f)
, _sharedPosition()
, _sharedViewRotationMatrix(1.f)
, _syncedScaling(1.f, 0.f)
, _syncedPosition()
, _syncedViewRotationMatrix(1.f)
, _viewDirectionInCameraSpace(0.f, 0.f, -1.f)
, _focusPosition()
{
_scaling.local = glm::vec2(1.f, 0.f);
_viewRotationMatrix.local = glm::mat4(1.0f);
_position.local = psc();
}
Camera::~Camera()
{
Camera::~Camera() { }
//////////////////////////////////////////////////////////////////////////////////////////
// CAMERA MUTATORS (SETTERS) //
//////////////////////////////////////////////////////////////////////////////////////////
void Camera::setPosition(psc pos){
std::lock_guard<std::mutex> _lock(_mutex);
_position.local = std::move(pos);
}
void Camera::setPosition(psc pos)
{
std::lock_guard<std::mutex> _lock(_mutex);
_localPosition = std::move(pos);
}
const psc& Camera::position() const
{
return _syncedPosition;
}
const psc& Camera::unsynchedPosition() const{
return _localPosition;
}
void Camera::setModelMatrix(glm::mat4 modelMatrix){
std::lock_guard<std::mutex> _lock(_mutex);
_modelMatrix = std::move(modelMatrix);
}
const glm::mat4& Camera::modelMatrix() const{
return _modelMatrix;
}
void Camera::setViewMatrix(glm::mat4 viewMatrix){
std::lock_guard<std::mutex> _lock(_mutex);
_viewMatrix = std::move(viewMatrix);
_dirtyViewProjectionMatrix = true;
}
const glm::mat4& Camera::viewMatrix() const{
return _viewMatrix;
}
void Camera::setProjectionMatrix(glm::mat4 projectionMatrix){
std::lock_guard<std::mutex> _lock(_mutex);
_projectionMatrix = std::move(projectionMatrix);
_dirtyViewProjectionMatrix = true;
}
const glm::mat4& Camera::projectionMatrix() const{
return _projectionMatrix;
}
const glm::mat4& Camera::viewProjectionMatrix() const {
if (_dirtyViewProjectionMatrix) {
std::lock_guard<std::mutex> _lock(_mutex);
_viewProjectionMatrix = _projectionMatrix * _viewMatrix;
_dirtyViewProjectionMatrix = false;
}
return _viewProjectionMatrix;
}
void Camera::setCameraDirection(glm::vec3 cameraDirection)
{
std::lock_guard<std::mutex> _lock(_mutex);
_cameraDirection = std::move(cameraDirection);
}
glm::vec3 Camera::cameraDirection() const
{
return _cameraDirection;
}
void Camera::setViewRotationMatrix(glm::mat4 m) {
std::lock_guard<std::mutex> _lock(_mutex);
_localViewRotationMatrix = m;
}
const glm::mat4& Camera::viewRotationMatrix() const
{
//return _localViewRotationMatrix;
return _syncedViewRotationMatrix;
}
void Camera::compileViewRotationMatrix()
{
std::lock_guard<std::mutex> _lock(_mutex);
// convert from quaternion to rotation matrix using glm
//_viewRotationMatrix = glm::mat4_cast(_viewRotation);
// the camera matrix needs to be rotated inverse to the world
// _viewDirection = glm::rotate(glm::inverse(_viewRotation), _cameraDirection);
//_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz;
_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz();
_viewDirection = glm::normalize(_viewDirection);
}
void Camera::rotate(const glm::quat& rotation)
{
std::lock_guard<std::mutex> _lock(_mutex);
glm::mat4 tmp = glm::mat4_cast(rotation);
_localViewRotationMatrix = _localViewRotationMatrix * tmp;
//_viewRotation = rotation * _viewRotation;
//_viewRotation = glm::normalize(_viewRotation);
}
void Camera::setRotation(glm::quat rotation)
{
std::lock_guard<std::mutex> _lock(_mutex);
//_viewRotation = glm::normalize(std::move(rotation));
_localViewRotationMatrix = glm::mat4_cast(rotation);
}
void Camera::setRotation(glm::mat4 rotation)
{
std::lock_guard<std::mutex> _lock(_mutex);
_localViewRotationMatrix = std::move(rotation);
}
//const glm::quat& Camera::rotation() const
//{
// return _viewRotation;
//}
void Camera::setFocusPosition(psc pos){
std::lock_guard<std::mutex> _lock(_mutex);
void Camera::setFocusPosition(psc pos) {
std::lock_guard<std::mutex> _lock(_mutex);
_focusPosition = pos;
}
const psc& Camera::focusPosition() const{
void Camera::setRotation(glm::quat rotation) {
std::lock_guard<std::mutex> _lock(_mutex);
_viewRotationMatrix.local = glm::mat4_cast(glm::normalize(rotation));
}
void Camera::setLookUpVector(glm::vec3 lookUp) {
std::lock_guard<std::mutex> _lock(_mutex);
_lookUp = std::move(lookUp);
}
void Camera::setScaling(glm::vec2 scaling) {
std::lock_guard<std::mutex> _lock(_mutex);
_scaling.local = std::move(scaling);
}
void Camera::setMaxFov(float fov) {
std::lock_guard<std::mutex> _lock(_mutex);
_maxFov = fov;
_sinMaxFov = sin(_maxFov);
}
//////////////////////////////////////////////////////////////////////////////////////////
// CAMERA ACCESSORS (GETTERS) //
//////////////////////////////////////////////////////////////////////////////////////////
const psc& Camera::position() const {
return _position.synced;
}
const psc& Camera::unsynchedPosition() const {
return _position.local;
}
const psc& Camera::focusPosition() const {
return _focusPosition;
}
const glm::vec3& Camera::viewDirection() const
{
return _viewDirection;
const glm::vec3& Camera::viewDirection() const {
return _viewDirection;
}
const float& Camera::maxFov() const
{
return _maxFov;
const glm::vec3& Camera::lookUpVector() const {
return _lookUp;
}
const float& Camera::sinMaxFov() const
{
return _sinMaxFov;
const glm::vec2& Camera::scaling() const {
return _scaling.synced;
}
void Camera::setMaxFov(float fov)
{
std::lock_guard<std::mutex> _lock(_mutex);
_maxFov = fov;
_sinMaxFov = sin(_maxFov);
float Camera::maxFov() const {
return _maxFov;
}
void Camera::setScaling(glm::vec2 scaling)
{
std::lock_guard<std::mutex> _lock(_mutex);
_localScaling = std::move(scaling);
float Camera::sinMaxFov() const {
return _sinMaxFov;
}
const glm::vec2& Camera::scaling() const
{
//return _localScaling;
return _syncedScaling;
const glm::mat4& Camera::viewRotationMatrix() const {
return _viewRotationMatrix.synced;
}
void Camera::setLookUpVector(glm::vec3 lookUp)
{
std::lock_guard<std::mutex> _lock(_mutex);
_lookUp = std::move(lookUp);
const glm::mat4& Camera::combinedViewMatrix() const {
glm::vec3 cameraPosition = position().vec3();
glm::mat4 viewTransform = glm::inverse(glm::translate(glm::mat4(1.0), cameraPosition));
viewTransform = glm::mat4(viewRotationMatrix()) * viewTransform;
return viewTransform;
}
const glm::vec3& Camera::lookUpVector() const
{
return _lookUp;
//////////////////////////////////////////////////////////////////////////////////////////
// DEPRECATED CAMERA ACCESSORS (GETTERS) //
//////////////////////////////////////////////////////////////////////////////////////////
const glm::mat4& Camera::viewMatrix() const {
return sgctInternal.viewMatrix();
}
const glm::mat4& Camera::projectionMatrix() const {
return sgctInternal.projectionMatrix();
}
const glm::mat4& Camera::viewProjectionMatrix() const {
return sgctInternal.viewProjectionMatrix();
}
//////////////////////////////////////////////////////////////////////////////////////////
// CAMERA RELATICVE MUTATORS //
//////////////////////////////////////////////////////////////////////////////////////////
void Camera::rotate(const glm::quat& rotation) {
std::lock_guard<std::mutex> _lock(_mutex);
glm::mat4 tmp = glm::mat4_cast(rotation);
_viewRotationMatrix.local = _viewRotationMatrix.local * tmp;
}
//////////////////////////////////////////////////////////////////////////////////////////
// CAMERA SYNCHRONIZATION //
//////////////////////////////////////////////////////////////////////////////////////////
void Camera::serialize(SyncBuffer* syncBuffer){
_mutex.lock();
syncBuffer->encode(_sharedViewRotationMatrix);
syncBuffer->encode(_sharedPosition);
syncBuffer->encode(_sharedScaling);
_viewRotationMatrix.serialize(syncBuffer);
_position.serialize(syncBuffer);
_scaling.serialize(syncBuffer);
_mutex.unlock();
}
@@ -242,9 +185,9 @@ void Camera::serialize(SyncBuffer* syncBuffer){
void Camera::deserialize(SyncBuffer* syncBuffer){
_mutex.lock();
syncBuffer->decode(_sharedViewRotationMatrix);
syncBuffer->decode(_sharedPosition);
syncBuffer->decode(_sharedScaling);
_viewRotationMatrix.deserialize(syncBuffer);
_position.deserialize(syncBuffer);
_scaling.deserialize(syncBuffer);
_mutex.unlock();
}
@@ -252,9 +195,14 @@ void Camera::deserialize(SyncBuffer* syncBuffer){
void Camera::postSynchronizationPreDraw(){
_mutex.lock();
_syncedViewRotationMatrix = _sharedViewRotationMatrix;
_syncedPosition = _sharedPosition;
_syncedScaling = _sharedScaling;
_viewRotationMatrix.postSynchronizationPreDraw();
_position.postSynchronizationPreDraw();
_scaling.postSynchronizationPreDraw();
glm::vec4 localViewDir = glm::vec4(_viewDirectionInCameraSpace, 0.f);
_viewDirection = (glm::inverse(_viewRotationMatrix.local) * localViewDir).xyz();
_viewDirection = glm::normalize(_viewDirection);
_mutex.unlock();
}
@@ -262,107 +210,56 @@ void Camera::postSynchronizationPreDraw(){
void Camera::preSynchronization(){
_mutex.lock();
_sharedViewRotationMatrix = _localViewRotationMatrix;
_sharedPosition = _localPosition;
_sharedScaling = _localScaling;
_viewRotationMatrix.preSynchronization();
_position.preSynchronization();
_scaling.preSynchronization();
_mutex.unlock();
}
//
//Camera::Camera()
// : _position(0.f, 0.f, 1.f, 0.f)
// , _focus(0.f, 0.f, 0.f, 0.f)
// , _upVector(0.f, 1.f, 0.f, 0.f)
// , _projectionMatrix(glm::mat4(1.f))
// , _viewMatrix(glm::mat4(1.f))
// , _scaling(0.f)
// , _maxFov(0.f)
// , _viewMatrixIsDirty(false)
//{
//
//}
//
//void Camera::setPosition(psc pos)
//{
// _position = std::move(pos);
//}
//
//const psc& Camera::position() const
//{
// return _position;
//}
//
//void Camera::setFocus(psc focus)
//{
// _focus = std::move(focus);
//}
//
//const psc& Camera::focus() const
//{
// return _focus;
//}
//
//void Camera::setUpVector(psc upVector)
//{
// _upVector = std::move(upVector);
//}
//
//const psc& Camera::upVector() const
//{
// return _upVector;
//}
//
//void Camera::setScaling(float scaling)
//{
// _scaling = scaling;
//}
//
//float Camera::scaling() const
//{
// return _scaling;
//}
//
//const glm::mat4& Camera::viewMatrix() const
//{
//
// return _viewMatrix;
//}
//
//void Camera::setProjectionMatrix(glm::mat4 projectionMatrix)
//{
// _projectionMatrix = std::move(projectionMatrix);
//}
//
//const glm::mat4& Camera::projectionMatrix() const
//{
// return _projectionMatrix;
//}
//
//void Camera::setMaxFox(float fov)
//{
// _maxFov = fov;
//}
//
//float Camera::maxFov() const
//{
// return _maxFov;
//}
//
//psc Camera::lookVector() const
//{
// return _focus - _position;
//}
//
//void Camera::invalidateViewMatrix() {
// _viewMatrixIsDirty = true;
//}
//
//void Camera::updateViewMatrix() const {
// if (_viewMatrixIsDirty) {
// _viewMatrix = glm::lookAt(_position.getVec3f(), _focus.getVec3f(), _upVector.getVec3f());
// _viewMatrixIsDirty = false;
// }
//}
//////////////////////////////////////////////////////////////////////////////////////////
// SGCT NODE DEPENTENT //
//////////////////////////////////////////////////////////////////////////////////////////
Camera::SgctInternal::SgctInternal()
: _viewMatrix()
, _projectionMatrix()
, _dirtyViewProjectionMatrix(true)
{
}
void Camera::SgctInternal::setViewMatrix(glm::mat4 viewMatrix) {
std::lock_guard<std::mutex> _lock(_mutex);
_viewMatrix = std::move(viewMatrix);
_dirtyViewProjectionMatrix = true;
}
void Camera::SgctInternal::setProjectionMatrix(glm::mat4 projectionMatrix) {
std::lock_guard<std::mutex> _lock(_mutex);
_projectionMatrix = std::move(projectionMatrix);
_dirtyViewProjectionMatrix = true;
}
const glm::mat4& Camera::SgctInternal::viewMatrix() const {
return _viewMatrix;
}
const glm::mat4& Camera::SgctInternal::projectionMatrix() const {
return _projectionMatrix;
}
const glm::mat4& Camera::SgctInternal::viewProjectionMatrix() const {
if (_dirtyViewProjectionMatrix) {
std::lock_guard<std::mutex> _lock(_mutex);
_viewProjectionMatrix = _projectionMatrix * _viewMatrix;
_dirtyViewProjectionMatrix = false;
}
return _viewProjectionMatrix;
}
} // namespace openspace