mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-06 20:38:44 -06:00
Merge branch 'feature/camera' into feature/interaction
This commit is contained in:
@@ -63,17 +63,19 @@ namespace openspace {
|
||||
for caching.
|
||||
*/
|
||||
template<typename T>
|
||||
struct CachedDatum
|
||||
struct Cached
|
||||
{
|
||||
CachedDatum() { isDirty = true; }
|
||||
Cached() { isDirty = true; }
|
||||
T datum;
|
||||
bool isDirty;
|
||||
};
|
||||
|
||||
// For testing double vs float precision
|
||||
typedef glm::dquat Quat;
|
||||
typedef glm::dmat4 Mat4;
|
||||
typedef glm::dvec3 Vec3;
|
||||
// now working with float precision. To be changed to double later.
|
||||
// The reason double does not work yet is because of the setUniform function
|
||||
// in ghoul::opengl
|
||||
typedef glm::quat Quat;
|
||||
typedef glm::mat4 Mat4;
|
||||
typedef glm::vec3 Vec3;
|
||||
|
||||
// Static constants
|
||||
static const Vec3 _VIEW_DIRECTION_CAMERA_SPACE;
|
||||
@@ -99,18 +101,18 @@ namespace openspace {
|
||||
const Vec3& unsynchedPositionVec3() const;
|
||||
const Vec3& focusPositionVec3() const;
|
||||
// Should return const refs
|
||||
glm::vec3 viewDirectionWorldSpace() const;
|
||||
glm::vec3 lookUpVectorCameraSpace() const;
|
||||
const Vec3& viewDirectionWorldSpace() const;
|
||||
const Vec3& lookUpVectorCameraSpace() const;
|
||||
const glm::vec2& scaling() const;
|
||||
glm::mat4 viewRotationMatrix() const;
|
||||
glm::quat rotationQuaternion() const;
|
||||
const Mat4& viewRotationMatrix() const;
|
||||
const Quat& rotationQuaternion() const;
|
||||
float maxFov() const;
|
||||
float sinMaxFov() const;
|
||||
|
||||
// @TODO this should simply be called viewMatrix!
|
||||
// Or it needs to be changed so that it actually is combined. Right now it is
|
||||
// only the view matrix that is the same for all SGCT cameras.
|
||||
glm::mat4 combinedViewMatrix() const;
|
||||
const Mat4& combinedViewMatrix() const;
|
||||
|
||||
// Synchronization
|
||||
void postSynchronizationPreDraw();
|
||||
@@ -145,7 +147,7 @@ namespace openspace {
|
||||
glm::mat4 _projectionMatrix;
|
||||
|
||||
// Cache
|
||||
mutable CachedDatum<glm::mat4> _cachedViewProjectionMatrix;
|
||||
mutable Cached<glm::mat4> _cachedViewProjectionMatrix;
|
||||
mutable std::mutex _mutex;
|
||||
} sgctInternal;
|
||||
|
||||
@@ -193,14 +195,15 @@ namespace openspace {
|
||||
SyncData<Quat> _rotation;
|
||||
SyncData<glm::vec2> _scaling;
|
||||
|
||||
// _focusPosition to be removed
|
||||
Vec3 _focusPosition;
|
||||
float _maxFov;
|
||||
|
||||
// Cached data
|
||||
mutable CachedDatum<Vec3> _cachedViewDirection;
|
||||
mutable CachedDatum<Mat4> _cachedViewRotationMatrix;
|
||||
mutable CachedDatum<Mat4> _cachedCombinedViewMatrix;
|
||||
mutable CachedDatum<float> _cachedSinMaxFov;
|
||||
mutable Cached<Vec3> _cachedViewDirection;
|
||||
mutable Cached<Mat4> _cachedViewRotationMatrix;
|
||||
mutable Cached<Mat4> _cachedCombinedViewMatrix;
|
||||
mutable Cached<float> _cachedSinMaxFov;
|
||||
|
||||
mutable std::mutex _mutex;
|
||||
};
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace openspace {
|
||||
return _focusPosition;
|
||||
}
|
||||
|
||||
glm::vec3 Camera::viewDirectionWorldSpace() const {
|
||||
const Camera::Vec3& Camera::viewDirectionWorldSpace() const {
|
||||
if (_cachedViewDirection.isDirty) {
|
||||
_cachedViewDirection.datum =
|
||||
glm::inverse(_rotation.local) * Vec3(_VIEW_DIRECTION_CAMERA_SPACE);
|
||||
@@ -117,7 +117,7 @@ namespace openspace {
|
||||
return _cachedViewDirection.datum;
|
||||
}
|
||||
|
||||
glm::vec3 Camera::lookUpVectorCameraSpace() const {
|
||||
const Camera::Vec3& Camera::lookUpVectorCameraSpace() const {
|
||||
return _LOOKUP_VECTOR_CAMERA_SPACE;
|
||||
}
|
||||
|
||||
@@ -136,18 +136,18 @@ namespace openspace {
|
||||
return _cachedSinMaxFov.datum;
|
||||
}
|
||||
|
||||
glm::mat4 Camera::viewRotationMatrix() const {
|
||||
const Camera::Mat4& Camera::viewRotationMatrix() const {
|
||||
if (_cachedViewRotationMatrix.isDirty) {
|
||||
_cachedViewRotationMatrix.datum = glm::mat4_cast(_rotation.local);
|
||||
}
|
||||
return _cachedViewRotationMatrix.datum;
|
||||
}
|
||||
|
||||
glm::quat Camera::rotationQuaternion() const {
|
||||
const Camera::Quat& Camera::rotationQuaternion() const {
|
||||
return _rotation.synced;
|
||||
}
|
||||
|
||||
glm::mat4 Camera::combinedViewMatrix() const {
|
||||
const Camera::Mat4& Camera::combinedViewMatrix() const {
|
||||
if (_cachedCombinedViewMatrix.isDirty) {
|
||||
glm::vec3 cameraPosition = position().vec3();
|
||||
glm::mat4 cameraTranslation =
|
||||
|
||||
Reference in New Issue
Block a user