mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Merge branch 'feature/camera' into solarsystem2
This commit is contained in:
@@ -111,12 +111,13 @@ public:
|
||||
void setCameraDirection(glm::vec3 cameraDirection);
|
||||
glm::vec3 cameraDirection() const;
|
||||
|
||||
const glm::mat4& viewRotationMatrix() const;
|
||||
glm::mat4 viewRotationMatrix() const;
|
||||
void compileViewRotationMatrix();
|
||||
|
||||
void rotate(const glm::quat& rotation);
|
||||
void setRotation(glm::quat rotation);
|
||||
const glm::quat& rotation() const;
|
||||
// const glm::quat& rotation() const;
|
||||
void setRotation(glm::mat4 rotation);
|
||||
|
||||
const glm::vec3& viewDirection() const;
|
||||
|
||||
@@ -140,7 +141,7 @@ private:
|
||||
glm::vec3 _viewDirection;
|
||||
glm::vec3 _cameraDirection;
|
||||
glm::vec2 _scaling;
|
||||
glm::quat _viewRotation;
|
||||
// glm::quat _viewRotation;
|
||||
glm::mat4 _viewRotationMatrix; // compiled from the quaternion
|
||||
|
||||
glm::vec3 _lookUp;
|
||||
|
||||
@@ -161,12 +161,19 @@ void InteractionHandler::orbit(const glm::quat &rotation) {
|
||||
}
|
||||
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
glm::mat4 rotation_matrix = glm::mat4_cast(rotation);
|
||||
relative_origin_coordinate = relative_origin_coordinate * rotation_matrix;
|
||||
//glm::mat4 rotation_matrix = glm::mat4_cast(glm::inverse(rotation));
|
||||
//relative_origin_coordinate = relative_origin_coordinate.vec4() * glm::inverse(rotation);
|
||||
relative_origin_coordinate = glm::inverse(rotation) * relative_origin_coordinate.vec4();
|
||||
relative = relative_origin_coordinate + origin;
|
||||
|
||||
camera_->setPosition(relative);
|
||||
|
||||
//camera_->rotate(rotation);
|
||||
//camera_->setRotation(glm::mat4_cast(rotation));
|
||||
|
||||
glm::mat4 la = glm::lookAt(camera_->position().vec3(), node_->worldPosition().vec3(), glm::rotate(rotation, camera_->lookUpVector()));
|
||||
camera_->setRotation(la);
|
||||
//camera_->setLookUpVector();
|
||||
|
||||
unlockControls();
|
||||
}
|
||||
|
||||
@@ -268,7 +275,7 @@ void InteractionHandler::trackballRotate(int x, int y) {
|
||||
glm::vec2 mousePos = glm::vec2((float)x/width, (float)y/height);
|
||||
|
||||
mousePos = glm::clamp(mousePos, -0.5, 1.5); // Ugly fix #1: Camera position becomes NaN on mouse values outside [-0.5, 1.5]
|
||||
mousePos[1] = 0.5; // Ugly fix #2: Tempoarily only allow rotation around y
|
||||
//mousePos[1] = 0.5; // Ugly fix #2: Tempoarily only allow rotation around y
|
||||
|
||||
glm::vec3 curTrackballPos = mapToTrackball(mousePos);
|
||||
// LDEBUG(mousePos.x << ", " << mousePos.y << " = " << curTrackballPos.x << ", " << curTrackballPos.y << ", " << curTrackballPos.z);
|
||||
@@ -295,9 +302,7 @@ void InteractionHandler::trackballRotate(int x, int y) {
|
||||
glm::quat quaternion = glm::angleAxis(rotationAngle, rotationAxis);
|
||||
|
||||
// Apply quaternion to camera
|
||||
orbit(glm::inverse(quaternion));
|
||||
camera_->rotate(quaternion);
|
||||
camera_->setLookUpVector(glm::rotate(quaternion, camera_->lookUpVector()));
|
||||
orbit(quaternion);
|
||||
|
||||
_lastTrackballPos = curTrackballPos;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ namespace openspace {
|
||||
Camera::Camera()
|
||||
: _cameraDirection(0.f, 0.f, 0.f)
|
||||
, _scaling(1.f, 0.f)
|
||||
, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
, _viewRotationMatrix(1.f)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,37 +100,46 @@ glm::vec3 Camera::cameraDirection() const
|
||||
return _cameraDirection;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewRotationMatrix() const
|
||||
glm::mat4 Camera::viewRotationMatrix() const
|
||||
{
|
||||
return _viewRotationMatrix;
|
||||
return glm::mat4(_viewRotationMatrix);
|
||||
}
|
||||
|
||||
void Camera::compileViewRotationMatrix()
|
||||
{
|
||||
// convert from quaternion to rotation matrix using glm
|
||||
_viewRotationMatrix = glm::mat4_cast(_viewRotation);
|
||||
//_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(_viewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz;
|
||||
_viewDirection = glm::normalize(_viewDirection);
|
||||
}
|
||||
|
||||
void Camera::rotate(const glm::quat& rotation)
|
||||
{
|
||||
_viewRotation = rotation * _viewRotation;
|
||||
_viewRotation = glm::normalize(_viewRotation);
|
||||
glm::mat4 tmp = glm::mat4_cast(rotation);
|
||||
_viewRotationMatrix = _viewRotationMatrix * tmp;
|
||||
//_viewRotation = rotation * _viewRotation;
|
||||
//_viewRotation = glm::normalize(_viewRotation);
|
||||
}
|
||||
|
||||
void Camera::setRotation(glm::quat rotation)
|
||||
{
|
||||
_viewRotation = glm::normalize(std::move(rotation));
|
||||
//_viewRotation = glm::normalize(std::move(rotation));
|
||||
_viewRotationMatrix = glm::mat4_cast(rotation);
|
||||
}
|
||||
|
||||
const glm::quat& Camera::rotation() const
|
||||
void Camera::setRotation(glm::mat4 rotation)
|
||||
{
|
||||
return _viewRotation;
|
||||
_viewRotationMatrix = std::move(rotation);
|
||||
}
|
||||
|
||||
//const glm::quat& Camera::rotation() const
|
||||
//{
|
||||
// return _viewRotation;
|
||||
//}
|
||||
|
||||
const glm::vec3& Camera::viewDirection() const
|
||||
{
|
||||
return _viewDirection;
|
||||
|
||||
Reference in New Issue
Block a user