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

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