Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ReferenceApplication/ReferenceAppLayer/include/OgreRefAppWorld.h @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 9.1 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_WORLD_H__
30#define __REFAPP_WORLD_H__
31
32#include "OgreRefAppPrerequisites.h"
33#include "OgreRefAppJoint.h"
34#include <OgreSingleton.h>
35
36namespace OgreRefApp {
37
38    class _OgreRefAppExport World : public Singleton<World>
39    {
40    public:
41        /// World type, you'll want to extend this for your own apps
42        enum WorldType {
43            WT_REFAPP_GENERIC,
44            WT_REFAPP_BSP
45        };
46    protected:
47        /// Pointer to OGRE's scene manager
48        SceneManager* mSceneMgr;
49
50        typedef std::map<String, ApplicationObject*> ObjectMap;
51        /// Main list of objects
52        ObjectMap mObjects;
53
54        typedef std::map<String, Joint*> JointMap;
55        JointMap mJoints;
56
57        typedef std::set<ApplicationObject*> ObjectSet;
58        /// Set of dynamics objects (those to perform physics on)
59        ObjectSet mDynamicsObjects;
60
61        // ODE world object
62        dWorld* mOdeWorld;
63
64        /// Contact joint group
65        dJointGroup* mOdeContactGroup;
66
67        Vector3 mGravity;
68
69        IntersectionSceneQuery* mIntersectionQuery;
70
71        /// The step size of the collision / physics simulation
72        Real mSimulationStepSize;
73
74        /// The type of world we're dealing with
75        WorldType mWorldType;
76
77    public:
78        /** Creates an instance of the world.
79        @param sceneMgr Pointer to the scene manager which will manage the scene
80        @param worldType The type of world being used
81        */
82        World(SceneManager* sceneMgr, WorldType worldType = WT_REFAPP_GENERIC);
83        ~World();
84
85        /// Get the scene manager for this world
86        SceneManager* getSceneManager(void);
87
88        /** Create an OGRE head object. */
89        OgreHead* createOgreHead(const String& name, const Vector3& pos = Vector3::ZERO, 
90            const Quaternion& orientation = Quaternion::IDENTITY);
91
92        /** Create a plane object. */
93        FinitePlane* createPlane(const String& name, Real width, Real height, const Vector3& pos = Vector3::ZERO, 
94            const Quaternion& orientation = Quaternion::IDENTITY);
95
96        /** Create a ball object. */
97        Ball* createBall(const String& name, Real radius, const Vector3& pos = Vector3::ZERO, 
98            const Quaternion& orientation = Quaternion::IDENTITY);
99
100        /** Create a box object. */
101        Box* createBox(const String& name, Real width, Real height, Real depth,
102            const Vector3& pos = Vector3::ZERO, 
103            const Quaternion& orientation = Quaternion::IDENTITY);
104
105        /** Create a camera which interacts with the world. */
106        CollideCamera* createCamera(const String& name, 
107            const Vector3& pos = Vector3::ZERO, 
108            const Quaternion& orientation = Quaternion::IDENTITY);
109
110        /** Clears the scene. */
111        void clear(void);
112
113        dWorld* getOdeWorld(void);
114        dJointGroup* getOdeContactJointGroup(void);
115
116        /** Detects all the collisions in the world and acts on them.
117        @remarks
118            This method performs the appropriate queries to detect all the colliding objects
119            in the world, tells the objects about it and adds the appropriate physical simulation
120            constructs required to apply collision response when applyDynamics is called.
121        @par This method is called automatically by World::simulationStep()
122        */
123        void _applyCollision(void);
124
125        /** Updates the world simulation.
126        @par This method is called automatically by World::simulationStep()
127        */
128        void _applyDynamics(Real timeElapsed);
129
130        /** Internal method for notifying the world of a change in the dynamics status of an object. */
131        void _notifyDynamicsStateForObject(ApplicationObject* obj, bool dynamicsEnabled);
132
133        /** Sets the gravity vector, units are in m/s^2.
134        @remarks
135            The world defaults to no gravity.
136            Tip: Earth gravity is Vector3(0, -9.81, 0);
137        */
138        void setGravity(const Vector3& vec);
139
140        /** Gets the gravity vector. */
141        const Vector3& getGravity(void);
142
143        /** Creates a Joint object for linking objects together in the world.
144        @param name The name of the Joint.
145        @param jtype The type of joint, see Joint::JointType.
146        @param obj1 The first object to attach, or NULL to attach to the static world.
147        @param obj2 The second object to attach, or NULL to attach to the static world.
148        */
149        Joint* createJoint(const String& name, Joint::JointType jtype,
150            ApplicationObject* obj1, ApplicationObject* obj2);
151
152        /** Sets the step size of the simulation.
153        @remarks
154            This parameter allows you to alter the accuracy of the simulation.
155            This is the interval at which collision and physics are performed,
156            such that in high frame rate scenarios these operations are
157            not done every single frame, and in low frame rate situations more
158            steps are performed per frame to ensure the stability of the
159            simulation.
160        @par
161            The default value for this parameter is 0.01s.
162        */
163        void setSimulationStepSize(Real step);
164        /** Returns the size of the simulation step. */
165        Real getSimulationStepSize(void);
166
167        /** Performs a simulation step, ie applies collision and physics.
168        @remarks
169            Collision events will cause callbacks to your ApplicationObject
170            instances to notify them of the collisions; this is for information,
171            dynamics are applied automatically if turned on for the objects so you
172            do not need to handle physics yourself if you do not wish to.
173        @par
174            Note that if the timeElapsed parameter is greater than the simulation
175            step size (as set using setSimulationStepSize), more than one collision
176            and dynamics step will take place during this call. Similarly, no step
177            may occur if the time elapsed has not reached the simulation step
178            size yet.
179        */
180        void simulationStep(Real timeElapsed);
181        /** Override standard Singleton retrieval.
182        @remarks
183        Why do we do this? Well, it's because the Singleton
184        implementation is in a .h file, which means it gets compiled
185        into anybody who includes it. This is needed for the
186        Singleton template to work, but we actually only want it
187        compiled into the implementation of the class based on the
188        Singleton, not all of them. If we don't change this, we get
189        link errors when trying to use the Singleton-based class from
190        an outside dll.
191        @par
192        This method just delegates to the template version anyway,
193        but the implementation stays in this single compilation unit,
194        preventing link errors.
195        */
196        static World& getSingleton(void);
197        /** Override standard Singleton retrieval.
198        @remarks
199        Why do we do this? Well, it's because the Singleton
200        implementation is in a .h file, which means it gets compiled
201        into anybody who includes it. This is needed for the
202        Singleton template to work, but we actually only want it
203        compiled into the implementation of the class based on the
204        Singleton, not all of them. If we don't change this, we get
205        link errors when trying to use the Singleton-based class from
206        an outside dll.
207        @par
208        This method just delegates to the template version anyway,
209        but the implementation stays in this single compilation unit,
210        preventing link errors.
211        */
212        static World* getSingletonPtr(void);
213
214    };
215
216
217}
218
219#endif
220
Note: See TracBrowser for help on using the repository browser.