~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/cameras.h

  • Committer: Bazaar Package Importer
  • Author(s): D Haley, Sylvestre Ledru
  • Date: 2011-04-12 17:44:06 UTC
  • mfrom: (1.2.1 upstream) (3.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110412174406-zz06iu3xmardt43s
Tags: 0.0.5-1
[ Sylvestre Ledru ]
* watch file added
* Switch to dpkg-source 3.0 (quilt) format

* New upstream version 

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
enum CAM_ENUM
30
30
{
31
31
        CAM_FREE=1,
32
 
        CAM_PERSP,
33
32
        CAM_LOOKAT,
34
33
};
35
34
 
 
35
enum 
 
36
{
 
37
        PROJECTION_MODE_PERSPECTIVE,
 
38
        PROJECTION_MODE_ORTHOGONAL,
 
39
        PROJECTION_MODE_ENUM_END //not a valid mode.
 
40
};
 
41
 
36
42
class CameraProperties 
37
43
{
38
44
        public:
56
62
                Point3D viewDirection;
57
63
                //!Up direction for camera (required to work out "roll")
58
64
                Point3D upDirection;
 
65
 
 
66
                //!Projection mode (otho, perspective...)_
 
67
                unsigned int projectionMode;
 
68
 
 
69
                //!The current orthographic scaling
 
70
                float orthoScale;
 
71
 
59
72
                //!Type number
60
73
                unsigned int typeNum;
61
74
                //!user string, e.g. camera name
66
79
                //!Destructor
67
80
                virtual ~Camera();
68
81
                //!Duplication routine. Must delete returned pointer manually. 
69
 
                /*!Base implementation OK for non-pointer containing objects. Otherwise define (1) copy constructor or (2) overload
70
 
                 */
71
82
                virtual Camera *clone() const=0;
72
83
 
73
84
                //!Streaming output operator, presents human readable text
80
91
                //!Return the up direction for the camera
81
92
                Point3D getUpDirection() const;
82
93
 
 
94
                //!return the projection mode
 
95
                unsigned int getProjectionMode() const{ return projectionMode;};
 
96
                
83
97
                //!Set the camera's position
84
98
                virtual void setOrigin(const Point3D &);
85
99
                //!set the direction that the camera looks towards
92
106
                //!Get the user string
93
107
                std::string getUserString() const { return userString;};
94
108
 
95
 
                //!Do a forwards "dolly",where the camera moves along its viewing axis
 
109
                //!Do a forwards "dolly",where the camera moves along its viewing axis. In ortho mode, instead of moving along axis, a scaling is performed
96
110
                virtual void forwardsDolly(float dollyAmount);
97
111
 
98
112
                //!Move the camera origin
134
148
 
135
149
};
136
150
 
137
 
//!Orthognal transformation camera
138
 
class CameraOrthogonal : public Camera
139
 
{
140
 
        public:
141
 
                CameraOrthogonal() {typeNum=CAM_FREE;};
142
 
                ~CameraOrthogonal() {};
143
 
                //!clone function
144
 
                Camera *clone() const;  
145
 
                //!Applies the camera settings to openGL, ensuring cube is not clipped by far plane 
146
 
                virtual void apply(float outputRatio,const BoundCube &b,bool loadIdentity=true) const {}; 
147
 
                //!Applies the camera settings to openGL, restricting the viewport (range (-1, 1))
148
 
                virtual void apply(float outputRatio,const BoundCube &b,bool loadIdentity,
149
 
                                                float leftRestrict,float rightRestrict, 
150
 
                                                float bottomRestrict, float topRestrict) const {ASSERT(false);};
151
 
 
152
 
                //!Return the user-settable properties of the camera
153
 
                void getProperties(CameraProperties &p) const;
154
 
                
155
 
                //!Write the state of the camera
156
 
                virtual bool writeState(std::ostream &f, unsigned int format, unsigned int tabs=0) const;
157
 
                //!Read the state of the camera
158
 
                virtual bool readState(xmlNodePtr nodePtr);
159
 
};
160
 
 
161
 
//!A class for a perspective "point and view" camera
162
 
/*!Class employes a standard viewing frustrum method
163
 
 * using glFrustrum
164
 
 */
165
 
class CameraPerspective : public Camera
 
151
//!A perspective camera that looks at a specific location
 
152
class CameraLookAt : public Camera
166
153
{
167
154
        protected:
 
155
                //!Location for camera to look at
 
156
                Point3D target;
 
157
                
 
158
                void recomputeViewDirection();
 
159
                
168
160
                //!Perspective FOV
169
161
                float fovAngle;
170
162
 
173
165
                //!Far plane is computed on-the-fly. cannot be set directly. Oh no! mutable. gross!
174
166
                mutable float farPlane;
175
167
 
 
168
                //!Distort to the viewing frustum. (eg for stero) ( a frustum is a rectangular pyramid with the top cut off)
 
169
                float frustumDistortion;
 
170
 
176
171
                //!Do the perspective calculations
177
172
                void doPerspCalcs(float aspect,const BoundCube &bc,bool loadIdentity) const;
178
173
        
179
 
                //Version with top left control. left and top are in world coordinates.
180
 
                void doPerspCalcs(float aspect,const BoundCube &bc,
181
 
                                bool loadIdentity,float left, float top) const;
182
 
                
183
 
        public:
184
 
                //!Constructor
185
 
                CameraPerspective();
186
 
                //!Destructor
187
 
                virtual ~CameraPerspective();
188
 
                //!clone function
189
 
                Camera *clone() const;  
190
 
 
191
 
                //!Streaming output operator, presents human readable text
192
 
                friend std::ostream &operator<<(std::ostream &stream, const CameraPerspective &);
193
 
                //!Applies the camera transforms to world
194
 
                void apply(float outAspect, const BoundCube &boundCube,bool loadIdentity=true) const;
195
 
                
196
 
                //!Set the camera's near clipping plane
197
 
                void setNearPlane(float f) {nearPlane = f;}
198
 
 
199
 
                //!Set the camera's FOV angle. 
200
 
                inline void setFOV(float newFov) { ASSERT(newFov >0.0 && newFov<180.0); fovAngle =newFov;}
201
 
 
202
 
                //!get the camera's near clipping plane
203
 
                inline float getNearPlane() const {return nearPlane;}
204
 
                
205
 
                //!get the camera's near clipping plane
206
 
                inline float getFarPlane() const {return farPlane;}
207
 
 
208
 
                //!Get the camera's FOV angle (full angle across)
209
 
                inline float getFOV() const {return fovAngle;}
210
 
                
211
 
                //!Ensure that the box is visible
212
 
                /*! Face is set by cube net
213
 
                                        1
214
 
                                    2   3   4
215
 
                                        5
216
 
                                        6
217
 
                3 is the face directed to the +ve x axis,
218
 
                with the "up"" vector on the 3 aligned to z,
219
 
                so "1" is perpendicular to the Z axis and is "visible"
220
 
                 */
221
 
                virtual void ensureVisible(const BoundCube &b, unsigned int face=3);
222
 
 
223
 
                //!Return the user-settable properties of the camera
224
 
                void getProperties(CameraProperties &p) const;
225
 
                
226
 
                //!Set the camera property from a key & string pair
227
 
                bool setProperty(unsigned int key, const std::string &value);
228
 
                
229
 
                //!Ensure that up direction is perpendicular to view direction
230
 
                void recomputeUpDirection();
231
 
                
232
 
                //!Write the state of the camera
233
 
                bool writeState(std::ostream &f, unsigned int format, unsigned int tabs=0) const;
234
 
                //!Read the state of the camera
235
 
                bool readState(xmlNodePtr nodePtr) ;
236
 
        
237
 
                //!Apply, restricting viewport to subresgion    
238
 
                virtual void apply(float outputRatio,const BoundCube &b,bool loadIdentity,
239
 
                                                float leftRestrict,float rightRestrict, 
240
 
                                                float bottomRestrict, float topRestrict) const {ASSERT(false);};
241
 
};
242
 
 
243
 
//!A perspective camera that looks at a specific location
244
 
class CameraPerspLookAt : public CameraPerspective
245
 
{
246
 
        protected:
247
 
                //!Location for camera to look at
248
 
                Point3D target;
249
 
                
250
 
                void recomputeViewDirection();
251
 
        public:
252
 
                //!Constructor
253
 
                CameraPerspLookAt();
254
 
 
255
 
                //!Streaming output operator, presents human readable text
256
 
                friend std::ostream &operator<<(std::ostream &stream, const CameraPerspLookAt &);
257
 
                //!clone function
258
 
                Camera *clone() const;  
259
 
                //!Destructor
260
 
                virtual ~CameraPerspLookAt();
 
174
        public:
 
175
                //!Constructor
 
176
                CameraLookAt();
 
177
 
 
178
                //!Streaming output operator, presents human readable text
 
179
                friend std::ostream &operator<<(std::ostream &stream, const CameraLookAt &);
 
180
                //!clone function
 
181
                Camera *clone() const;  
 
182
                //!Destructor
 
183
                virtual ~CameraLookAt();
261
184
                //!Set the look at target
262
185
                void setOrigin(const Point3D &);
263
186
                //!Set the look at target
264
187
                void setTarget(const Point3D &);
265
188
                //!Get the look at target
266
189
                Point3D getTarget() const;
 
190
                
 
191
                //!Get the camera's FOV angle (full angle across)
 
192
                float getFOV() const {return fovAngle;}
 
193
 
267
194
                //!Applies the view transform 
268
195
                void apply(float outAspect, const BoundCube &boundCube,bool loadIdentity=true) const;
269
196
                
279
206
 
280
207
                void translate(float lrTrans, float udTrans);
281
208
 
 
209
 
 
210
 
282
211
                //Clockwise roll looking from camera view by rollRad radians
283
212
                void roll(float rollRad);
284
213
                
285
 
                //TODO: Move to parent class? Maybe not?
 
214
                //!Ensure that up direction is perpendicular to view direction
 
215
                void recomputeUpDirection();
 
216
                
286
217
                //!Ensure that the box is visible
287
218
                /*! Face is set by cube net
288
219
                                        1
310
241
                virtual void apply(float outputRatio,const BoundCube &b,bool loadIdentity,
311
242
                                                float leftRestrict,float rightRestrict, 
312
243
                                                float topRestrict, float bottomRestrict) const;
313
 
};
314
 
 
315
 
/*Follows a list of points
316
 
 *
317
 
 * Class contains some elementary constructions
318
 
class CameraTrack
319
 
{
320
 
        private:
321
 
                Camera *cam;
322
 
                vector<Point3D> cameraTrackPts;
323
 
                //Optional track of target points
324
 
                vector<Point3D> targetTrackPts;
325
 
 
326
 
        public:
327
 
        
328
 
};
329
 
*/
 
244
 
 
245
                float getViewWidth(float depth) const;
 
246
 
 
247
                void setFrustumDistort(float offset){frustumDistortion=offset;};
 
248
 
 
249
};
 
250
 
330
251
#endif