summaryrefslogtreecommitdiff
path: root/src/Camera.h
blob: 87b5e83a13d17064700f94f1d4ae854827249a6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef OPENSCAD_CAMERA_H_
#define OPENSCAD_CAMERA_H_

/*

Camera

For usage, see *View.cc / export_png.cc / openscad.cc

There are two different types of cameras represented in this class:

*Gimbal camera - uses Euler Angles, object translation, and viewer distance
*Vector camera - uses 'eye', 'center', and 'up' vectors ('lookat' style)

There are two modes of projection, Perspective and Orthogonal.

*/

#include <vector>
#include <Eigen/Geometry>

class Camera
{
public:
	enum CameraType { NONE, GIMBAL, VECTOR } type;
	enum ProjectionType { ORTHOGONAL, PERSPECTIVE } projection;
	Camera() {
		type = Camera::NONE;
		projection = Camera::PERSPECTIVE;
	}
	Camera( enum CameraType e )
	{
		type = e;
		if ( e == Camera::GIMBAL ) {
			object_trans << 0,0,0;
			object_rot << 35,0,25;
			viewer_distance = 500;
		} else if ( e == Camera::VECTOR ) {
			center << 0,0,0;
			Eigen::Vector3d cameradir(1, 1, -0.5);
			eye = center - 500 * cameradir;
		}
		pixel_width = 512;
		pixel_height = 512;
		projection = Camera::PERSPECTIVE;
	}

	void setup( std::vector<double> params ) {
		if ( params.size() == 7 ) {
			type = Camera::GIMBAL;
			object_trans << params[0], params[1], params[2];
			object_rot << params[3], params[4], params[5];
			viewer_distance = params[6];
		} else if ( params.size() == 6 ) {
			type = Camera::VECTOR;
			eye << params[0], params[1], params[2];
			center << params[3], params[4], params[5];
		} else {
			assert( "Gimbal cam needs 7 numbers, Vector camera needs 6" );
		}
	}

	// Vectorcam
	Eigen::Vector3d eye;
	Eigen::Vector3d center; // (aka 'target')
	Eigen::Vector3d up;

	// Gimbalcam
	Eigen::Vector3d object_trans;
	Eigen::Vector3d object_rot;
	double viewer_distance;

	unsigned int pixel_width;
	unsigned int pixel_height;
};


#endif
contact: Jan Huwald // Impressum