source: OGRE/trunk/ogrenew/ReferenceApplication/ReferenceAppLayer/include/OgreRefAppCollideCamera.h @ 692

Revision 692, 14.3 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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