1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org |
---|
6 | |
---|
7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
8 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | #ifndef __Camera_H__ |
---|
29 | #define __Camera_H__ |
---|
30 | |
---|
31 | // Default options |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | |
---|
34 | #include "OgreString.h" |
---|
35 | #include "OgreMovableObject.h" |
---|
36 | |
---|
37 | // Matrices & Vectors |
---|
38 | #include "OgreMatrix4.h" |
---|
39 | #include "OgreVector3.h" |
---|
40 | #include "OgrePlane.h" |
---|
41 | #include "OgreQuaternion.h" |
---|
42 | #include "OgreCommon.h" |
---|
43 | #include "OgreFrustum.h" |
---|
44 | #include "OgreRay.h" |
---|
45 | #include "OgrePlaneBoundedVolume.h" |
---|
46 | #include "OgreHeaderPrefix.h" |
---|
47 | |
---|
48 | |
---|
49 | namespace Ogre { |
---|
50 | |
---|
51 | /** \addtogroup Core |
---|
52 | * @{ |
---|
53 | */ |
---|
54 | /** \addtogroup Scene |
---|
55 | * @{ |
---|
56 | */ |
---|
57 | |
---|
58 | /** A viewpoint from which the scene will be rendered. |
---|
59 | @remarks |
---|
60 | OGRE renders scenes from a camera viewpoint into a buffer of |
---|
61 | some sort, normally a window or a texture (a subclass of |
---|
62 | RenderTarget). OGRE cameras support both perspective projection (the default, |
---|
63 | meaning objects get smaller the further away they are) and |
---|
64 | orthographic projection (blueprint-style, no decrease in size |
---|
65 | with distance). Each camera carries with it a style of rendering, |
---|
66 | e.g. full textured, flat shaded, wireframe), field of view, |
---|
67 | rendering distances etc, allowing you to use OGRE to create |
---|
68 | complex multi-window views if required. In addition, more than |
---|
69 | one camera can point at a single render target if required, |
---|
70 | each rendering to a subset of the target, allowing split screen |
---|
71 | and picture-in-picture views. |
---|
72 | @par |
---|
73 | Cameras maintain their own aspect ratios, field of view, and frustum, |
---|
74 | and project co-ordinates into a space measured from -1 to 1 in x and y, |
---|
75 | and 0 to 1 in z. At render time, the camera will be rendering to a |
---|
76 | Viewport which will translate these parametric co-ordinates into real screen |
---|
77 | co-ordinates. Obviously it is advisable that the viewport has the same |
---|
78 | aspect ratio as the camera to avoid distortion (unless you want it!). |
---|
79 | @par |
---|
80 | Note that a Camera can be attached to a SceneNode, using the method |
---|
81 | SceneNode::attachObject. If this is done the Camera will combine it's own |
---|
82 | position/orientation settings with it's parent SceneNode. |
---|
83 | This is useful for implementing more complex Camera / object |
---|
84 | relationships i.e. having a camera attached to a world object. |
---|
85 | */ |
---|
86 | class _OgreExport Camera : public Frustum |
---|
87 | { |
---|
88 | public: |
---|
89 | /** Listener interface so you can be notified of Camera events. |
---|
90 | */ |
---|
91 | class _OgreExport Listener |
---|
92 | { |
---|
93 | public: |
---|
94 | Listener() {} |
---|
95 | virtual ~Listener() {} |
---|
96 | |
---|
97 | /// Called prior to the scene being rendered with this camera |
---|
98 | virtual void cameraPreRenderScene(Camera* cam) |
---|
99 | { (void)cam; } |
---|
100 | |
---|
101 | /// Called after the scene has been rendered with this camera |
---|
102 | virtual void cameraPostRenderScene(Camera* cam) |
---|
103 | { (void)cam; } |
---|
104 | |
---|
105 | /// Called when the camera is being destroyed |
---|
106 | virtual void cameraDestroyed(Camera* cam) |
---|
107 | { (void)cam; } |
---|
108 | |
---|
109 | }; |
---|
110 | protected: |
---|
111 | /// Scene manager responsible for the scene |
---|
112 | SceneManager *mSceneMgr; |
---|
113 | |
---|
114 | /// Camera orientation, quaternion style |
---|
115 | Quaternion mOrientation; |
---|
116 | |
---|
117 | /// Camera position - default (0,0,0) |
---|
118 | Vector3 mPosition; |
---|
119 | |
---|
120 | /// Derived orientation/position of the camera, including reflection |
---|
121 | mutable Quaternion mDerivedOrientation; |
---|
122 | mutable Vector3 mDerivedPosition; |
---|
123 | |
---|
124 | /// Real world orientation/position of the camera |
---|
125 | mutable Quaternion mRealOrientation; |
---|
126 | mutable Vector3 mRealPosition; |
---|
127 | |
---|
128 | /// Whether to yaw around a fixed axis. |
---|
129 | bool mYawFixed; |
---|
130 | /// Fixed axis to yaw around |
---|
131 | Vector3 mYawFixedAxis; |
---|
132 | |
---|
133 | /// Rendering type |
---|
134 | PolygonMode mSceneDetail; |
---|
135 | |
---|
136 | /// Stored number of visible faces in the last render |
---|
137 | unsigned int mVisFacesLastRender; |
---|
138 | |
---|
139 | /// Stored number of visible batches in the last render |
---|
140 | unsigned int mVisBatchesLastRender; |
---|
141 | |
---|
142 | /// Shared class-level name for Movable type |
---|
143 | static String msMovableType; |
---|
144 | |
---|
145 | /// SceneNode which this Camera will automatically track |
---|
146 | SceneNode* mAutoTrackTarget; |
---|
147 | /// Tracking offset for fine tuning |
---|
148 | Vector3 mAutoTrackOffset; |
---|
149 | |
---|
150 | /// Scene LOD factor used to adjust overall LOD |
---|
151 | Real mSceneLodFactor; |
---|
152 | /// Inverted scene LOD factor, can be used by Renderables to adjust their LOD |
---|
153 | Real mSceneLodFactorInv; |
---|
154 | |
---|
155 | |
---|
156 | /** Viewing window. |
---|
157 | @remarks |
---|
158 | Generalize camera class for the case, when viewing frustum doesn't cover all viewport. |
---|
159 | */ |
---|
160 | Real mWLeft, mWTop, mWRight, mWBottom; |
---|
161 | /// Is viewing window used. |
---|
162 | bool mWindowSet; |
---|
163 | /// Windowed viewport clip planes |
---|
164 | mutable vector<Plane>::type mWindowClipPlanes; |
---|
165 | /// Was viewing window changed. |
---|
166 | mutable bool mRecalcWindow; |
---|
167 | /// The last viewport to be added using this camera |
---|
168 | Viewport* mLastViewport; |
---|
169 | /** Whether aspect ratio will automatically be recalculated |
---|
170 | when a viewport changes its size |
---|
171 | */ |
---|
172 | bool mAutoAspectRatio; |
---|
173 | /// Custom culling frustum |
---|
174 | Frustum *mCullFrustum; |
---|
175 | /// Whether or not the rendering distance of objects should take effect for this camera |
---|
176 | bool mUseRenderingDistance; |
---|
177 | /// Camera to use for LOD calculation |
---|
178 | const Camera* mLodCamera; |
---|
179 | |
---|
180 | /// Whether or not the minimum display size of objects should take effect for this camera |
---|
181 | bool mUseMinPixelSize; |
---|
182 | /// @see Camera::getPixelDisplayRatio |
---|
183 | Real mPixelDisplayRatio; |
---|
184 | |
---|
185 | typedef vector<Listener*>::type ListenerList; |
---|
186 | ListenerList mListeners; |
---|
187 | |
---|
188 | |
---|
189 | // Internal functions for calcs |
---|
190 | bool isViewOutOfDate(void) const; |
---|
191 | /// Signal to update frustum information. |
---|
192 | void invalidateFrustum(void) const; |
---|
193 | /// Signal to update view information. |
---|
194 | void invalidateView(void) const; |
---|
195 | |
---|
196 | |
---|
197 | /** Do actual window setting, using parameters set in SetWindow call |
---|
198 | @remarks |
---|
199 | The method will called on demand. |
---|
200 | */ |
---|
201 | virtual void setWindowImpl(void) const; |
---|
202 | |
---|
203 | /** Helper function for forwardIntersect that intersects rays with canonical plane */ |
---|
204 | virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const; |
---|
205 | |
---|
206 | public: |
---|
207 | /** Standard constructor. |
---|
208 | */ |
---|
209 | Camera( const String& name, SceneManager* sm); |
---|
210 | |
---|
211 | /** Standard destructor. |
---|
212 | */ |
---|
213 | virtual ~Camera(); |
---|
214 | |
---|
215 | /// Add a listener to this camera |
---|
216 | virtual void addListener(Listener* l); |
---|
217 | /// Remove a listener to this camera |
---|
218 | virtual void removeListener(Listener* l); |
---|
219 | |
---|
220 | /** Returns a pointer to the SceneManager this camera is rendering through. |
---|
221 | */ |
---|
222 | SceneManager* getSceneManager(void) const; |
---|
223 | |
---|
224 | /** Sets the level of rendering detail required from this camera. |
---|
225 | @remarks |
---|
226 | Each camera is set to render at full detail by default, that is |
---|
227 | with full texturing, lighting etc. This method lets you change |
---|
228 | that behaviour, allowing you to make the camera just render a |
---|
229 | wireframe view, for example. |
---|
230 | */ |
---|
231 | void setPolygonMode(PolygonMode sd); |
---|
232 | |
---|
233 | /** Retrieves the level of detail that the camera will render. |
---|
234 | */ |
---|
235 | PolygonMode getPolygonMode(void) const; |
---|
236 | |
---|
237 | /** Sets the camera's position. |
---|
238 | */ |
---|
239 | void setPosition(Real x, Real y, Real z); |
---|
240 | |
---|
241 | /** Sets the camera's position. |
---|
242 | */ |
---|
243 | void setPosition(const Vector3& vec); |
---|
244 | |
---|
245 | /** Retrieves the camera's position. |
---|
246 | */ |
---|
247 | const Vector3& getPosition(void) const; |
---|
248 | |
---|
249 | /** Moves the camera's position by the vector offset provided along world axes. |
---|
250 | */ |
---|
251 | void move(const Vector3& vec); |
---|
252 | |
---|
253 | /** Moves the camera's position by the vector offset provided along it's own axes (relative to orientation). |
---|
254 | */ |
---|
255 | void moveRelative(const Vector3& vec); |
---|
256 | |
---|
257 | /** Sets the camera's direction vector. |
---|
258 | @remarks |
---|
259 | Note that the 'up' vector for the camera will automatically be recalculated based on the |
---|
260 | current 'up' vector (i.e. the roll will remain the same). |
---|
261 | */ |
---|
262 | void setDirection(Real x, Real y, Real z); |
---|
263 | |
---|
264 | /** Sets the camera's direction vector. |
---|
265 | */ |
---|
266 | void setDirection(const Vector3& vec); |
---|
267 | |
---|
268 | /** Gets the camera's direction. |
---|
269 | */ |
---|
270 | Vector3 getDirection(void) const; |
---|
271 | |
---|
272 | /** Gets the camera's up vector. |
---|
273 | */ |
---|
274 | Vector3 getUp(void) const; |
---|
275 | |
---|
276 | /** Gets the camera's right vector. |
---|
277 | */ |
---|
278 | Vector3 getRight(void) const; |
---|
279 | |
---|
280 | /** Points the camera at a location in worldspace. |
---|
281 | @remarks |
---|
282 | This is a helper method to automatically generate the |
---|
283 | direction vector for the camera, based on it's current position |
---|
284 | and the supplied look-at point. |
---|
285 | @param |
---|
286 | targetPoint A vector specifying the look at point. |
---|
287 | */ |
---|
288 | void lookAt( const Vector3& targetPoint ); |
---|
289 | /** Points the camera at a location in worldspace. |
---|
290 | @remarks |
---|
291 | This is a helper method to automatically generate the |
---|
292 | direction vector for the camera, based on it's current position |
---|
293 | and the supplied look-at point. |
---|
294 | @param x |
---|
295 | The @c x co-ordinates of the point to look at. |
---|
296 | @param y |
---|
297 | The @c y co-ordinates of the point to look at. |
---|
298 | @param z |
---|
299 | The @c z co-ordinates of the point to look at. |
---|
300 | */ |
---|
301 | void lookAt(Real x, Real y, Real z); |
---|
302 | |
---|
303 | /** Rolls the camera anticlockwise, around its local z axis. |
---|
304 | */ |
---|
305 | void roll(const Radian& angle); |
---|
306 | |
---|
307 | /** Rotates the camera anticlockwise around it's local y axis. |
---|
308 | */ |
---|
309 | void yaw(const Radian& angle); |
---|
310 | |
---|
311 | /** Pitches the camera up/down anticlockwise around it's local z axis. |
---|
312 | */ |
---|
313 | void pitch(const Radian& angle); |
---|
314 | |
---|
315 | /** Rotate the camera around an arbitrary axis. |
---|
316 | */ |
---|
317 | void rotate(const Vector3& axis, const Radian& angle); |
---|
318 | |
---|
319 | /** Rotate the camera around an arbitrary axis using a Quaternion. |
---|
320 | */ |
---|
321 | void rotate(const Quaternion& q); |
---|
322 | |
---|
323 | /** Tells the camera whether to yaw around it's own local Y axis or a |
---|
324 | fixed axis of choice. |
---|
325 | @remarks |
---|
326 | This method allows you to change the yaw behaviour of the camera |
---|
327 | - by default, the camera yaws around a fixed Y axis. This is |
---|
328 | often what you want - for example if you're making a first-person |
---|
329 | shooter, you really don't want the yaw axis to reflect the local |
---|
330 | camera Y, because this would mean a different yaw axis if the |
---|
331 | player is looking upwards rather than when they are looking |
---|
332 | straight ahead. You can change this behaviour by calling this |
---|
333 | method, which you will want to do if you are making a completely |
---|
334 | free camera like the kind used in a flight simulator. |
---|
335 | @param useFixed |
---|
336 | If @c true, the axis passed in the second parameter will |
---|
337 | always be the yaw axis no matter what the camera orientation. |
---|
338 | If false, the camera yaws around the local Y. |
---|
339 | @param fixedAxis |
---|
340 | The axis to use if the first parameter is true. |
---|
341 | */ |
---|
342 | void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y ); |
---|
343 | |
---|
344 | |
---|
345 | /** Returns the camera's current orientation. |
---|
346 | */ |
---|
347 | const Quaternion& getOrientation(void) const; |
---|
348 | |
---|
349 | /** Sets the camera's orientation. |
---|
350 | */ |
---|
351 | void setOrientation(const Quaternion& q); |
---|
352 | |
---|
353 | /** Tells the Camera to contact the SceneManager to render from it's viewpoint. |
---|
354 | @param vp The viewport to render to |
---|
355 | @param includeOverlays Whether or not any overlay objects should be included |
---|
356 | */ |
---|
357 | void _renderScene(Viewport *vp, bool includeOverlays); |
---|
358 | |
---|
359 | /** Function for outputting to a stream. |
---|
360 | */ |
---|
361 | _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c); |
---|
362 | |
---|
363 | /** Internal method to notify camera of the visible faces in the last render. |
---|
364 | */ |
---|
365 | void _notifyRenderedFaces(unsigned int numfaces); |
---|
366 | |
---|
367 | /** Internal method to notify camera of the visible batches in the last render. |
---|
368 | */ |
---|
369 | void _notifyRenderedBatches(unsigned int numbatches); |
---|
370 | |
---|
371 | /** Internal method to retrieve the number of visible faces in the last render. |
---|
372 | */ |
---|
373 | unsigned int _getNumRenderedFaces(void) const; |
---|
374 | |
---|
375 | /** Internal method to retrieve the number of visible batches in the last render. |
---|
376 | */ |
---|
377 | unsigned int _getNumRenderedBatches(void) const; |
---|
378 | |
---|
379 | /** Gets the derived orientation of the camera, including any |
---|
380 | rotation inherited from a node attachment and reflection matrix. */ |
---|
381 | const Quaternion& getDerivedOrientation(void) const; |
---|
382 | /** Gets the derived position of the camera, including any |
---|
383 | translation inherited from a node attachment and reflection matrix. */ |
---|
384 | const Vector3& getDerivedPosition(void) const; |
---|
385 | /** Gets the derived direction vector of the camera, including any |
---|
386 | rotation inherited from a node attachment and reflection matrix. */ |
---|
387 | Vector3 getDerivedDirection(void) const; |
---|
388 | /** Gets the derived up vector of the camera, including any |
---|
389 | rotation inherited from a node attachment and reflection matrix. */ |
---|
390 | Vector3 getDerivedUp(void) const; |
---|
391 | /** Gets the derived right vector of the camera, including any |
---|
392 | rotation inherited from a node attachment and reflection matrix. */ |
---|
393 | Vector3 getDerivedRight(void) const; |
---|
394 | |
---|
395 | /** Gets the real world orientation of the camera, including any |
---|
396 | rotation inherited from a node attachment */ |
---|
397 | const Quaternion& getRealOrientation(void) const; |
---|
398 | /** Gets the real world position of the camera, including any |
---|
399 | translation inherited from a node attachment. */ |
---|
400 | const Vector3& getRealPosition(void) const; |
---|
401 | /** Gets the real world direction vector of the camera, including any |
---|
402 | rotation inherited from a node attachment. */ |
---|
403 | Vector3 getRealDirection(void) const; |
---|
404 | /** Gets the real world up vector of the camera, including any |
---|
405 | rotation inherited from a node attachment. */ |
---|
406 | Vector3 getRealUp(void) const; |
---|
407 | /** Gets the real world right vector of the camera, including any |
---|
408 | rotation inherited from a node attachment. */ |
---|
409 | Vector3 getRealRight(void) const; |
---|
410 | |
---|
411 | /** Overridden from Frustum/Renderable */ |
---|
412 | void getWorldTransforms(Matrix4* mat) const; |
---|
413 | |
---|
414 | /** Overridden from MovableObject */ |
---|
415 | const String& getMovableType(void) const; |
---|
416 | |
---|
417 | /** Enables / disables automatic tracking of a SceneNode. |
---|
418 | @remarks |
---|
419 | If you enable auto-tracking, this Camera will automatically rotate to |
---|
420 | look at the target SceneNode every frame, no matter how |
---|
421 | it or SceneNode move. This is handy if you want a Camera to be focused on a |
---|
422 | single object or group of objects. Note that by default the Camera looks at the |
---|
423 | origin of the SceneNode, if you want to tweak this, e.g. if the object which is |
---|
424 | attached to this target node is quite big and you want to point the camera at |
---|
425 | a specific point on it, provide a vector in the 'offset' parameter and the |
---|
426 | camera's target point will be adjusted. |
---|
427 | @param enabled If true, the Camera will track the SceneNode supplied as the next |
---|
428 | parameter (cannot be null). If false the camera will cease tracking and will |
---|
429 | remain in it's current orientation. |
---|
430 | @param target Pointer to the SceneNode which this Camera will track. Make sure you don't |
---|
431 | delete this SceneNode before turning off tracking (e.g. SceneManager::clearScene will |
---|
432 | delete it so be careful of this). Can be null if and only if the enabled param is false. |
---|
433 | @param offset If supplied, the camera targets this point in local space of the target node |
---|
434 | instead of the origin of the target node. Good for fine tuning the look at point. |
---|
435 | */ |
---|
436 | void setAutoTracking(bool enabled, SceneNode* const target = 0, |
---|
437 | const Vector3& offset = Vector3::ZERO); |
---|
438 | |
---|
439 | |
---|
440 | /** Sets the level-of-detail factor for this Camera. |
---|
441 | @remarks |
---|
442 | This method can be used to influence the overall level of detail of the scenes |
---|
443 | rendered using this camera. Various elements of the scene have level-of-detail |
---|
444 | reductions to improve rendering speed at distance; this method allows you |
---|
445 | to hint to those elements that you would like to adjust the level of detail that |
---|
446 | they would normally use (up or down). |
---|
447 | @par |
---|
448 | The most common use for this method is to reduce the overall level of detail used |
---|
449 | for a secondary camera used for sub viewports like rear-view mirrors etc. |
---|
450 | Note that scene elements are at liberty to ignore this setting if they choose, |
---|
451 | this is merely a hint. |
---|
452 | @param factor The factor to apply to the usual level of detail calculation. Higher |
---|
453 | values increase the detail, so 2.0 doubles the normal detail and 0.5 halves it. |
---|
454 | */ |
---|
455 | void setLodBias(Real factor = 1.0); |
---|
456 | |
---|
457 | /** Returns the level-of-detail bias factor currently applied to this camera. |
---|
458 | @remarks |
---|
459 | See Camera::setLodBias for more details. |
---|
460 | */ |
---|
461 | Real getLodBias(void) const; |
---|
462 | |
---|
463 | /** Set a pointer to the camera which should be used to determine |
---|
464 | LOD settings. |
---|
465 | @remarks |
---|
466 | Sometimes you don't want the LOD of a render to be based on the camera |
---|
467 | that's doing the rendering, you want it to be based on a different |
---|
468 | camera. A good example is when rendering shadow maps, since they will |
---|
469 | be viewed from the perspective of another camera. Therefore this method |
---|
470 | lets you associate a different camera instance to use to determine the LOD. |
---|
471 | @par |
---|
472 | To revert the camera to determining LOD based on itself, call this method with |
---|
473 | a pointer to itself. |
---|
474 | */ |
---|
475 | virtual void setLodCamera(const Camera* lodCam); |
---|
476 | |
---|
477 | /** Get a pointer to the camera which should be used to determine |
---|
478 | LOD settings. |
---|
479 | @remarks |
---|
480 | If setLodCamera hasn't been called with a different camera, this |
---|
481 | method will return 'this'. |
---|
482 | */ |
---|
483 | virtual const Camera* getLodCamera() const; |
---|
484 | |
---|
485 | |
---|
486 | /** Gets a world space ray as cast from the camera through a viewport position. |
---|
487 | @param screenx, screeny The x and y position at which the ray should intersect the viewport, |
---|
488 | in normalised screen coordinates [0,1] |
---|
489 | */ |
---|
490 | Ray getCameraToViewportRay(Real screenx, Real screeny) const; |
---|
491 | /** Gets a world space ray as cast from the camera through a viewport position. |
---|
492 | @param screenx, screeny The x and y position at which the ray should intersect the viewport, |
---|
493 | in normalised screen coordinates [0,1] |
---|
494 | @param outRay Ray instance to populate with result |
---|
495 | */ |
---|
496 | void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const; |
---|
497 | |
---|
498 | /** Gets a world-space list of planes enclosing a volume based on a viewport |
---|
499 | rectangle. |
---|
500 | @remarks |
---|
501 | Can be useful for populating a PlaneBoundedVolumeListSceneQuery, e.g. |
---|
502 | for a rubber-band selection. |
---|
503 | @param screenLeft, screenTop, screenRight, screenBottom The bounds of the |
---|
504 | on-screen rectangle, expressed in normalised screen coordinates [0,1] |
---|
505 | @param includeFarPlane If true, the volume is truncated by the camera far plane, |
---|
506 | by default it is left open-ended |
---|
507 | */ |
---|
508 | PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft, |
---|
509 | Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false); |
---|
510 | |
---|
511 | /** Gets a world-space list of planes enclosing a volume based on a viewport |
---|
512 | rectangle. |
---|
513 | @remarks |
---|
514 | Can be useful for populating a PlaneBoundedVolumeListSceneQuery, e.g. |
---|
515 | for a rubber-band selection. |
---|
516 | @param screenLeft, screenTop, screenRight, screenBottom The bounds of the |
---|
517 | on-screen rectangle, expressed in normalised screen coordinates [0,1] |
---|
518 | @param outVolume The plane list to populate with the result |
---|
519 | @param includeFarPlane If true, the volume is truncated by the camera far plane, |
---|
520 | by default it is left open-ended |
---|
521 | */ |
---|
522 | void getCameraToViewportBoxVolume(Real screenLeft, |
---|
523 | Real screenTop, Real screenRight, Real screenBottom, |
---|
524 | PlaneBoundedVolume* outVolume, bool includeFarPlane = false); |
---|
525 | |
---|
526 | /** Internal method for OGRE to use for LOD calculations. */ |
---|
527 | Real _getLodBiasInverse(void) const; |
---|
528 | |
---|
529 | |
---|
530 | /** Internal method used by OGRE to update auto-tracking cameras. */ |
---|
531 | void _autoTrack(void); |
---|
532 | |
---|
533 | |
---|
534 | /** Sets the viewing window inside of viewport. |
---|
535 | @remarks |
---|
536 | This method can be used to set a subset of the viewport as the rendering |
---|
537 | target. |
---|
538 | @param left Relative to Viewport - 0 corresponds to left edge, 1 - to right edge (default - 0). |
---|
539 | @param top Relative to Viewport - 0 corresponds to top edge, 1 - to bottom edge (default - 0). |
---|
540 | @param right Relative to Viewport - 0 corresponds to left edge, 1 - to right edge (default - 1). |
---|
541 | @param bottom Relative to Viewport - 0 corresponds to top edge, 1 - to bottom edge (default - 1). |
---|
542 | */ |
---|
543 | virtual void setWindow (Real left, Real top, Real right, Real bottom); |
---|
544 | /// Cancel view window. |
---|
545 | virtual void resetWindow (void); |
---|
546 | /// Returns if a viewport window is being used |
---|
547 | virtual bool isWindowSet(void) const { return mWindowSet; } |
---|
548 | /// Gets the window clip planes, only applicable if isWindowSet == true |
---|
549 | const vector<Plane>::type& getWindowPlanes(void) const; |
---|
550 | |
---|
551 | /** Overridden from MovableObject */ |
---|
552 | Real getBoundingRadius(void) const; |
---|
553 | /** Get the auto tracking target for this camera, if any. */ |
---|
554 | SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; } |
---|
555 | /** Get the auto tracking offset for this camera, if it is auto tracking. */ |
---|
556 | const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; } |
---|
557 | |
---|
558 | /** Get the last viewport which was attached to this camera. |
---|
559 | @note This is not guaranteed to be the only viewport which is |
---|
560 | using this camera, just the last once which was created referring |
---|
561 | to it. |
---|
562 | */ |
---|
563 | Viewport* getViewport(void) const {return mLastViewport;} |
---|
564 | /** Notifies this camera that a viewport is using it.*/ |
---|
565 | void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;} |
---|
566 | |
---|
567 | /** If set to true a viewport that owns this frustum will be able to |
---|
568 | recalculate the aspect ratio whenever the frustum is resized. |
---|
569 | @remarks |
---|
570 | You should set this to true only if the frustum / camera is used by |
---|
571 | one viewport at the same time. Otherwise the aspect ratio for other |
---|
572 | viewports may be wrong. |
---|
573 | */ |
---|
574 | void setAutoAspectRatio(bool autoratio); |
---|
575 | |
---|
576 | /** Retrieves if AutoAspectRatio is currently set or not |
---|
577 | */ |
---|
578 | bool getAutoAspectRatio(void) const; |
---|
579 | |
---|
580 | /** Tells the camera to use a separate Frustum instance to perform culling. |
---|
581 | @remarks |
---|
582 | By calling this method, you can tell the camera to perform culling |
---|
583 | against a different frustum to it's own. This is mostly useful for |
---|
584 | debug cameras that allow you to show the culling behaviour of another |
---|
585 | camera, or a manual frustum instance. |
---|
586 | @param frustum Pointer to a frustum to use; this can either be a manual |
---|
587 | Frustum instance (which you can attach to scene nodes like any other |
---|
588 | MovableObject), or another camera. If you pass 0 to this method it |
---|
589 | reverts the camera to normal behaviour. |
---|
590 | */ |
---|
591 | void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; } |
---|
592 | /** Returns the custom culling frustum in use. */ |
---|
593 | Frustum* getCullingFrustum(void) const { return mCullFrustum; } |
---|
594 | |
---|
595 | /** Forward projects frustum rays to find forward intersection with plane. |
---|
596 | @remarks |
---|
597 | Forward projection may lead to intersections at infinity. |
---|
598 | */ |
---|
599 | virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const; |
---|
600 | |
---|
601 | /// @copydoc Frustum::isVisible(const AxisAlignedBox&, FrustumPlane*) const |
---|
602 | bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const; |
---|
603 | /// @copydoc Frustum::isVisible(const Sphere&, FrustumPlane*) const |
---|
604 | bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const; |
---|
605 | /// @copydoc Frustum::isVisible(const Vector3&, FrustumPlane*) const |
---|
606 | bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const; |
---|
607 | /// @copydoc Frustum::getWorldSpaceCorners |
---|
608 | const Vector3* getWorldSpaceCorners(void) const; |
---|
609 | /// @copydoc Frustum::getFrustumPlane |
---|
610 | const Plane& getFrustumPlane( unsigned short plane ) const; |
---|
611 | /// @copydoc Frustum::projectSphere |
---|
612 | bool projectSphere(const Sphere& sphere, |
---|
613 | Real* left, Real* top, Real* right, Real* bottom) const; |
---|
614 | /// @copydoc Frustum::getNearClipDistance |
---|
615 | Real getNearClipDistance(void) const; |
---|
616 | /// @copydoc Frustum::getFarClipDistance |
---|
617 | Real getFarClipDistance(void) const; |
---|
618 | /// @copydoc Frustum::getViewMatrix |
---|
619 | const Matrix4& getViewMatrix(void) const; |
---|
620 | /** Specialised version of getViewMatrix allowing caller to differentiate |
---|
621 | whether the custom culling frustum should be allowed or not. |
---|
622 | @remarks |
---|
623 | The default behaviour of the standard getViewMatrix is to delegate to |
---|
624 | the alternate culling frustum, if it is set. This is expected when |
---|
625 | performing CPU calculations, but the final rendering must be performed |
---|
626 | using the real view matrix in order to display the correct debug view. |
---|
627 | */ |
---|
628 | const Matrix4& getViewMatrix(bool ownFrustumOnly) const; |
---|
629 | /** Set whether this camera should use the 'rendering distance' on |
---|
630 | objects to exclude distant objects from the final image. The |
---|
631 | default behaviour is to use it. |
---|
632 | @param use True to use the rendering distance, false not to. |
---|
633 | */ |
---|
634 | virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; } |
---|
635 | /** Get whether this camera should use the 'rendering distance' on |
---|
636 | objects to exclude distant objects from the final image. |
---|
637 | */ |
---|
638 | virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; } |
---|
639 | |
---|
640 | /** Synchronise core camera settings with another. |
---|
641 | @remarks |
---|
642 | Copies the position, orientation, clip distances, projection type, |
---|
643 | FOV, focal length and aspect ratio from another camera. Other settings like query flags, |
---|
644 | reflection etc are preserved. |
---|
645 | */ |
---|
646 | virtual void synchroniseBaseSettingsWith(const Camera* cam); |
---|
647 | |
---|
648 | /** Get the derived position of this frustum. */ |
---|
649 | const Vector3& getPositionForViewUpdate(void) const; |
---|
650 | /** Get the derived orientation of this frustum. */ |
---|
651 | const Quaternion& getOrientationForViewUpdate(void) const; |
---|
652 | |
---|
653 | /** @brief Sets whether to use min display size calculations. |
---|
654 | When active, objects that derive from MovableObject whose size on the screen is less then a MovableObject::mMinPixelSize will not |
---|
655 | be rendered. |
---|
656 | */ |
---|
657 | void setUseMinPixelSize(bool enable) { mUseMinPixelSize = enable; } |
---|
658 | /** Returns whether to use min display size calculations |
---|
659 | @see Camera::setUseMinDisplaySize |
---|
660 | */ |
---|
661 | bool getUseMinPixelSize() const { return mUseMinPixelSize; } |
---|
662 | |
---|
663 | /** Returns an estimated ratio between a pixel and the display area it represents. |
---|
664 | For orthographic cameras this function returns the amount of meters covered by |
---|
665 | a single pixel along the vertical axis. For perspective cameras the value |
---|
666 | returned is the amount of meters covered by a single pixel per meter distance |
---|
667 | from the camera. |
---|
668 | @note |
---|
669 | This parameter is calculated just before the camera is rendered |
---|
670 | @note |
---|
671 | This parameter is used in min display size calculations. |
---|
672 | */ |
---|
673 | Real getPixelDisplayRatio() const { return mPixelDisplayRatio; } |
---|
674 | |
---|
675 | }; |
---|
676 | /** @} */ |
---|
677 | /** @} */ |
---|
678 | |
---|
679 | } // namespace Ogre |
---|
680 | |
---|
681 | #include "OgreHeaderSuffix.h" |
---|
682 | |
---|
683 | #endif // __Camera_H__ |
---|