Skip to content

Commit cecc7f2

Browse files
committed
viewer: replace deprecated gluLookAt
1 parent 30bac45 commit cecc7f2

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

apps/Viewer/Camera.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,30 @@ void Camera::SetFOV(double _fov)
103103

104104
Eigen::Vector3d Camera::GetPosition() const
105105
{
106-
const Eigen::Matrix3d r(rotation.toRotationMatrix());
106+
const Eigen::Matrix3d R(rotation.toRotationMatrix());
107107
const Eigen::Vector3d eye(0, 0, dist);
108-
return r * eye + center;
108+
return R * eye + center;
109109
}
110110

111-
void Camera::GetLookAt(Eigen::Vector3d& _eye, Eigen::Vector3d& _center, Eigen::Vector3d& _up)
111+
Eigen::Matrix4d Camera::GetLookAt() const
112+
{
113+
const Eigen::Matrix3d R(rotation.toRotationMatrix());
114+
const Eigen::Vector3d eye(R.col(2) * dist + center);
115+
const Eigen::Vector3d up(R.col(1));
116+
117+
const Eigen::Vector3d n((center-eye).normalized());
118+
const Eigen::Vector3d s(n.cross(up));
119+
const Eigen::Vector3d v(s.cross(n));
120+
121+
Eigen::Matrix4d m;
122+
m <<
123+
s(0), s(1), s(2), -eye.dot(s),
124+
v(0), v(1), v(2), -eye.dot(v),
125+
-n(0), -n(1), -n(2), eye.dot(n),
126+
0.0, 0.0, 0.0, 1.0;
127+
return m;
128+
}
129+
void Camera::GetLookAt(Eigen::Vector3d& _eye, Eigen::Vector3d& _center, Eigen::Vector3d& _up) const
112130
{
113131
const Eigen::Matrix3d R(rotation.toRotationMatrix());
114132
const Eigen::Vector3d eye(0, 0, dist);

apps/Viewer/Camera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class Camera
6868
void SetFOV(double _fov);
6969

7070
Eigen::Vector3d GetPosition() const;
71-
void GetLookAt(Eigen::Vector3d& eye, Eigen::Vector3d& center, Eigen::Vector3d& up);
71+
Eigen::Matrix4d GetLookAt() const;
72+
void GetLookAt(Eigen::Vector3d& eye, Eigen::Vector3d& center, Eigen::Vector3d& up) const;
7273
void Rotate(const Eigen::Vector2d& pos, const Eigen::Vector2d& prevPos);
7374

7475
protected:

apps/Viewer/Window.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,19 @@ void Window::Reset()
124124
void Window::UpdateView(const ImageArr& images, const MVS::ImageArr& sceneImages)
125125
{
126126
glMatrixMode(GL_MODELVIEW);
127-
glLoadIdentity();
128127
if (camera->prevCamID != camera->currentCamID && camera->currentCamID != NO_ID) {
129128
// enable camera view mode
130129
// apply current camera transform
131130
const Image& image = images[camera->currentCamID];
132131
const MVS::Image& imageData = sceneImages[image.idx];
133132
const MVS::Camera& camera = imageData.camera;
134133
const Eigen::Matrix4d trans(TransW2L((const Matrix3x3::EMat)camera.R, camera.GetT()));
135-
glMultMatrixf((GLfloat*)gs_convert);
134+
glLoadMatrixf((GLfloat*)gs_convert);
136135
glMultMatrixd((GLdouble*)trans.data());
137136
} else {
138137
// apply view point transform
139-
Eigen::Vector3d eye, center, up;
140-
camera->GetLookAt(eye, center, up);
141-
gluLookAt(eye.x(), eye.y(), eye.z(), center.x(), center.y(), center.z(), up.x(), up.y(), up.z());
138+
const Eigen::Matrix4d trans(camera->GetLookAt());
139+
glLoadMatrixd((GLdouble*)trans.data());
142140
}
143141
}
144142

0 commit comments

Comments
 (0)