mirror of https://github.com/vitalif/openscad
commit
578b70c40d
|
@ -101,25 +101,20 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
|
||||||
|
|
||||||
void Camera::zoom(int delta)
|
void Camera::zoom(int delta)
|
||||||
{
|
{
|
||||||
if (this->projection == PERSPECTIVE) {
|
this->viewer_distance *= pow(0.9, delta / 120.0);
|
||||||
this->viewer_distance *= pow(0.9, delta / 120.0);
|
this->height = this->viewer_distance;
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->height *= pow(0.9, delta / 120.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::setProjection(ProjectionType type)
|
void Camera::setProjection(ProjectionType type)
|
||||||
{
|
{
|
||||||
if (this->projection != type) {
|
this->projection = type;
|
||||||
switch (type) {
|
}
|
||||||
case PERSPECTIVE:
|
|
||||||
this->viewer_distance = this->height;
|
std::string Camera::statusText()
|
||||||
break;
|
{
|
||||||
case ORTHOGONAL:
|
boost::format fmt(_("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f"));
|
||||||
this->height = this->viewer_distance;
|
fmt % object_trans.x() % object_trans.y() % object_trans.z()
|
||||||
break;
|
% object_rot.x() % object_rot.y() % object_rot.z()
|
||||||
}
|
% (this->projection == PERSPECTIVE ? viewer_distance : height);
|
||||||
this->projection = type;
|
return fmt.str();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
void setProjection(ProjectionType type);
|
void setProjection(ProjectionType type);
|
||||||
void zoom(int delta);
|
void zoom(int delta);
|
||||||
void viewAll(const BoundingBox &bbox, float scalefactor = 1.0f);
|
void viewAll(const BoundingBox &bbox, float scalefactor = 1.0f);
|
||||||
|
std::string statusText();
|
||||||
|
|
||||||
// Vectorcam
|
// Vectorcam
|
||||||
Eigen::Vector3d eye;
|
Eigen::Vector3d eye;
|
||||||
|
|
|
@ -91,21 +91,23 @@ void GLView::setupCamera()
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
switch (this->cam.type) {
|
switch (this->cam.type) {
|
||||||
case Camera::GIMBAL:
|
case Camera::GIMBAL: {
|
||||||
|
double eyeY = 0.0;
|
||||||
switch (this->cam.projection) {
|
switch (this->cam.projection) {
|
||||||
case Camera::PERSPECTIVE: {
|
case Camera::PERSPECTIVE: {
|
||||||
double dist = cam.viewer_distance;
|
eyeY = cam.viewer_distance;
|
||||||
gluPerspective(cam.fov, aspectratio, 0.1*dist, 100*dist);
|
gluPerspective(cam.fov, aspectratio, 0.1 * eyeY, 100 * eyeY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Camera::ORTHOGONAL: {
|
case Camera::ORTHOGONAL: {
|
||||||
|
eyeY = cam.height;
|
||||||
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);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gluLookAt(0.0, -cam.viewer_distance, 0.0,
|
gluLookAt(0.0, -eyeY, 0.0,
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0);
|
0.0, 0.0, 1.0);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
@ -114,6 +116,7 @@ void GLView::setupCamera()
|
||||||
glRotated(cam.object_rot.y(), 0.0, 1.0, 0.0);
|
glRotated(cam.object_rot.y(), 0.0, 1.0, 0.0);
|
||||||
glRotated(cam.object_rot.z(), 0.0, 0.0, 1.0);
|
glRotated(cam.object_rot.z(), 0.0, 0.0, 1.0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Camera::VECTOR: {
|
case Camera::VECTOR: {
|
||||||
switch (this->cam.projection) {
|
switch (this->cam.projection) {
|
||||||
case Camera::PERSPECTIVE: {
|
case Camera::PERSPECTIVE: {
|
||||||
|
|
|
@ -164,16 +164,9 @@ void QGLView::paintGL()
|
||||||
GLView::paintGL();
|
GLView::paintGL();
|
||||||
|
|
||||||
if (statusLabel) {
|
if (statusLabel) {
|
||||||
QString msg;
|
|
||||||
|
|
||||||
Camera nc(cam);
|
Camera nc(cam);
|
||||||
nc.gimbalDefaultTranslate();
|
nc.gimbalDefaultTranslate();
|
||||||
msg.sprintf(_("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f"),
|
statusLabel->setText(QString::fromStdString(nc.statusText()));
|
||||||
nc.object_trans.x(), nc.object_trans.y(), nc.object_trans.z(),
|
|
||||||
nc.object_rot.x(), nc.object_rot.y(), nc.object_rot.z(),
|
|
||||||
nc.viewer_distance );
|
|
||||||
|
|
||||||
statusLabel->setText(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (running_under_wine) swapBuffers();
|
if (running_under_wine) swapBuffers();
|
||||||
|
|
Loading…
Reference in New Issue