Skip to content

Commit

Permalink
viewer: replace deprecated gluLookAt
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Dec 21, 2018
1 parent 30bac45 commit cecc7f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
24 changes: 21 additions & 3 deletions apps/Viewer/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,30 @@ void Camera::SetFOV(double _fov)

Eigen::Vector3d Camera::GetPosition() const
{
const Eigen::Matrix3d r(rotation.toRotationMatrix());
const Eigen::Matrix3d R(rotation.toRotationMatrix());
const Eigen::Vector3d eye(0, 0, dist);
return r * eye + center;
return R * eye + center;
}

void Camera::GetLookAt(Eigen::Vector3d& _eye, Eigen::Vector3d& _center, Eigen::Vector3d& _up)
Eigen::Matrix4d Camera::GetLookAt() const
{
const Eigen::Matrix3d R(rotation.toRotationMatrix());
const Eigen::Vector3d eye(R.col(2) * dist + center);
const Eigen::Vector3d up(R.col(1));

const Eigen::Vector3d n((center-eye).normalized());
const Eigen::Vector3d s(n.cross(up));
const Eigen::Vector3d v(s.cross(n));

Eigen::Matrix4d m;
m <<
s(0), s(1), s(2), -eye.dot(s),
v(0), v(1), v(2), -eye.dot(v),
-n(0), -n(1), -n(2), eye.dot(n),
0.0, 0.0, 0.0, 1.0;
return m;
}
void Camera::GetLookAt(Eigen::Vector3d& _eye, Eigen::Vector3d& _center, Eigen::Vector3d& _up) const
{
const Eigen::Matrix3d R(rotation.toRotationMatrix());
const Eigen::Vector3d eye(0, 0, dist);
Expand Down
3 changes: 2 additions & 1 deletion apps/Viewer/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Camera
void SetFOV(double _fov);

Eigen::Vector3d GetPosition() const;
void GetLookAt(Eigen::Vector3d& eye, Eigen::Vector3d& center, Eigen::Vector3d& up);
Eigen::Matrix4d GetLookAt() const;
void GetLookAt(Eigen::Vector3d& eye, Eigen::Vector3d& center, Eigen::Vector3d& up) const;
void Rotate(const Eigen::Vector2d& pos, const Eigen::Vector2d& prevPos);

protected:
Expand Down
8 changes: 3 additions & 5 deletions apps/Viewer/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,19 @@ void Window::Reset()
void Window::UpdateView(const ImageArr& images, const MVS::ImageArr& sceneImages)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (camera->prevCamID != camera->currentCamID && camera->currentCamID != NO_ID) {
// enable camera view mode
// apply current camera transform
const Image& image = images[camera->currentCamID];
const MVS::Image& imageData = sceneImages[image.idx];
const MVS::Camera& camera = imageData.camera;
const Eigen::Matrix4d trans(TransW2L((const Matrix3x3::EMat)camera.R, camera.GetT()));
glMultMatrixf((GLfloat*)gs_convert);
glLoadMatrixf((GLfloat*)gs_convert);
glMultMatrixd((GLdouble*)trans.data());
} else {
// apply view point transform
Eigen::Vector3d eye, center, up;
camera->GetLookAt(eye, center, up);
gluLookAt(eye.x(), eye.y(), eye.z(), center.x(), center.y(), center.z(), up.x(), up.y(), up.z());
const Eigen::Matrix4d trans(camera->GetLookAt());
glLoadMatrixd((GLdouble*)trans.data());
}
}

Expand Down

0 comments on commit cecc7f2

Please sign in to comment.