Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ReferenceApplication/ReferenceAppLayer/include/OgreRefAppCollideCamera.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 14.2 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of the OGRE Reference Application, a layer built
4on top of OGRE(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __REFAPP_COLLIDECAMERA_H__
30#define __REFAPP_COLLIDECAMERA_H__
31
32#include "OgreRefAppPrerequisites.h"
33#include "OgreCamera.h"
34#include "OgreRefAppApplicationObject.h"
35
36namespace OgreRefApp {
37
38    /** A camera which can interact with the world. */
39    class _OgreRefAppExport CollideCamera : public ApplicationObject
40    {
41    protected:
42        /// Contained camera
43        /* Note that I choose to contain Camera rather than subclass because the
44           multiple inheritence would get very nasty (lots of method name clashes)
45           and it's better that we can hide a few non-relevant methods this way.
46           ApplicationObject needs to be the top-level interface anyway. */
47        Camera *mCamera;
48        /// Set up
49        void setUp(const String& name);
50        /// Triggers recacl of collison bounds
51        void nearDistChanged(void);
52    public:
53        CollideCamera(const String& name);
54
55        /** Gets the internal Camera object. */
56        Camera* getRealCamera(void) { return mCamera; }
57
58        // ----------------------------------------------
59        // Overridden methods from ApplicationObject
60        // Note that we position the camera using the node
61        // But we orient the camera on it's own rotation
62        // ----------------------------------------------
63       
64        /** This method is called automatically if testCollide indicates a real collision.
65        */
66        void _notifyCollided(SceneQuery::WorldFragment* wf, const CollisionInfo& info);
67        /** Sets the orientation of this object. */
68        void setOrientation(const Quaternion& orientation);
69        /** Gets the current orientation of this object. */
70        const Quaternion& getOrientation(void);
71
72        /** Moves the object along it's local  axes.
73            @par
74                This method moves the object by the supplied vector along the
75                local axes of the obect.
76            @param
77                d Vector with x,y,z values representing the translation.
78        */
79        void translate(const Vector3& d);
80        /** Rotate the object around the local Z-axis.
81        */
82        void roll(const Radian& angle);
83#ifndef OGRE_FORCE_ANGLE_TYPES
84        inline void roll(Real angleunits) {
85            roll ( Angle(angleunits) );
86        }
87#endif//OGRE_FORCE_ANGLE_TYPES
88
89        /** Rotate the object around the local X-axis.
90        */
91        void pitch(const Radian& angle);
92#ifndef OGRE_FORCE_ANGLE_TYPES
93        inline void pitch(Real angleunits) {
94            pitch ( Angle(angleunits) );
95        }
96#endif//OGRE_FORCE_ANGLE_TYPES
97
98        /** Rotate the object around the local Y-axis.
99        */
100        void yaw(const Radian& angle);
101#ifndef OGRE_FORCE_ANGLE_TYPES
102        inline void yaw(Real angleunits) {
103            yaw ( Angle(angleunits) );
104        }
105#endif//OGRE_FORCE_ANGLE_TYPES
106
107        /** Rotate the object around an arbitrary axis.
108        */
109        void rotate(const Vector3& axis, const Radian& angle);
110#ifndef OGRE_FORCE_ANGLE_TYPES
111        inline void rotate(const Vector3& axis, Real angleunits) {
112            rotate ( axis, Angle(angleunits) );
113        }
114#endif//OGRE_FORCE_ANGLE_TYPES
115
116        /** Rotate the object around an aritrary axis using a Quarternion.
117        */
118        void rotate(const Quaternion& q);
119
120        // ----------------------------------------------
121        // The following are methods delegated to Camera
122        // ----------------------------------------------
123
124        /** Sets the type of projection to use (orthographic or perspective). Default is perspective.
125        */
126        void setProjectionType(ProjectionType pt);
127
128        /** Retrieves info on the type of projection used (orthographic or perspective).
129        */
130        ProjectionType getProjectionType(void) const;
131
132        /** Sets the level of rendering detail required from this camera.
133            @remarks
134                Each camera is set to render at full detail by default, that is
135                with full texturing, lighting etc. This method lets you change
136                that behaviour, allowing you to make the camera just render a
137                wireframe view, for example.
138        */
139        void setPolygonMode(PolygonMode sd);
140
141        /** Retrieves the level of detail that the camera will render.
142        */
143        PolygonMode getPolygonMode(void) const;
144
145        /** Sets the camera's direction vector.
146            @remarks
147                Note that the 'up' vector for the camera will automatically be recalculated based on the
148                current 'up' vector (i.e. the roll will remain the same).
149        */
150        void setDirection(Real x, Real y, Real z);
151
152        /** Sets the camera's direction vector.
153        */
154        void setDirection(const Vector3& vec);
155
156        /* Gets the camera's direction.
157        */
158        Vector3 getDirection(void) const;
159
160
161        /** Points the camera at a location in worldspace.
162            @remarks
163                This is a helper method to automatically generate the
164                direction vector for the camera, based on it's current position
165                and the supplied look-at point.
166            @param
167                targetPoint A vector specifying the look at point.
168        */
169        void lookAt( const Vector3& targetPoint );
170        /** Points the camera at a location in worldspace.
171            @remarks
172                This is a helper method to automatically generate the
173                direction vector for the camera, based on it's current position
174                and the supplied look-at point.
175            @param
176                x
177            @param
178                y
179            @param
180                z Co-ordinates of the point to look at.
181        */
182        void lookAt(Real x, Real y, Real z);
183
184        /** Tells the camera whether to yaw around it's own local Y axis or a fixed axis of choice.
185            @remarks
186                This method allows you to change the yaw behaviour of the camera - by default, the camera
187                yaws around it's own local Y axis. This is often what you want - for example a flying camera
188                - but sometimes this produces unwanted effects. For example, if you're making a first-person
189                shooter, you really don't want the yaw axis to reflect the local camera Y, because this would
190                mean a different yaw axis if the player is looking upwards rather than when they are looking
191                straight ahead. You can change this behaviour by setting the yaw to a fixed axis (say, the world Y).
192            @param
193                useFixed If true, the axis passed in the second parameter will always be the yaw axis no
194                matter what the camera orientation. If false, the camera returns to it's default behaviour.
195            @param
196                fixedAxis The axis to use if the first parameter is true.
197        */
198        void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
199
200        /** Sets the Y-dimension Field Of View (FOV) of the camera.
201            @remarks
202                Field Of View (FOV) is the angle made between the camera's position, and the left & right edges
203                of the 'screen' onto which the scene is projected. High values (90+) result in a wide-angle,
204                fish-eye kind of view, low values (30-) in a stretched, telescopic kind of view. Typical values
205                are between 45 and 60.
206            @par
207                This value represents the HORIZONTAL field-of-view. The vertical field of view is calculated from
208                this depending on the dimensions of the viewport (they will only be the same if the viewport is square).
209            @note
210                Setting the FOV overrides the value supplied for Camera::setNearClipPlane.
211         */
212        void setFOVy(const Radian& fovy);
213#ifndef OGRE_FORCE_ANGLE_TYPES
214        inline void setFOVy(Real fovy) {
215            setFOVy ( Angle(fovy) );
216        }
217#endif//OGRE_FORCE_ANGLE_TYPES
218
219        /** Retrieves the cameras Y-dimension Field Of View (FOV).
220        */
221        const Radian& getFOVy(void) const;
222
223        /** Sets the position of the near clipping plane.
224            @remarks
225                The position of the near clipping plane is the distance from the cameras position to the screen
226                on which the world is projected. The near plane distance, combined with the field-of-view and the
227                aspect ratio, determines the size of the viewport through which the world is viewed (in world
228                co-ordinates). Note that this world viewport is different to a screen viewport, which has it's
229                dimensions expressed in pixels. The cameras viewport should have the same aspect ratio as the
230                screen viewport it renders into to avoid distortion.
231            @param
232                near The distance to the near clipping plane from the camera in world coordinates.
233         */
234        void setNearClipDistance(Real nearDist);
235
236        /** Sets the position of the near clipping plane.
237        */
238        Real getNearClipDistance(void) const;
239
240        /** Sets the distance to the far clipping plane.
241            @remarks
242                The view frustrum is a pyramid created from the camera position and the edges of the viewport.
243                This frustrum does not extend to infinity - it is cropped near to the camera and there is a far
244                plane beyond which nothing is displayed. This method sets the distance for the far plane. Different
245                applications need different values: e.g. a flight sim needs a much further far clipping plane than
246                a first-person shooter. An important point here is that the larger the gap between near and far
247                clipping planes, the lower the accuracy of the Z-buffer used to depth-cue pixels. This is because the
248                Z-range is limited to the size of the Z buffer (16 or 32-bit) and the max values must be spread over
249                the gap between near and far clip planes. The bigger the range, the more the Z values will
250                be approximated which can cause artifacts when lots of objects are close together in the Z-plane. So
251                make sure you clip as close to the camera as you can - don't set a huge value for the sake of
252                it.
253            @param
254                far The distance to the far clipping plane from the camera in world coordinates.
255        */
256        void setFarClipDistance(Real farDist);
257
258        /** Retrieves the distance from the camera to the far clipping plane.
259        */
260        Real getFarClipDistance(void) const;
261
262        /** Sets the aspect ratio for the camera viewport.
263            @remarks
264                The ratio between the x and y dimensions of the rectangular area visible through the camera
265                is known as aspect ratio: aspect = width / height .
266            @par
267                The default for most fullscreen windows is 1.3333 - this is also assumed by Ogre unless you
268                use this method to state otherwise.
269        */
270        void setAspectRatio(Real ratio);
271
272        /** Retreives the current aspect ratio.
273        */
274        Real getAspectRatio(void) const;
275
276        /** Retrieves a specified plane of the frustum.
277            @remarks
278                Gets a reference to one of the planes which make up the camera frustum, e.g. for clipping purposes.
279        */
280        const Plane& getFrustumPlane( FrustumPlane plane );
281
282        /** Tests whether the given container is visible in the Frustum.
283            @param
284                bound Bounding box to be checked
285            @param
286                culledBy Optional pointer to an int which will be filled by the plane number which culled
287                the box if the result was false;
288            @returns
289                If the box was visible, true is returned.
290            @par
291                Otherwise, false is returned.
292        */
293        bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0);
294
295        /** Tests whether the given container is visible in the Frustum.
296            @param
297                bound Bounding sphere to be checked
298            @param
299                culledBy Optional pointer to an int which will be filled by the plane number which culled
300                the box if the result was false;
301            @returns
302                If the sphere was visible, true is returned.
303            @par
304                Otherwise, false is returned.
305        */
306        bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0);
307
308        /** Tests whether the given vertex is visible in the Frustum.
309            @param
310                vert Vertex to be checked
311            @param
312                culledBy Optional pointer to an int which will be filled by the plane number which culled
313                the box if the result was false;
314            @returns
315                If the box was visible, true is returned.
316            @par
317                Otherwise, false is returned.
318        */
319        bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0);
320
321    };
322
323}
324
325#endif
Note: See TracBrowser for help on using the repository browser.