Some cleanup of old eigen2 workarounds. Added fix to support cameras looking down the Z axis

master
Marius Kintel 2014-06-21 12:44:38 -04:00
parent 96d17bd6e2
commit 81d92f2254
4 changed files with 7 additions and 28 deletions

View File

@ -52,23 +52,21 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
{
if (this->type == Camera::NONE) {
this->type = Camera::VECTOR;
this->center = getBoundingCenter(bbox);
this->center = bbox.center();
this->eye = this->center - Vector3d(1,1,-0.5);
}
switch (this->projection) {
case Camera::ORTHOGONAL:
this->height = getBoundingRadius(bbox)*2;
this->height = bbox.diagonal().norm();
break;
case Camera::PERSPECTIVE: {
double radius = getBoundingRadius(bbox);
double radius = bbox.diagonal().norm()/2;
switch (this->type) {
case Camera::GIMBAL:
// FIXME: viewAll() of gimbal cameras doesn't work
this->viewer_distance = radius / tan(this->fov*M_PI/360);
break;
case Camera::VECTOR: {
// FIXME: viewAll() of orthographic cameras doesn't work
Vector3d cameradir = (this->center - this->eye).normalized();
this->eye = this->center - radius*scalefactor*cameradir;
break;

View File

@ -66,19 +66,18 @@ void GLView::setupCamera()
case Camera::PERSPECTIVE: {
double dist = cam.viewer_distance;
gluPerspective(cam.fov, aspectratio, 0.1*dist, 100*dist);
gluLookAt(0.0, -cam.viewer_distance, 0.0,
0.0, 0.0, 0.0,
0.0, 0.0, 1.0);
break;
}
case Camera::ORTHOGONAL: {
glOrtho(-cam.height/2*aspectratio, cam.height*aspectratio/2,
-cam.height/2, cam.height/2,
-far_far_away, +far_far_away);
gluLookAt(0.0, -cam.viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
break;
}
}
gluLookAt(0.0, -cam.viewer_distance, 0.0,
0.0, 0.0, 0.0,
0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotated(cam.object_rot.x(), 1.0, 0.0, 0.0);
@ -105,7 +104,7 @@ void GLView::setupCamera()
glLoadIdentity();
gluLookAt(cam.eye[0], cam.eye[1], cam.eye[2],
cam.center[0], cam.center[1], cam.center[2],
0.0, 0.0, 1.0);
0.0, 0.1, 1.0); // Tilt it a bit to be able to look down the Z axis
break;
default:
break;

View File

@ -46,18 +46,3 @@ bool matrix_contains_nan( const Transform3d &m )
}
return false;
}
double getBoundingRadius(BoundingBox bbox)
{
// FIXME: For eigen3, we can use bbox.diagonal().norm()/2;
double radius = (bbox.max() - bbox.min()).norm() / 2;
return radius; // 0;
}
Vector3d getBoundingCenter(BoundingBox bbox)
{
// FIXME: For eigen3, we can use bbox.center();
Vector3d center = (bbox.min() + bbox.max()) / 2;
return center; // Vector3d(0,0,0);
}

View File

@ -21,9 +21,6 @@ bool matrix_contains_infinity( const Transform3d &m );
bool matrix_contains_nan( const Transform3d &m );
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
Vector3d getBoundingCenter(BoundingBox bbox);
double getBoundingRadius(BoundingBox bbox);
class Color4f : public Eigen::Vector4f
{