summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Camera.h28
-rw-r--r--src/GLView.cc31
-rw-r--r--src/GLView.h26
-rw-r--r--src/export_png.cc8
-rw-r--r--src/openscad.cc54
5 files changed, 76 insertions, 71 deletions
diff --git a/src/Camera.h b/src/Camera.h
index 2d2b18f..8dd6f68 100644
--- a/src/Camera.h
+++ b/src/Camera.h
@@ -2,19 +2,12 @@
#define OPENSCAD_CAMERA_H_
// Cameras
-// Variant design is similar to value.h/value.cc
-// see GLView.cc / export_png.cc / openscad.cc for usage
+// For usage, see GLView.cc / export_png.cc / openscad.cc
#include <vector>
#include <Eigen/Geometry>
#include <boost/variant.hpp>
-class NullCamera
-{
-public:
- NullCamera(){}
-};
-
class GimbalCamera
{
public:
@@ -24,7 +17,7 @@ public:
object_rot << 35,0,25;
viewer_distance = 500;
}
- void setup( std::vector<double> d )
+ GimbalCamera( std::vector<double> d )
{
assert( d.size() == 7 );
object_trans << d[0], d[1], d[2];
@@ -46,6 +39,12 @@ public:
eye = center - 500 * cameradir;
// "up" not currently used
}
+ VectorCamera( std::vector<double> d )
+ {
+ assert( d.size() == 6 );
+ eye << d[0], d[1], d[2];
+ center << d[3], d[4], d[5];
+ }
Eigen::Vector3d eye;
Eigen::Vector3d center; // (aka 'target')
Eigen::Vector3d up;
@@ -54,11 +53,12 @@ public:
class Camera
{
public:
- enum CameraType { NONE, GIMBAL, VECTOR };
- typedef boost::variant<NullCamera, GimbalCamera, VectorCamera> CamVariant;
- CamVariant value;
- Camera() {}
- CameraType type() { return static_cast<CameraType>(value.which()); }
+ enum CameraType { NONE, GIMBAL, VECTOR } type;
+ Camera() { type = Camera::NONE; }
+ void set( VectorCamera &c ) { vcam = c; type = Camera::VECTOR; }
+ void set( GimbalCamera &c ) { gcam = c; type = Camera::GIMBAL; }
+ GimbalCamera gcam;
+ VectorCamera vcam;
};
diff --git a/src/GLView.cc b/src/GLView.cc
index 0c02922..6586ba2 100644
--- a/src/GLView.cc
+++ b/src/GLView.cc
@@ -45,14 +45,6 @@ void GLView::resizeGL(int w, int h)
w_h_ratio = sqrt((double)w / (double)h);
}
-void GLView::setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance)
-{
- gcam.object_trans = pos;
- gcam.object_rot = rot;
- gcam.viewer_distance = distance;
- camtype = Camera::GIMBAL;
-}
-
void GLView::setupGimbalCamPerspective()
{
glMatrixMode(GL_PROJECTION);
@@ -74,15 +66,6 @@ void GLView::setupGimbalCamOrtho(double distance, bool offset)
gluLookAt(0.0, -gcam.viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
}
-void GLView::setVectorCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center)
-{
- vcam.eye = pos;
- vcam.center = center;
- camtype = Camera::VECTOR;
- // FIXME kludge for showAxes to work in VectorCamera mode
- gcam.viewer_distance = 10*3*(vcam.center - vcam.eye).norm();
-}
-
void GLView::setupVectorCamPerspective()
{
glMatrixMode(GL_PROJECTION);
@@ -104,14 +87,12 @@ void GLView::setupVectorCamOrtho(bool offset)
void GLView::setCamera( Camera &cam )
{
- if ( cam.type() == Camera::NONE ) {
- return;
- } else if ( cam.type() == Camera::GIMBAL ) {
- GimbalCamera gc = boost::get<GimbalCamera>(cam.value);
- setGimbalCamera( gc.object_trans, gc.object_rot, gc.viewer_distance );
- } else if ( cam.type() == Camera::VECTOR ) {
- VectorCamera vc = boost::get<VectorCamera>(cam.value);
- setVectorCamera( vc.eye, vc.center );
+ camtype = cam.type;
+ if ( camtype == Camera::GIMBAL ) {
+ gcam = cam.gcam;
+ } else if ( camtype == Camera::VECTOR ) {
+ vcam = cam.vcam;
+ gcam.viewer_distance = 10*3*(vcam.center - vcam.eye).norm();
}
}
diff --git a/src/GLView.h b/src/GLView.h
index 30d3c03..dae402a 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -3,19 +3,23 @@
/* GLView: A basic OpenGL rectangle for rendering images.
-This class is inherited by
+This class is inherited by:
-*QGLview (for Qt GUI)
-*OffscreenView (used in tests and for offscreen command-line rendering).
+*QGLview - for Qt GUI
+*OffscreenView - for offscreen rendering, in tests and from command-line
-There are two different types of cameras
+There are two different types of cameras:
*Gimbal camera - uses Euler Angles, object translation, and viewer distance
-*Vector camera - uses 'eye', 'center', and 'up' vectors
+*Vector camera - uses 'eye', 'center', and 'up' vectors ('lookat' style)
-Currently, the two cameras are not kept in sync and they are not easily
-interchangable. QGLView uses GimbalCamera while OffscreenView can
-use either (defaulting to Vector).
+They are selectable by creating a GimbalCamera or VectorCamera (Camera.h)
+and then calling GLView.setCamera().
+
+Currently, the camera is set in two separate variables that are not kept
+in sync. Some actions (showCrossHairs) only work properly on Gimbal
+Camera. QGLView uses GimbalCamera while OffscreenView can use either one
+(defaulting to Vector).
*/
@@ -43,18 +47,16 @@ public:
void resizeGL(int w, int h);
virtual void paintGL();
- void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance);
+ void setCamera( Camera &cam );
+
void setupGimbalCamPerspective();
void setupGimbalCamOrtho(double distance, bool offset=false);
void gimbalCamPaintGL();
- void setVectorCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center);
void setupVectorCamPerspective();
void setupVectorCamOrtho(bool offset=false);
void vectorCamPaintGL();
- void setCamera( Camera &cam );
-
void showCrosshairs();
void showAxes();
void showSmallaxes();
diff --git a/src/export_png.cc b/src/export_png.cc
index 8a6dd1d..bedc230 100644
--- a/src/export_png.cc
+++ b/src/export_png.cc
@@ -35,13 +35,13 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &cam, std::ostream
bbox = cgalRenderer.polyset->getBoundingBox();
}
- if (cam.type() == Camera::NONE) {
+ if (cam.type == Camera::NONE) {
VectorCamera vcam;
vcam.center = getBoundingCenter(bbox);
double radius = getBoundingRadius(bbox);
Vector3d cameradir(1, 1, -0.5);
vcam.eye = vcam.center - radius*2*cameradir;
- cam.value = vcam;
+ cam.set(vcam);
}
//std::cerr << center << "\n";
@@ -78,7 +78,7 @@ void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output)
OpenCSGRenderer opencsgRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain, csgInfo.glview->shaderinfo);
- if (cam.type() == Camera::NONE) {
+ if (cam.type == Camera::NONE) {
VectorCamera vcam;
vcam.center << 0,0,0;
double radius = 1.0;
@@ -89,7 +89,7 @@ void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output)
}
Vector3d cameradir(1, 1, -0.5);
vcam.eye = vcam.center - radius*1.8*cameradir;
- cam.value = vcam;
+ cam.set(vcam);
}
csgInfo.glview->setCamera( cam );
diff --git a/src/openscad.cc b/src/openscad.cc
index 92ddcb7..5c8fe31 100644
--- a/src/openscad.cc
+++ b/src/openscad.cc
@@ -98,6 +98,43 @@ using std::vector;
using boost::lexical_cast;
using boost::is_any_of;
+Camera determine_camera( po::variables_map vm )
+{
+ Camera camera;
+
+ if (vm.count("gimbalcam")) {
+ std::cout << "x:" << vm["gimbalcam"].as<string>().c_str() << "\n";
+ vector<string> strs;
+ vector<double> cam_parameters;
+ split(strs, vm["gimbalcam"].as<string>(), is_any_of(","));
+ if ( strs.size() != 7 ) {
+ fprintf(stderr,"Need 7 numbers for gimbalcam\n");
+ } else {
+ BOOST_FOREACH(string &s, strs)
+ cam_parameters.push_back(lexical_cast<double>(s));
+ GimbalCamera gcam( cam_parameters );
+ camera.set( gcam );
+ }
+ }
+
+ if (vm.count("vectorcam")) {
+ std::cout << "x:" << vm["vectorcam"].as<string>().c_str() << "\n";
+ vector<string> strs;
+ vector<double> cam_parameters;
+ split(strs, vm["vectorcam"].as<string>(), is_any_of(","));
+ if ( strs.size() != 6 ) {
+ fprintf(stderr,"Need 6 numbers for vectorcam\n");
+ } else {
+ BOOST_FOREACH(string &s, strs)
+ cam_parameters.push_back(lexical_cast<double>(s));
+ VectorCamera vcam( cam_parameters );
+ camera.set( vcam );
+ }
+ }
+
+ return camera;
+}
+
int main(int argc, char **argv)
{
int rc = 0;
@@ -134,8 +171,6 @@ int main(int argc, char **argv)
const char *filename = NULL;
const char *output_file = NULL;
const char *deps_output_file = NULL;
- Camera camera;
- camera.value = NullCamera();
po::options_description desc("Allowed options");
desc.add_options()
@@ -217,20 +252,7 @@ int main(int argc, char **argv)
currentdir = boosty::stringy(fs::current_path());
- if (vm.count("gimbalcam")) {
- std::cout << "x:" << vm["gimbalcam"].as<string>().c_str() << "\n";
- vector<string> strs;
- vector<double> nums;
- split(strs, vm["gimbalcam"].as<string>(), is_any_of(","));
- if ( strs.size() != 7 ) {
- fprintf(stderr,"Need 7 numbers for gimbalcam\n");
- } else {
- BOOST_FOREACH(string &s, strs) nums.push_back(lexical_cast<double>(s));
- GimbalCamera gcam;
- gcam.setup( nums );
- camera.value = gcam;
- }
- }
+ Camera camera = determine_camera( vm );
QDir exdir(QApplication::instance()->applicationDirPath());
#ifdef Q_WS_MAC
contact: Jan Huwald // Impressum