mirror of https://github.com/vitalif/openscad
Merge branch 'master' of github.com:openscad/openscad
commit
d0cee28898
|
@ -3,13 +3,13 @@
|
|||
#include "printutils.h"
|
||||
|
||||
Camera::Camera(enum CameraType camtype) :
|
||||
type(camtype), projection(Camera::PERSPECTIVE), fov(45), height(60), viewall(false)
|
||||
type(camtype), projection(Camera::PERSPECTIVE), fov(45), viewall(false), zoom_value(60)
|
||||
{
|
||||
PRINTD("Camera()");
|
||||
if (this->type == Camera::GIMBAL) {
|
||||
object_trans << 0,0,0;
|
||||
object_rot << 35,0,25;
|
||||
viewer_distance = 500;
|
||||
zoom_value = 500;
|
||||
} else if (this->type == Camera::VECTOR) {
|
||||
center << 0,0,0;
|
||||
Eigen::Vector3d cameradir(1, 1, -0.5);
|
||||
|
@ -26,8 +26,7 @@ void Camera::setup(std::vector<double> params)
|
|||
type = Camera::GIMBAL;
|
||||
object_trans << params[0], params[1], params[2];
|
||||
object_rot << params[3], params[4], params[5];
|
||||
viewer_distance = params[6];
|
||||
height = params[6];
|
||||
zoom_value = params[6];
|
||||
} else if (params.size() == 6) {
|
||||
type = Camera::VECTOR;
|
||||
eye << params[0], params[1], params[2];
|
||||
|
@ -74,13 +73,13 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
|
|||
|
||||
switch (this->projection) {
|
||||
case Camera::ORTHOGONAL:
|
||||
this->height = bbox.diagonal().norm();
|
||||
this->zoom_value = bbox.diagonal().norm();
|
||||
break;
|
||||
case Camera::PERSPECTIVE: {
|
||||
double radius = bbox.diagonal().norm()/2;
|
||||
switch (this->type) {
|
||||
case Camera::GIMBAL:
|
||||
this->viewer_distance = radius / tan(this->fov*M_PI/360);
|
||||
this->zoom_value = radius / tan(this->fov*M_PI/360);
|
||||
break;
|
||||
case Camera::VECTOR: {
|
||||
Vector3d cameradir = (this->center - this->eye).normalized();
|
||||
|
@ -101,25 +100,31 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
|
|||
|
||||
void Camera::zoom(int delta)
|
||||
{
|
||||
if (this->projection == PERSPECTIVE) {
|
||||
this->viewer_distance *= pow(0.9, delta / 120.0);
|
||||
}
|
||||
else {
|
||||
this->height *= pow(0.9, delta / 120.0);
|
||||
}
|
||||
this->zoom_value *= pow(0.9, delta / 120.0);
|
||||
}
|
||||
|
||||
void Camera::setProjection(ProjectionType type)
|
||||
{
|
||||
if (this->projection != type) {
|
||||
switch (type) {
|
||||
case PERSPECTIVE:
|
||||
this->viewer_distance = this->height;
|
||||
break;
|
||||
case ORTHOGONAL:
|
||||
this->height = this->viewer_distance;
|
||||
break;
|
||||
}
|
||||
this->projection = type;
|
||||
}
|
||||
this->projection = type;
|
||||
}
|
||||
|
||||
void Camera::resetView()
|
||||
{
|
||||
object_rot << 35, 0, -25;
|
||||
object_trans << 0, 0, 0;
|
||||
zoom_value = 140;
|
||||
}
|
||||
|
||||
double Camera::zoomValue()
|
||||
{
|
||||
return zoom_value;
|
||||
}
|
||||
|
||||
std::string Camera::statusText()
|
||||
{
|
||||
boost::format fmt(_("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f"));
|
||||
fmt % object_trans.x() % object_trans.y() % object_trans.z()
|
||||
% object_rot.x() % object_rot.y() % object_rot.z()
|
||||
% zoom_value;
|
||||
return fmt.str();
|
||||
}
|
||||
|
|
13
src/Camera.h
13
src/Camera.h
|
@ -30,7 +30,10 @@ public:
|
|||
void gimbalDefaultTranslate();
|
||||
void setProjection(ProjectionType type);
|
||||
void zoom(int delta);
|
||||
void resetView();
|
||||
void viewAll(const BoundingBox &bbox, float scalefactor = 1.0f);
|
||||
double zoomValue();
|
||||
std::string statusText();
|
||||
|
||||
// Vectorcam
|
||||
Eigen::Vector3d eye;
|
||||
|
@ -40,14 +43,10 @@ public:
|
|||
// Gimbalcam
|
||||
Eigen::Vector3d object_trans;
|
||||
Eigen::Vector3d object_rot;
|
||||
double viewer_distance;
|
||||
|
||||
// Perspective settings
|
||||
double fov; // Field of view
|
||||
|
||||
// Orthographic settings
|
||||
double height; // world-space height of viewport
|
||||
|
||||
// true if camera should try to view everything in a given
|
||||
// bounding box.
|
||||
bool viewall;
|
||||
|
@ -58,4 +57,10 @@ public:
|
|||
|
||||
unsigned int pixel_width;
|
||||
unsigned int pixel_height;
|
||||
|
||||
protected:
|
||||
// This is the viewer-distance in perspective mode and in
|
||||
// ortographic mode, this is defining the viewport height
|
||||
// (in world-space)
|
||||
double zoom_value;
|
||||
};
|
||||
|
|
|
@ -91,21 +91,22 @@ void GLView::setupCamera()
|
|||
glLoadIdentity();
|
||||
|
||||
switch (this->cam.type) {
|
||||
case Camera::GIMBAL:
|
||||
case Camera::GIMBAL: {
|
||||
switch (this->cam.projection) {
|
||||
case Camera::PERSPECTIVE: {
|
||||
double dist = cam.viewer_distance;
|
||||
gluPerspective(cam.fov, aspectratio, 0.1*dist, 100*dist);
|
||||
double dist = cam.zoomValue();
|
||||
gluPerspective(cam.fov, aspectratio, 0.1 * dist, 100 * dist);
|
||||
break;
|
||||
}
|
||||
case Camera::ORTHOGONAL: {
|
||||
glOrtho(-cam.height/2*aspectratio, cam.height*aspectratio/2,
|
||||
-cam.height/2, cam.height/2,
|
||||
double height = cam.zoomValue();
|
||||
glOrtho(-height/2*aspectratio, height*aspectratio/2,
|
||||
-height/2, height/2,
|
||||
-far_far_away, +far_far_away);
|
||||
break;
|
||||
}
|
||||
}
|
||||
gluLookAt(0.0, -cam.viewer_distance, 0.0,
|
||||
gluLookAt(0.0, -cam.zoomValue(), 0.0,
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
@ -114,6 +115,7 @@ void GLView::setupCamera()
|
|||
glRotated(cam.object_rot.y(), 0.0, 1.0, 0.0);
|
||||
glRotated(cam.object_rot.z(), 0.0, 0.0, 1.0);
|
||||
break;
|
||||
}
|
||||
case Camera::VECTOR: {
|
||||
switch (this->cam.projection) {
|
||||
case Camera::PERSPECTIVE: {
|
||||
|
@ -122,8 +124,9 @@ void GLView::setupCamera()
|
|||
break;
|
||||
}
|
||||
case Camera::ORTHOGONAL: {
|
||||
glOrtho(-cam.height/2*aspectratio, cam.height*aspectratio/2,
|
||||
-cam.height/2, cam.height/2,
|
||||
double height = cam.zoomValue();
|
||||
glOrtho(-height/2*aspectratio, height*aspectratio/2,
|
||||
-height/2, height/2,
|
||||
-far_far_away, +far_far_away);
|
||||
break;
|
||||
}
|
||||
|
@ -450,7 +453,7 @@ void GLView::showSmallaxes(const Color4f &col)
|
|||
|
||||
void GLView::showAxes(const Color4f &col)
|
||||
{
|
||||
double l = cam.projection == Camera::PERSPECTIVE ? cam.viewer_distance : cam.height;
|
||||
double l = cam.zoomValue();
|
||||
|
||||
// FIXME: doesn't work under Vector Camera
|
||||
// Large gray axis cross inline with the model
|
||||
|
@ -489,7 +492,7 @@ void GLView::showCrosshairs()
|
|||
glBegin(GL_LINES);
|
||||
for (double xf = -1; xf <= +1; xf += 2)
|
||||
for (double yf = -1; yf <= +1; yf += 2) {
|
||||
double vd = cam.viewer_distance/8;
|
||||
double vd = cam.zoomValue()/8;
|
||||
glVertex3d(-xf*vd, -yf*vd, -vd);
|
||||
glVertex3d(+xf*vd, +yf*vd, +vd);
|
||||
}
|
||||
|
|
|
@ -84,9 +84,7 @@ void QGLView::init()
|
|||
|
||||
void QGLView::resetView()
|
||||
{
|
||||
cam.object_rot << 35, 0, -25;
|
||||
cam.object_trans << 0, 0, 0;
|
||||
cam.viewer_distance = 140;
|
||||
cam.resetView();
|
||||
}
|
||||
|
||||
void QGLView::viewAll()
|
||||
|
@ -164,16 +162,9 @@ void QGLView::paintGL()
|
|||
GLView::paintGL();
|
||||
|
||||
if (statusLabel) {
|
||||
QString msg;
|
||||
|
||||
Camera nc(cam);
|
||||
nc.gimbalDefaultTranslate();
|
||||
msg.sprintf(_("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f"),
|
||||
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);
|
||||
statusLabel->setText(QString::fromStdString(nc.statusText()));
|
||||
}
|
||||
|
||||
if (running_under_wine) swapBuffers();
|
||||
|
@ -252,11 +243,10 @@ void QGLView::mouseMoveEvent(QMouseEvent *event)
|
|||
// Middle button pans in the xy plane
|
||||
// Shift-right and Shift-middle zooms
|
||||
if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) {
|
||||
cam.viewer_distance += (GLdouble)dy;
|
||||
cam.zoom(-12.0 * dy);
|
||||
} else {
|
||||
|
||||
double mx = +(dx) * cam.viewer_distance/1000;
|
||||
double mz = -(dy) * cam.viewer_distance/1000;
|
||||
double mx = +(dx) * 3.0 * cam.zoomValue() / QWidget::width();
|
||||
double mz = -(dy) * 3.0 * cam.zoomValue() / QWidget::height();
|
||||
|
||||
double my = 0;
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(4, 7, 0))
|
||||
|
|
|
@ -1505,7 +1505,7 @@ void MainWindow::updateTemporalVariables()
|
|||
vpr.push_back(Value(fmodf(360 - qglview->cam.object_rot.z(), 360)));
|
||||
top_ctx.set_variable("$vpr", ValuePtr(vpr));
|
||||
|
||||
top_ctx.set_variable("$vpd", ValuePtr(qglview->cam.viewer_distance));
|
||||
top_ctx.set_variable("$vpd", ValuePtr(qglview->cam.zoomValue()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1529,7 +1529,7 @@ void MainWindow::updateCamera()
|
|||
double rx = cam.object_rot.x();
|
||||
double ry = cam.object_rot.y();
|
||||
double rz = cam.object_rot.z();
|
||||
double d = cam.viewer_distance;
|
||||
double d = cam.zoomValue();
|
||||
|
||||
double x, y, z;
|
||||
const ValuePtr vpr = root_module->lookup_variable("$vpr");
|
||||
|
|
Loading…
Reference in New Issue