mirror of https://github.com/vitalif/openscad
Some cleanup of old eigen2 workarounds. Added fix to support cameras looking down the Z axis
parent
96d17bd6e2
commit
81d92f2254
|
@ -52,23 +52,21 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
|
||||||
{
|
{
|
||||||
if (this->type == Camera::NONE) {
|
if (this->type == Camera::NONE) {
|
||||||
this->type = Camera::VECTOR;
|
this->type = Camera::VECTOR;
|
||||||
this->center = getBoundingCenter(bbox);
|
this->center = bbox.center();
|
||||||
this->eye = this->center - Vector3d(1,1,-0.5);
|
this->eye = this->center - Vector3d(1,1,-0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this->projection) {
|
switch (this->projection) {
|
||||||
case Camera::ORTHOGONAL:
|
case Camera::ORTHOGONAL:
|
||||||
this->height = getBoundingRadius(bbox)*2;
|
this->height = bbox.diagonal().norm();
|
||||||
break;
|
break;
|
||||||
case Camera::PERSPECTIVE: {
|
case Camera::PERSPECTIVE: {
|
||||||
double radius = getBoundingRadius(bbox);
|
double radius = bbox.diagonal().norm()/2;
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
case Camera::GIMBAL:
|
case Camera::GIMBAL:
|
||||||
// FIXME: viewAll() of gimbal cameras doesn't work
|
|
||||||
this->viewer_distance = radius / tan(this->fov*M_PI/360);
|
this->viewer_distance = radius / tan(this->fov*M_PI/360);
|
||||||
break;
|
break;
|
||||||
case Camera::VECTOR: {
|
case Camera::VECTOR: {
|
||||||
// FIXME: viewAll() of orthographic cameras doesn't work
|
|
||||||
Vector3d cameradir = (this->center - this->eye).normalized();
|
Vector3d cameradir = (this->center - this->eye).normalized();
|
||||||
this->eye = this->center - radius*scalefactor*cameradir;
|
this->eye = this->center - radius*scalefactor*cameradir;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -66,19 +66,18 @@ void GLView::setupCamera()
|
||||||
case Camera::PERSPECTIVE: {
|
case Camera::PERSPECTIVE: {
|
||||||
double dist = cam.viewer_distance;
|
double dist = cam.viewer_distance;
|
||||||
gluPerspective(cam.fov, aspectratio, 0.1*dist, 100*dist);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case Camera::ORTHOGONAL: {
|
case Camera::ORTHOGONAL: {
|
||||||
glOrtho(-cam.height/2*aspectratio, cam.height*aspectratio/2,
|
glOrtho(-cam.height/2*aspectratio, cam.height*aspectratio/2,
|
||||||
-cam.height/2, cam.height/2,
|
-cam.height/2, cam.height/2,
|
||||||
-far_far_away, +far_far_away);
|
-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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gluLookAt(0.0, -cam.viewer_distance, 0.0,
|
||||||
|
0.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 1.0);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glRotated(cam.object_rot.x(), 1.0, 0.0, 0.0);
|
glRotated(cam.object_rot.x(), 1.0, 0.0, 0.0);
|
||||||
|
@ -105,7 +104,7 @@ void GLView::setupCamera()
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(cam.eye[0], cam.eye[1], cam.eye[2],
|
gluLookAt(cam.eye[0], cam.eye[1], cam.eye[2],
|
||||||
cam.center[0], cam.center[1], cam.center[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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -46,18 +46,3 @@ bool matrix_contains_nan( const Transform3d &m )
|
||||||
}
|
}
|
||||||
return false;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,6 @@ bool matrix_contains_infinity( const Transform3d &m );
|
||||||
bool matrix_contains_nan( const Transform3d &m );
|
bool matrix_contains_nan( const Transform3d &m );
|
||||||
|
|
||||||
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
|
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
|
||||||
Vector3d getBoundingCenter(BoundingBox bbox);
|
|
||||||
double getBoundingRadius(BoundingBox bbox);
|
|
||||||
|
|
||||||
|
|
||||||
class Color4f : public Eigen::Vector4f
|
class Color4f : public Eigen::Vector4f
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue