soc-2008-mxcurioni: first version of lib3ds code. It does NOT work yet and has to...
[blender.git] / source / blender / freestyle / intern / scene_graph / NodeCamera.h
1 //
2 //  Filename         : NodeCamera.h
3 //  Author(s)        : Stephane Grabli
4 //  Purpose          : Class to represent a light node
5 //  Date of creation : 25/01/2002
6 //
7 ///////////////////////////////////////////////////////////////////////////////
8
9
10 //
11 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
12 //   with this source distribution. 
13 //
14 //  This program is free software; you can redistribute it and/or
15 //  modify it under the terms of the GNU General Public License
16 //  as published by the Free Software Foundation; either version 2
17 //  of the License, or (at your option) any later version.
18 //
19 //  This program is distributed in the hope that it will be useful,
20 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //  GNU General Public License for more details.
23 //
24 //  You should have received a copy of the GNU General Public License
25 //  along with this program; if not, write to the Free Software
26 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 //
28 ///////////////////////////////////////////////////////////////////////////////
29
30
31 #ifndef NODE_CAMERA_H_
32 #define NODE_CAMERA_H_
33
34 # include "../geometry/Geom.h"
35 # include "../system/FreestyleConfig.h"
36 # include "Node.h"
37
38 using namespace Geometry;
39
40 class NodeOrthographicCamera;
41 class NodePerspectiveCamera;
42 class LIB_SCENE_GRAPH_EXPORT NodeCamera : public Node
43 {
44 public:
45     typedef enum {PERSPECTIVE,ORTHOGRAPHIC,GENERIC} CameraType;
46
47     /*! Default matrices: Identity for both projection and modelview. */
48     NodeCamera(CameraType camera_type = GENERIC); 
49     NodeCamera(const NodeCamera& iBrother);
50
51     virtual ~NodeCamera() {}
52
53     /*! Accept the corresponding visitor */
54     virtual void accept(SceneVisitor& v);
55
56     /*! Matrix is copied */
57     void setModelViewMatrix(double modelview_matrix[16]);
58     /*! Matrix is copied */
59     void setProjectionMatrix(double projection_matrix[16]);
60
61     double * modelViewMatrix() {return modelview_matrix_;}
62     double * projectionMatrix() {return projection_matrix_;}
63
64 protected:
65     // row major right handed matrix
66     double modelview_matrix_[16];
67     // row major right handed matrix
68     double projection_matrix_[16];
69
70     CameraType camera_type_;
71 };
72
73 class LIB_SCENE_GRAPH_EXPORT NodeOrthographicCamera : public NodeCamera{
74 public:
75     NodeOrthographicCamera();
76     /*! Builds a parallel projection matrix a la glOrtho.
77     A   0       0       tx
78     0   B       0       ty
79     0   0       C       tz
80     0   0       0       1
81
82     where
83
84     A =
85     2 / (right - left) 
86     B =
87     2 / (top - bottom) 
88     C =
89     -2 / (far - near) 
90     tx =
91     -(right + left) / (right - left) 
92     ty =
93     -(top + bottom) / (top - bottom) 
94     tz =
95     -(zFar + zNear) / (zFar - zNear) 
96     */
97     NodeOrthographicCamera(double left
98         , double right
99         , double bottom
100         , double top
101         , double zNear
102         , double zFar
103         );
104
105     double left() const {return left_;}
106     double right() const {return right_;}
107     double bottom() const {return bottom_;}
108     double top() const {return top_;}
109     double zNear() const {return zNear_;}
110     double zFar() const {return zFar_;}
111
112     NodeOrthographicCamera(const NodeOrthographicCamera& iBrother);
113
114 private:
115     double left_;
116     double right_;
117     double bottom_;
118     double top_;
119     double zNear_;
120     double zFar_;
121 };
122
123 class LIB_SCENE_GRAPH_EXPORT NodePerspectiveCamera : public NodeCamera {
124 public:
125     NodePerspectiveCamera();
126     /*! Builds a perspective projection matrix a la gluPerspective. 
127     Given       f defined as follows:
128     fovy
129     f   = cotangent(____)
130     2
131     The generated       matrix is
132
133
134     (    f                                                                  )
135     |  ______                                                                   |
136     |  aspect           0                   0                   0               |
137     |                                                                               |
138     |   0               f                   0                   0               |
139     |                                                                               |
140     |                                               zNear+zFar       2*zNear*zFar   |
141     |                                   __________      ____________    |
142     |   0               0               zNear-zFar       zNear-zFar     |
143     |                                                                               |
144     (   0               0                   -1                  0           )
145     \param fovy
146     Field of View specified in radians.
147     */
148     NodePerspectiveCamera(double fovy
149         , double aspect
150         , double zNear
151         , double zFar);
152
153     /*! Builds a perspective projection matrix a la glFrustum.
154     (   2*zNear                                                         )
155     |  __________                                                                   |
156     |  right-left           0               A               0           |
157     |                                                                   |
158     |                            2*zNear                                                |
159     |     0                 __________          B               0           |
160     |                       top-bottom                                          |
161     |                                                                   |
162     |     0                     0               C               D           |
163     |                                                                                   |
164     |     0                     0               -1              0           |
165     (                                                                                   )
166
167     right+left
168     A = __________
169     right-left
170
171     top+bottom
172     B = __________
173     top-bottom
174
175     zFar+zNear
176     C = - __________
177     zFar-zNear
178
179     2*zFar*zNear
180     D = -  ____________
181     zFar-zNear
182     */
183     NodePerspectiveCamera(double left,
184         double right,
185         double bottom,
186         double top,
187         double zNear,
188         double zFar);
189 };
190
191
192 #endif // NODE_CAMERA_H_