1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | Based on the FS Import classes:
|
---|
7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
10 | */
|
---|
11 |
|
---|
12 | /**
|
---|
13 | @file FCDCamera.h
|
---|
14 | This file contains the FCDCamera class.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef _FCD_CAMERA_H_
|
---|
18 | #define _FCD_CAMERA_H_
|
---|
19 |
|
---|
20 | #include "FCDocument/FCDTargetedEntity.h"
|
---|
21 |
|
---|
22 | class FCDocument;
|
---|
23 | class FCDSceneNode;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | A COLLADA camera.
|
---|
27 | Based on the FCDTargetedEntity class to support aimed cameras.
|
---|
28 | COLLADA defines two types of cameras: perspective and orthographic.
|
---|
29 | Both types are fully handled by this class.
|
---|
30 |
|
---|
31 | A COLLADA perspective camera defines two of the three following parameters: horizontal field of view,
|
---|
32 | vertical field of view and aspect ratio. The missing parameter can be calculated using the following formulae:
|
---|
33 | aspect ratio = vertical field of view / horizontal field of view. The vertical and horizontal field
|
---|
34 | of view are in degrees.
|
---|
35 |
|
---|
36 | A COLLADA orthographic camera defines two of the three following parameters: horizontal magnification,
|
---|
37 | vertical magnification and aspect ratio. The missing parameter can be calculated using the following formulae:
|
---|
38 | aspect ratio = vertical magnification / horizontal magnification. You can calculate the viewport width
|
---|
39 | and height using the following formulas: viewport width = horizontal magnification * 2, viewport height
|
---|
40 | = vertical magnification * 2.
|
---|
41 |
|
---|
42 | @ingroup FCDocument
|
---|
43 | */
|
---|
44 | class FCOLLADA_EXPORT FCDCamera : public FCDTargetedEntity
|
---|
45 | {
|
---|
46 | private:
|
---|
47 | DeclareObjectType;
|
---|
48 |
|
---|
49 | // Camera flags
|
---|
50 | bool isPerspective;
|
---|
51 | bool isOrthographic;
|
---|
52 | bool hasHorizontalView;
|
---|
53 | bool hasVerticalView;
|
---|
54 |
|
---|
55 | // Camera parameters
|
---|
56 | float viewY;
|
---|
57 | float viewX;
|
---|
58 | float nearZ;
|
---|
59 | float farZ;
|
---|
60 | float aspectRatio;
|
---|
61 |
|
---|
62 | // Maya parameters
|
---|
63 | bool hasAperture;
|
---|
64 | float verticalAperture;
|
---|
65 | float horizontalAperture;
|
---|
66 | float lensSqueeze;
|
---|
67 |
|
---|
68 | public:
|
---|
69 | /** Constructor: do not use directly. Create new cameras using the FCDLibrary::AddEntity function.
|
---|
70 | @param document The COLLADA document that contains this camera entity.*/
|
---|
71 | FCDCamera(FCDocument* document);
|
---|
72 |
|
---|
73 | /** Destructor: do not release directly. Release cameras using the FCDLibrary::ReleaseEntity function.
|
---|
74 | All cameras are released with the document that they belong to. */
|
---|
75 | virtual ~FCDCamera();
|
---|
76 |
|
---|
77 | /** Retrieves the entity type for this class. This function is part of the FCDEntity interface.
|
---|
78 | @return The entity type: CAMERA. */
|
---|
79 | virtual Type GetType() const { return CAMERA; }
|
---|
80 |
|
---|
81 | /** Retrieves whether this camera is a perspective camera.
|
---|
82 | This is the default type of camera.
|
---|
83 | @return Whether this camera is a perspective camera.*/
|
---|
84 | inline bool IsPerspective() const { return isPerspective; }
|
---|
85 |
|
---|
86 | /** Sets the type of this camera to perspective. */
|
---|
87 | inline void SetPerspective() { isPerspective = true; isOrthographic = false; }
|
---|
88 |
|
---|
89 | /** Retrieves whether the perspective camera defines an horizontal field of view.
|
---|
90 | If the camera does not define the horizontal field of view, you can calculate
|
---|
91 | it using the following formula: horizontal field of view = vertical field of view / aspect ratio.
|
---|
92 | @return Whether the perspective camera defines an horizontal field of view. */
|
---|
93 | inline bool HasHorizontalFov() const { return hasHorizontalView; }
|
---|
94 |
|
---|
95 | /** Retrieves whether the perspective camera defines a vertical field of view.
|
---|
96 | If the camera does not define the vertical field of view, you can calculate
|
---|
97 | it using the following formula: vertical field of view = aspect ratio * horizontal field of view.
|
---|
98 | @return Whether the perspective camera defines a vertical field of view. */
|
---|
99 | inline bool HasVerticalFov() const { return hasVerticalView; }
|
---|
100 |
|
---|
101 | /** Retrieves the horizontal field of view. Before retrieving this value,
|
---|
102 | check whether the camera defines the horizontal field of view using the
|
---|
103 | HasHorizontalFov function.
|
---|
104 | @return The horizontal field of view, in degrees. */
|
---|
105 | inline float& GetFovX() { return viewX; }
|
---|
106 | inline const float& GetFovX() const { return viewX; } /**< See above. */
|
---|
107 |
|
---|
108 | /** Retrieves the vertical field of view. Before retrieving this value,
|
---|
109 | check whether the camera defines the vertical field of view using the
|
---|
110 | HasVerticalFov function.
|
---|
111 | @return The horizontal field of view, in degrees. */
|
---|
112 | inline float& GetFovY() { return viewY; }
|
---|
113 | inline const float& GetFovY() const { return viewY; } /**< See above. */
|
---|
114 |
|
---|
115 | /** Sets the horizontal field of view value for this camera.
|
---|
116 | @param fovX The new horizontal field of view, in degrees. */
|
---|
117 | void SetFovX(float fovX);
|
---|
118 |
|
---|
119 | /** Sets the vertical field of view value for this camera.
|
---|
120 | @param fovY The new vertical field of view, in degrees. */
|
---|
121 | void SetFovY(float fovY);
|
---|
122 |
|
---|
123 | /** Retrieves whether this camera is an orthographic camera.
|
---|
124 | @return Whether this camera is an orthographic camera. */
|
---|
125 | inline bool IsOrthographic() const { return isOrthographic; }
|
---|
126 |
|
---|
127 | /** Sets the type of this camera to orthographic. */
|
---|
128 | inline void SetOrthographic() { isPerspective = false; isOrthographic = true; }
|
---|
129 |
|
---|
130 | /** Retrieves whether the orthographic camera defines an horizontal magnification.
|
---|
131 | If the camera does not define the horizontal magnification, you can calculate
|
---|
132 | it using the following formula: horizontal magnification = vertical magnification / aspect ratio.
|
---|
133 | @return Whether the orthographic camera defines an horizontal magnification. */
|
---|
134 | inline bool HasHorizontalMag() const { return hasHorizontalView; }
|
---|
135 |
|
---|
136 | /** Retrieves whether the perspective camera defines a vertical magnification.
|
---|
137 | If the camera does not define the vertical magnification, you can calculate
|
---|
138 | it using the following formula: vertical magnification = aspect ratio * horizontal magnification.
|
---|
139 | @return Whether the perspective camera defines a vertical magnification. */
|
---|
140 | inline bool HasVerticalMag() const { return hasVerticalView; }
|
---|
141 |
|
---|
142 | /** Retrieves the horizontal magnification. Before retrieving this value,
|
---|
143 | check whether the camera defines the horizontal magnification using the
|
---|
144 | HasHorizontalMag function.
|
---|
145 | @return The horizontal magnification. */
|
---|
146 | inline float& GetMagX() { return viewX; }
|
---|
147 | inline const float& GetMagX() const { return viewX; } /**< See above. */
|
---|
148 |
|
---|
149 | /** Retrieves the vertical magnification. Before retrieving this value,
|
---|
150 | check whether the camera defines the vertical magnification using the
|
---|
151 | HasVerticalMag function.
|
---|
152 | @return The vertical magnification. */
|
---|
153 | inline float& GetMagY() { return viewY; }
|
---|
154 | inline const float& GetMagY() const { return viewY; } /**< See above. */
|
---|
155 |
|
---|
156 | /** Sets the horizontal magnification for this camera.
|
---|
157 | @param magX The new horizontal magnification, in degrees. */
|
---|
158 | inline void SetMagX(float magX) { return SetFovX(magX); }
|
---|
159 |
|
---|
160 | /** Sets the vertical magnification value for this camera.
|
---|
161 | @param magY The new vertical magnification, in degrees. */
|
---|
162 | inline void SetMagY(float magY) { return SetFovY(magY); }
|
---|
163 |
|
---|
164 | /** Retrieves the near-z value for this camera.
|
---|
165 | The near-z value represent how close the near-clip
|
---|
166 | plane of the view frustrum is. For orthographic cameras,
|
---|
167 | this value is solely used for depth-buffering.
|
---|
168 | @return The near-z value for this camera. */
|
---|
169 | inline float& GetNearZ() { return nearZ; }
|
---|
170 | inline const float& GetNearZ() const { return nearZ; } /**< See above. */
|
---|
171 |
|
---|
172 | /** Retrieves the far-z value for this camera. The far-z value represent
|
---|
173 | how close the far-clip plane of the view frustrum is.
|
---|
174 | For orthographic cameras, this value is solely used for depth-buffering.
|
---|
175 | @return The far-z value for this camera. */
|
---|
176 | inline float& GetFarZ() { return farZ; }
|
---|
177 | inline const float& GetFarZ() const { return farZ; } /**< See above. */
|
---|
178 |
|
---|
179 | /** Retrieves the aspect ratio for the view of this camera. Before using this value,
|
---|
180 | check if there are only one of the horizontal and vertical view ratios.
|
---|
181 | If there are both of the view ratios provided for the camera, you will
|
---|
182 | need to calculate the aspect ratio using the following formula:
|
---|
183 | aspect ratio = vertical field of view / horizontal field of view.
|
---|
184 | @return The view aspect ratio. */
|
---|
185 | inline float& GetAspectRatio() { return aspectRatio; }
|
---|
186 | inline const float& GetAspectRatio() const { return aspectRatio; } /**< See above. */
|
---|
187 |
|
---|
188 | /** Sets the near-z value for this camera.
|
---|
189 | The near-z value represent how close the near-clip
|
---|
190 | plane of the view frustrum is. For orthographic cameras,
|
---|
191 | this value is solely used for depth-buffering.
|
---|
192 | @param _nearZ A valid near-z value. No check is made to verify that the
|
---|
193 | near-z value is greather than the far-z value.*/
|
---|
194 | inline void SetNearZ(float _nearZ) { nearZ = _nearZ; }
|
---|
195 |
|
---|
196 | /** Sets the far-z value for this camera. The far-z value represent
|
---|
197 | how close the far-clip plane of the view frustrum is.
|
---|
198 | For orthographic cameras, this value is solely used for depth-buffering.
|
---|
199 | @param _farZ A valid far-z value. No check is made to verify that the
|
---|
200 | far-z value is greather than the near-z value.*/
|
---|
201 | inline void SetFarZ(float _farZ) { farZ = _farZ; }
|
---|
202 |
|
---|
203 | /** Sets the aspect ratio for the view of this camera.
|
---|
204 | @param aspectRatio The new view aspect ratio. */
|
---|
205 | void SetAspectRatio(float aspectRatio);
|
---|
206 |
|
---|
207 | /** Retrieves whether the camera provides aperture information. This information is specific
|
---|
208 | to COLLADA documents exported from ColladaMaya.
|
---|
209 | @return Whether the camera provides aperture information. */
|
---|
210 | inline bool HasAperture() const { return hasAperture; }
|
---|
211 |
|
---|
212 | /** Retrieves the vertical aperture of the camera. This information is specific to
|
---|
213 | COLLADA documents exported from ColladaMaya.
|
---|
214 | @return The vertical aperture of the camera. */
|
---|
215 | inline float& GetVerticalAperture() { return verticalAperture; }
|
---|
216 | inline const float& GetVerticalAperture() const { return verticalAperture; } /**< See above. */
|
---|
217 |
|
---|
218 | /** Retrieves the horizontal aperture of the camera. This information is specific to
|
---|
219 | COLLADA documents exported from ColladaMaya.
|
---|
220 | @return The horizontal aperture of the camera. */
|
---|
221 | inline float& GetHorizontalAperture() { return horizontalAperture; }
|
---|
222 | inline const float& GetHorizontalAperture() const { return horizontalAperture; } /**< See above. */
|
---|
223 |
|
---|
224 | /** Retrieves the lens squeeze of the camera. This information is specific to
|
---|
225 | COLLADA documents exported from ColladaMaya. The lens squeeze of the camera
|
---|
226 | is a multiplier that acts directly on the horizontal aperture, following this
|
---|
227 | formula: real horizontal aperture = given horizontal aperture * lens squeeze.
|
---|
228 | @return The lens squeeze of the camera. */
|
---|
229 | inline float& GetLensSqueeze() { return lensSqueeze; }
|
---|
230 | inline const float& GetLensSqueeze() const { return lensSqueeze; } /**< See above. */
|
---|
231 |
|
---|
232 | /** Sets the vertical aperture of the camera.
|
---|
233 | @param aperture The vertical aperture of the camera. */
|
---|
234 | inline void SetVerticalAperture(float aperture) { verticalAperture = aperture; hasAperture = true; }
|
---|
235 |
|
---|
236 | /** Sets the horizontal aperture of the camera.
|
---|
237 | @param aperture The horizontal aperture of the camera. */
|
---|
238 | inline void SetHorizontalAperture(float aperture) { horizontalAperture = aperture; hasAperture = true; }
|
---|
239 |
|
---|
240 | /** Sets the lens squeeze of the camera.
|
---|
241 | @param factor The lense squeeze of the camera. */
|
---|
242 | inline void SetLensSqueeze(float factor) { lensSqueeze = factor; }
|
---|
243 |
|
---|
244 | /** [INTERNAL] Reads in the \<camera\> element from a given COLLADA XML tree node.
|
---|
245 | @param cameraNode A COLLADA XML tree node.
|
---|
246 | @return The status of the import. If the status is not successful,
|
---|
247 | it may be dangerous to extract information from the camera.*/
|
---|
248 | FUStatus LoadFromXML(xmlNode* cameraNode);
|
---|
249 |
|
---|
250 | /** [INTERNAL] Writes out the \<camera\> element to the given COLLADA XML tree node.
|
---|
251 | @param parentNode The COLLADA XML parent node in which to insert the geometry information.
|
---|
252 | @return The created XML tree node. */
|
---|
253 | virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
254 | };
|
---|
255 |
|
---|
256 | #endif // _FCD_CAMERA_H_
|
---|
257 |
|
---|