mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-15 18:19:58 -05:00
Camera class compiles but missing implementation of two functions.
This commit is contained in:
@@ -30,211 +30,177 @@
|
||||
#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)
|
||||
: _maxFov(0.f)
|
||||
, _sinMaxFov(0.f)
|
||||
, _viewDirection(0,0,-1)
|
||||
, _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);
|
||||
void Camera::setFocusPosition(psc pos) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_focusPosition = pos;
|
||||
}
|
||||
|
||||
const psc& Camera::position() const
|
||||
{
|
||||
return _syncedPosition;
|
||||
void Camera::setRotation(glm::quat rotation) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_viewRotationMatrix.local = glm::mat4_cast(glm::normalize(rotation));
|
||||
}
|
||||
|
||||
const psc& Camera::unsynchedPosition() const{
|
||||
return _localPosition;
|
||||
void Camera::setLookUpVector(glm::vec3 lookUp) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_lookUp = std::move(lookUp);
|
||||
}
|
||||
|
||||
void Camera::setModelMatrix(glm::mat4 modelMatrix){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_modelMatrix = std::move(modelMatrix);
|
||||
void Camera::setScaling(glm::vec2 scaling) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_scaling.local = std::move(scaling);
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::modelMatrix() const{
|
||||
return _modelMatrix;
|
||||
void Camera::setMaxFov(float fov) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_maxFov = fov;
|
||||
_sinMaxFov = sin(_maxFov);
|
||||
}
|
||||
|
||||
void Camera::setViewMatrix(glm::mat4 viewMatrix){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_viewMatrix = std::move(viewMatrix);
|
||||
_dirtyViewProjectionMatrix = true;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CAMERA ACCESSORS (GETTERS) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
const psc& Camera::position() const {
|
||||
return _position.synced;
|
||||
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewMatrix() const{
|
||||
return _viewMatrix;
|
||||
const psc& Camera::unsynchedPosition() const {
|
||||
return _position.local;
|
||||
}
|
||||
|
||||
void Camera::setProjectionMatrix(glm::mat4 projectionMatrix){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_projectionMatrix = std::move(projectionMatrix);
|
||||
_dirtyViewProjectionMatrix = true;
|
||||
const psc& Camera::focusPosition() const {
|
||||
return _focusPosition;
|
||||
}
|
||||
|
||||
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;
|
||||
const glm::vec3& Camera::viewDirection() const {
|
||||
return _viewDirection;
|
||||
}
|
||||
|
||||
void Camera::setCameraDirection(glm::vec3 cameraDirection)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_cameraDirection = std::move(cameraDirection);
|
||||
const glm::vec3& Camera::lookUpVector() const {
|
||||
return _lookUp;
|
||||
}
|
||||
|
||||
glm::vec3 Camera::cameraDirection() const
|
||||
{
|
||||
return _cameraDirection;
|
||||
const glm::vec2& Camera::scaling() const {
|
||||
return _scaling.synced;
|
||||
}
|
||||
|
||||
float Camera::maxFov() const {
|
||||
return _maxFov;
|
||||
}
|
||||
|
||||
float Camera::sinMaxFov() const {
|
||||
return _sinMaxFov;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewRotationMatrix() const {
|
||||
return _viewRotationMatrix.synced;
|
||||
}
|
||||
|
||||
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::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);
|
||||
_focusPosition = pos;
|
||||
}
|
||||
|
||||
const psc& Camera::focusPosition() const{
|
||||
return _focusPosition;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
const glm::vec3& Camera::viewDirection() const
|
||||
{
|
||||
return _viewDirection;
|
||||
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 float& Camera::maxFov() const
|
||||
{
|
||||
return _maxFov;
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// DEPRECATED CAMERA ACCESSORS (GETTERS) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const glm::mat4& Camera::viewMatrix() const {
|
||||
return sgctInternal.viewMatrix();
|
||||
}
|
||||
|
||||
const float& Camera::sinMaxFov() const
|
||||
{
|
||||
return _sinMaxFov;
|
||||
const glm::mat4& Camera::projectionMatrix() const {
|
||||
return sgctInternal.projectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::setMaxFov(float fov)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_maxFov = fov;
|
||||
_sinMaxFov = sin(_maxFov);
|
||||
const glm::mat4& Camera::viewProjectionMatrix() const {
|
||||
return sgctInternal.viewProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::setScaling(glm::vec2 scaling)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_localScaling = std::move(scaling);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
}
|
||||
|
||||
const glm::vec2& Camera::scaling() const
|
||||
{
|
||||
//return _localScaling;
|
||||
return _syncedScaling;
|
||||
}
|
||||
|
||||
void Camera::setLookUpVector(glm::vec3 lookUp)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_lookUp = std::move(lookUp);
|
||||
}
|
||||
|
||||
const glm::vec3& Camera::lookUpVector() const
|
||||
{
|
||||
return _lookUp;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 +208,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 +218,13 @@ 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 +232,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
|
||||
|
||||
Reference in New Issue
Block a user