| 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-2006 Torus Knot Software Ltd | 
|---|
| 8 | Also see acknowledgements in Readme.html | 
|---|
| 9 |  | 
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under | 
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software | 
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later | 
|---|
| 13 | version. | 
|---|
| 14 |  | 
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT | 
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | 
|---|
| 18 |  | 
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with | 
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | 
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to | 
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. | 
|---|
| 23 |  | 
|---|
| 24 | You may alternatively use this source under the terms of a specific version of | 
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from | 
|---|
| 26 | Torus Knot Software Ltd. | 
|---|
| 27 | ----------------------------------------------------------------------------- | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | #ifndef __MovableObject_H__ | 
|---|
| 31 | #define __MovableObject_H__ | 
|---|
| 32 |  | 
|---|
| 33 | // Precompiler options | 
|---|
| 34 | #include "OgrePrerequisites.h" | 
|---|
| 35 | #include "OgreRenderQueue.h" | 
|---|
| 36 | #include "OgreAxisAlignedBox.h" | 
|---|
| 37 | #include "OgreSphere.h" | 
|---|
| 38 | #include "OgreShadowCaster.h" | 
|---|
| 39 | #include "OgreFactoryObj.h" | 
|---|
| 40 | #include "OgreAnimable.h" | 
|---|
| 41 | #include "OgreAny.h" | 
|---|
| 42 | #include "OgreUserDefinedObject.h" | 
|---|
| 43 |  | 
|---|
| 44 | namespace Ogre { | 
|---|
| 45 |  | 
|---|
| 46 |         // Forward declaration | 
|---|
| 47 |         class MovableObjectFactory; | 
|---|
| 48 |  | 
|---|
| 49 |     /** Abstract class definining a movable object in a scene. | 
|---|
| 50 |         @remarks | 
|---|
| 51 |             Instances of this class are discrete, relatively small, movable objects | 
|---|
| 52 |             which are attached to SceneNode objects to define their position. | 
|---|
| 53 |     */ | 
|---|
| 54 |     class _OgreExport MovableObject : public ShadowCaster, public AnimableObject | 
|---|
| 55 |     { | 
|---|
| 56 |     public: | 
|---|
| 57 |         /** Listener which gets called back on MovableObject events. | 
|---|
| 58 |         */ | 
|---|
| 59 |         class _OgreExport Listener | 
|---|
| 60 |         { | 
|---|
| 61 |         public: | 
|---|
| 62 |             Listener(void) {} | 
|---|
| 63 |             virtual ~Listener() {} | 
|---|
| 64 |             /** MovableObject is being destroyed */ | 
|---|
| 65 |             virtual void objectDestroyed(MovableObject*) {} | 
|---|
| 66 |             /** MovableObject has been attached to a node */ | 
|---|
| 67 |             virtual void objectAttached(MovableObject*) {} | 
|---|
| 68 |             /** MovableObject has been detached from a node */ | 
|---|
| 69 |             virtual void objectDetached(MovableObject*) {} | 
|---|
| 70 |             /** MovableObject has been moved */ | 
|---|
| 71 |             virtual void objectMoved(MovableObject*) {} | 
|---|
| 72 |             /** Called when the movable object of the camera to be used for rendering. | 
|---|
| 73 |             @returns | 
|---|
| 74 |                 true if allows queue for rendering, false otherwise. | 
|---|
| 75 |             */ | 
|---|
| 76 |             virtual bool objectRendering(const MovableObject*, const Camera*) { return true; } | 
|---|
| 77 |             /** Called when the movable object needs to query a light list. | 
|---|
| 78 |             @remarks | 
|---|
| 79 |                 If you want to customize light finding for this object, you should override  | 
|---|
| 80 |                                 this method and hook into MovableObject via MovableObject::setListener. | 
|---|
| 81 |                                 Be aware that the default method caches results within a frame to  | 
|---|
| 82 |                                 prevent unnecessary recalculation, so if you override this you  | 
|---|
| 83 |                                 should provide your own cacheing to maintain performance. | 
|---|
| 84 |                         @note | 
|---|
| 85 |                                 If you use texture shadows, there is an additional restriction -  | 
|---|
| 86 |                                 since the lights which should have shadow textures rendered for | 
|---|
| 87 |                                 them are determined based on the entire frustum, and not per-object, | 
|---|
| 88 |                                 it is important that the lights returned at the start of this  | 
|---|
| 89 |                                 list (up to the number of shadow textures available) are the same  | 
|---|
| 90 |                                 lights that were used to generate the shadow textures,  | 
|---|
| 91 |                                 and they are in the same order (particularly for additive effects). | 
|---|
| 92 |             @returns | 
|---|
| 93 |                 A pointer to a light list if you populated the light list yourself, or | 
|---|
| 94 |                 NULL to fall back on the default finding process. | 
|---|
| 95 |             */ | 
|---|
| 96 |             virtual const LightList* objectQueryLights(const MovableObject*) { return 0; } | 
|---|
| 97 |         }; | 
|---|
| 98 |  | 
|---|
| 99 |     protected: | 
|---|
| 100 |                 /// Name of this object | 
|---|
| 101 |                 String mName; | 
|---|
| 102 |                 /// Creator of this object (if created by a factory) | 
|---|
| 103 |                 MovableObjectFactory* mCreator; | 
|---|
| 104 |                 /// SceneManager holding this object (if applicable) | 
|---|
| 105 |                 SceneManager* mManager; | 
|---|
| 106 |         /// node to which this object is attached | 
|---|
| 107 |         Node* mParentNode; | 
|---|
| 108 |         bool mParentIsTagPoint; | 
|---|
| 109 |         /// Is this object visible? | 
|---|
| 110 |         bool mVisible; | 
|---|
| 111 |                 /// Upper distance to still render | 
|---|
| 112 |                 Real mUpperDistance; | 
|---|
| 113 |                 Real mSquaredUpperDistance; | 
|---|
| 114 |                 /// Hidden because of distance? | 
|---|
| 115 |                 bool mBeyondFarDistance; | 
|---|
| 116 |                 /// User defined link to another object / value / whatever | 
|---|
| 117 |                 Any mUserAny; | 
|---|
| 118 |         /// The render queue to use when rendering this object | 
|---|
| 119 |         uint8 mRenderQueueID; | 
|---|
| 120 |                 /// Flags whether the RenderQueue's default should be used. | 
|---|
| 121 |                 bool mRenderQueueIDSet; | 
|---|
| 122 |         /// Flags determining whether this object is included / excluded from scene queries | 
|---|
| 123 |         uint32 mQueryFlags; | 
|---|
| 124 |         /// Flags determining whether this object is visible (compared to SceneManager mask) | 
|---|
| 125 |         uint32 mVisibilityFlags; | 
|---|
| 126 |         /// Cached world AABB of this object | 
|---|
| 127 |         mutable AxisAlignedBox mWorldAABB; | 
|---|
| 128 |                 // Cached world bounding sphere | 
|---|
| 129 |                 mutable Sphere mWorldBoundingSphere; | 
|---|
| 130 |         /// World space AABB of this object's dark cap | 
|---|
| 131 |         mutable AxisAlignedBox mWorldDarkCapBounds; | 
|---|
| 132 |         /// Does this object cast shadows? | 
|---|
| 133 |         bool mCastShadows; | 
|---|
| 134 |  | 
|---|
| 135 |         /// Does rendering this object disabled by listener? | 
|---|
| 136 |         bool mRenderingDisabled; | 
|---|
| 137 |         /// MovableObject listener - only one allowed (no list) for size & performance reasons. */ | 
|---|
| 138 |         Listener* mListener; | 
|---|
| 139 |  | 
|---|
| 140 |         /// List of lights for this object | 
|---|
| 141 |         mutable LightList mLightList; | 
|---|
| 142 |         /// The last frame that this light list was updated in | 
|---|
| 143 |         mutable ulong mLightListUpdated; | 
|---|
| 144 |  | 
|---|
| 145 |                 // Static members | 
|---|
| 146 |                 /// Default query flags | 
|---|
| 147 |                 static uint32 msDefaultQueryFlags; | 
|---|
| 148 |                 /// Default visibility flags | 
|---|
| 149 |                 static uint32 msDefaultVisibilityFlags; | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|
| 152 |  | 
|---|
| 153 |     public: | 
|---|
| 154 |         /// Constructor | 
|---|
| 155 |         MovableObject(); | 
|---|
| 156 |  | 
|---|
| 157 |                 /// Named constructor | 
|---|
| 158 |                 MovableObject(const String& name); | 
|---|
| 159 |         /** Virtual destructor - read Scott Meyers if you don't know why this is needed. | 
|---|
| 160 |         */ | 
|---|
| 161 |         virtual ~MovableObject(); | 
|---|
| 162 |  | 
|---|
| 163 |                 /** Notify the object of it's creator (internal use only) */ | 
|---|
| 164 |                 virtual void _notifyCreator(MovableObjectFactory* fact) { mCreator = fact; } | 
|---|
| 165 |                 /** Get the creator of this object, if any (internal use only) */ | 
|---|
| 166 |                 virtual MovableObjectFactory*  _getCreator(void) const { return mCreator; } | 
|---|
| 167 |                 /** Notify the object of it's manager (internal use only) */ | 
|---|
| 168 |                 virtual void _notifyManager(SceneManager* man) { mManager = man; } | 
|---|
| 169 |                 /** Get the manager of this object, if any (internal use only) */ | 
|---|
| 170 |                 virtual SceneManager* _getManager(void) const { return mManager; } | 
|---|
| 171 |  | 
|---|
| 172 |         /** Returns the name of this object. */ | 
|---|
| 173 |                 virtual const String& getName(void) const { return mName; } | 
|---|
| 174 |  | 
|---|
| 175 |         /** Returns the type name of this object. */ | 
|---|
| 176 |         virtual const String& getMovableType(void) const = 0; | 
|---|
| 177 |  | 
|---|
| 178 |         /** Returns the node to which this object is attached. | 
|---|
| 179 |         @remarks | 
|---|
| 180 |             A MovableObject may be attached to either a SceneNode or to a TagPoint,  | 
|---|
| 181 |             the latter case if it's attached to a bone on an animated entity.  | 
|---|
| 182 |             Both are Node subclasses so this method will return either. | 
|---|
| 183 |         */ | 
|---|
| 184 |         virtual Node* getParentNode(void) const; | 
|---|
| 185 |  | 
|---|
| 186 |         /** Returns the scene node to which this object is attached. | 
|---|
| 187 |         @remarks | 
|---|
| 188 |             A MovableObject may be attached to either a SceneNode or to a TagPoint,  | 
|---|
| 189 |             the latter case if it's attached to a bone on an animated entity.  | 
|---|
| 190 |             This method will return the scene node of the parent entity  | 
|---|
| 191 |             if the latter is true. | 
|---|
| 192 |         */ | 
|---|
| 193 |         virtual SceneNode* getParentSceneNode(void) const; | 
|---|
| 194 |  | 
|---|
| 195 |         /** Internal method called to notify the object that it has been attached to a node. | 
|---|
| 196 |         */ | 
|---|
| 197 |         virtual void _notifyAttached(Node* parent, bool isTagPoint = false); | 
|---|
| 198 |  | 
|---|
| 199 |         /** Returns true if this object is attached to a SceneNode or TagPoint. */ | 
|---|
| 200 |         virtual bool isAttached(void) const; | 
|---|
| 201 |  | 
|---|
| 202 |         /** Returns true if this object is attached to a SceneNode or TagPoint,  | 
|---|
| 203 |                         and this SceneNode / TagPoint is currently in an active part of the | 
|---|
| 204 |                         scene graph. */ | 
|---|
| 205 |         virtual bool isInScene(void) const; | 
|---|
| 206 |  | 
|---|
| 207 |         /** Internal method called to notify the object that it has been moved. | 
|---|
| 208 |         */ | 
|---|
| 209 |         virtual void _notifyMoved(void); | 
|---|
| 210 |  | 
|---|
| 211 |                 /** Internal method to notify the object of the camera to be used for the next rendering operation. | 
|---|
| 212 |             @remarks | 
|---|
| 213 |                 Certain objects may want to do specific processing based on the camera position. This method notifies | 
|---|
| 214 |                 them incase they wish to do this. | 
|---|
| 215 |         */ | 
|---|
| 216 |         virtual void _notifyCurrentCamera(Camera* cam); | 
|---|
| 217 |  | 
|---|
| 218 |         /** Retrieves the local axis-aligned bounding box for this object. | 
|---|
| 219 |             @remarks | 
|---|
| 220 |                 This bounding box is in local coordinates. | 
|---|
| 221 |         */ | 
|---|
| 222 |         virtual const AxisAlignedBox& getBoundingBox(void) const = 0; | 
|---|
| 223 |  | 
|---|
| 224 |                 /** Retrieves the radius of the origin-centered bounding sphere  | 
|---|
| 225 |                          for this object. | 
|---|
| 226 |                 */ | 
|---|
| 227 |                 virtual Real getBoundingRadius(void) const = 0; | 
|---|
| 228 |  | 
|---|
| 229 |         /** Retrieves the axis-aligned bounding box for this object in world coordinates. */ | 
|---|
| 230 |         virtual const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const; | 
|---|
| 231 |                 /** Retrieves the worldspace bounding sphere for this object. */ | 
|---|
| 232 |         virtual const Sphere& getWorldBoundingSphere(bool derive = false) const; | 
|---|
| 233 |         /** Internal method by which the movable object must add Renderable subclass instances to the rendering queue. | 
|---|
| 234 |             @remarks | 
|---|
| 235 |                 The engine will call this method when this object is to be rendered. The object must then create one or more | 
|---|
| 236 |                 Renderable subclass instances which it places on the passed in Queue for rendering. | 
|---|
| 237 |         */ | 
|---|
| 238 |         virtual void _updateRenderQueue(RenderQueue* queue) = 0; | 
|---|
| 239 |  | 
|---|
| 240 |         /** Tells this object whether to be visible or not, if it has a renderable component.  | 
|---|
| 241 |                 @note An alternative approach of making an object invisible is to detach it | 
|---|
| 242 |                         from it's SceneNode, or to remove the SceneNode entirely.  | 
|---|
| 243 |                         Detaching a node means that structurally the scene graph changes.  | 
|---|
| 244 |                         Once this change has taken place, the objects / nodes that have been  | 
|---|
| 245 |                         removed have less overhead to the visbility detection pass than simply | 
|---|
| 246 |                         making the object invisible, so if you do this and leave the objects  | 
|---|
| 247 |                         out of the tree for a long time, it's faster. However, the act of  | 
|---|
| 248 |                         detaching / reattaching nodes is in itself more expensive than  | 
|---|
| 249 |                         setting an object visibility flag, since in the latter case  | 
|---|
| 250 |                         structural changes are not made. Therefore, small or frequent visbility | 
|---|
| 251 |                         changes are best done using this method; large or more longer term | 
|---|
| 252 |                         changes are best done by detaching. | 
|---|
| 253 |                 */ | 
|---|
| 254 |         virtual void setVisible(bool visible); | 
|---|
| 255 |  | 
|---|
| 256 |         /** Gets this object whether to be visible or not, if it has a renderable component.  | 
|---|
| 257 |         @remarks | 
|---|
| 258 |             Returns the value set by MovableObject::setVisible only. | 
|---|
| 259 |         */ | 
|---|
| 260 |         virtual bool getVisible(void) const; | 
|---|
| 261 |  | 
|---|
| 262 |         /** Returns whether or not this object is supposed to be visible or not.  | 
|---|
| 263 |                 @remarks | 
|---|
| 264 |                         Takes into account both upper rendering distance and visible flag. | 
|---|
| 265 |                 */ | 
|---|
| 266 |         virtual bool isVisible(void) const; | 
|---|
| 267 |  | 
|---|
| 268 |                 /** Sets the distance at which the object is no longer rendered. | 
|---|
| 269 |                 @param dist Distance beyond which the object will not be rendered  | 
|---|
| 270 |                         (the default is 0, which means objects are always rendered). | 
|---|
| 271 |                 */ | 
|---|
| 272 |                 virtual void setRenderingDistance(Real dist) {  | 
|---|
| 273 |                         mUpperDistance = dist;  | 
|---|
| 274 |                         mSquaredUpperDistance = mUpperDistance * mUpperDistance; | 
|---|
| 275 |                 } | 
|---|
| 276 |  | 
|---|
| 277 |                 /** Gets the distance at which batches are no longer rendered. */ | 
|---|
| 278 |                 virtual Real getRenderingDistance(void) const { return mUpperDistance; } | 
|---|
| 279 |  | 
|---|
| 280 |         /** Call this to associate your own custom user object instance with this MovableObject. | 
|---|
| 281 |         @remarks | 
|---|
| 282 |             By simply making your game / application object a subclass of UserDefinedObject, you | 
|---|
| 283 |             can establish a link between an OGRE instance of MovableObject and your own application | 
|---|
| 284 |             classes. Call this method to establish the link. | 
|---|
| 285 |         */ | 
|---|
| 286 |         virtual void setUserObject(UserDefinedObject* obj) { mUserAny = Any(obj); } | 
|---|
| 287 |         /** Retrieves a pointer to a custom application object associated with this movable by an earlier | 
|---|
| 288 |             call to setUserObject. | 
|---|
| 289 |         */ | 
|---|
| 290 |         virtual UserDefinedObject* getUserObject(void)  | 
|---|
| 291 |                 {  | 
|---|
| 292 |                         return mUserAny.isEmpty() ? 0 : any_cast<UserDefinedObject*>(mUserAny);  | 
|---|
| 293 |                 } | 
|---|
| 294 |  | 
|---|
| 295 |                 /** Sets any kind of user value on this object. | 
|---|
| 296 |                 @remarks | 
|---|
| 297 |                         This method allows you to associate any user value you like with  | 
|---|
| 298 |                         this MovableObject. This can be a pointer back to one of your own | 
|---|
| 299 |                         classes for instance. | 
|---|
| 300 |                 @note This value is shared with setUserObject so don't use both! | 
|---|
| 301 |                 */ | 
|---|
| 302 |                 virtual void setUserAny(const Any& anything) { mUserAny = anything; } | 
|---|
| 303 |  | 
|---|
| 304 |                 /** Retrieves the custom user value associated with this object. | 
|---|
| 305 |                 */ | 
|---|
| 306 |                 virtual const Any& getUserAny(void) const { return mUserAny; } | 
|---|
| 307 |  | 
|---|
| 308 |         /** Sets the render queue group this entity will be rendered through. | 
|---|
| 309 |         @remarks | 
|---|
| 310 |             Render queues are grouped to allow you to more tightly control the ordering | 
|---|
| 311 |             of rendered objects. If you do not call this method, all Entity objects default | 
|---|
| 312 |             to the default queue (RenderQueue::getDefaultQueueGroup), which is fine for most objects. You may want to alter this | 
|---|
| 313 |             if you want this entity to always appear in front of other objects, e.g. for | 
|---|
| 314 |             a 3D menu system or such. | 
|---|
| 315 |         @par | 
|---|
| 316 |             See RenderQueue for more details. | 
|---|
| 317 |         @param queueID Enumerated value of the queue group to use. | 
|---|
| 318 |         */ | 
|---|
| 319 |         virtual void setRenderQueueGroup(uint8 queueID); | 
|---|
| 320 |  | 
|---|
| 321 |         /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */ | 
|---|
| 322 |         virtual uint8 getRenderQueueGroup(void) const; | 
|---|
| 323 |  | 
|---|
| 324 |                 /// return the full transformation of the parent sceneNode or the attachingPoint node | 
|---|
| 325 |                 virtual const Matrix4& _getParentNodeFullTransform(void) const; | 
|---|
| 326 |  | 
|---|
| 327 |         /** Sets the query flags for this object. | 
|---|
| 328 |         @remarks | 
|---|
| 329 |             When performing a scene query, this object will be included or excluded according | 
|---|
| 330 |             to flags on the object and flags on the query. This is a bitwise value, so only when | 
|---|
| 331 |             a bit on these flags is set, will it be included in a query asking for that flag. The | 
|---|
| 332 |             meaning of the bits is application-specific. | 
|---|
| 333 |         */ | 
|---|
| 334 |         virtual void setQueryFlags(uint32 flags) { mQueryFlags = flags; } | 
|---|
| 335 |  | 
|---|
| 336 |         /** As setQueryFlags, except the flags passed as parameters are appended to the | 
|---|
| 337 |         existing flags on this object. */ | 
|---|
| 338 |         virtual void addQueryFlags(uint32 flags) { mQueryFlags |= flags; } | 
|---|
| 339 |              | 
|---|
| 340 |         /** As setQueryFlags, except the flags passed as parameters are removed from the | 
|---|
| 341 |         existing flags on this object. */ | 
|---|
| 342 |         virtual void removeQueryFlags(unsigned long flags) { mQueryFlags &= ~flags; } | 
|---|
| 343 |          | 
|---|
| 344 |         /// Returns the query flags relevant for this object | 
|---|
| 345 |         virtual uint32 getQueryFlags(void) const { return mQueryFlags; } | 
|---|
| 346 |  | 
|---|
| 347 |                 /** Set the default query flags for all future MovableObject instances. | 
|---|
| 348 |                 */ | 
|---|
| 349 |                 static void setDefaultQueryFlags(uint32 flags) { msDefaultQueryFlags = flags; } | 
|---|
| 350 |  | 
|---|
| 351 |                 /** Get the default query flags for all future MovableObject instances. | 
|---|
| 352 |                 */ | 
|---|
| 353 |                 static uint32 getDefaultQueryFlags() { return msDefaultQueryFlags; } | 
|---|
| 354 |  | 
|---|
| 355 |                  | 
|---|
| 356 |         /** Sets the visiblity flags for this object. | 
|---|
| 357 |         @remarks | 
|---|
| 358 |                         As well as a simple true/false value for visibility (as seen in setVisible),  | 
|---|
| 359 |                         you can also set visiblity flags which when 'and'ed with the SceneManager's | 
|---|
| 360 |                         visibility mask can also make an object invisible. | 
|---|
| 361 |         */ | 
|---|
| 362 |         virtual void setVisibilityFlags(uint32 flags) { mVisibilityFlags = flags; } | 
|---|
| 363 |  | 
|---|
| 364 |         /** As setVisibilityFlags, except the flags passed as parameters are appended to the | 
|---|
| 365 |         existing flags on this object. */ | 
|---|
| 366 |         virtual void addVisibilityFlags(uint32 flags) { mVisibilityFlags |= flags; } | 
|---|
| 367 |              | 
|---|
| 368 |         /** As setVisibilityFlags, except the flags passed as parameters are removed from the | 
|---|
| 369 |         existing flags on this object. */ | 
|---|
| 370 |         virtual void removeVisibilityFlags(uint32 flags) { mVisibilityFlags &= ~flags; } | 
|---|
| 371 |          | 
|---|
| 372 |         /// Returns the visibility flags relevant for this object | 
|---|
| 373 |         virtual uint32 getVisibilityFlags(void) const { return mVisibilityFlags; } | 
|---|
| 374 |  | 
|---|
| 375 |                 /** Set the default visibility flags for all future MovableObject instances. | 
|---|
| 376 |                 */ | 
|---|
| 377 |                 static void setDefaultVisibilityFlags(uint32 flags) { msDefaultVisibilityFlags = flags; } | 
|---|
| 378 |                  | 
|---|
| 379 |                 /** Get the default visibility flags for all future MovableObject instances. | 
|---|
| 380 |                 */ | 
|---|
| 381 |                 static uint32 getDefaultVisibilityFlags() { return msDefaultVisibilityFlags; } | 
|---|
| 382 |  | 
|---|
| 383 |         /** Sets a listener for this object. | 
|---|
| 384 |         @remarks | 
|---|
| 385 |             Note for size and performance reasons only one listener per object | 
|---|
| 386 |             is allowed. | 
|---|
| 387 |         */ | 
|---|
| 388 |         virtual void setListener(Listener* listener) { mListener = listener; } | 
|---|
| 389 |  | 
|---|
| 390 |         /** Gets the current listener for this object. | 
|---|
| 391 |         */ | 
|---|
| 392 |         virtual Listener* getListener(void) const { return mListener; } | 
|---|
| 393 |  | 
|---|
| 394 |         /** Gets a list of lights, ordered relative to how close they are to this movable object. | 
|---|
| 395 |         @remarks | 
|---|
| 396 |             By default, this method gives the listener a chance to populate light list first, | 
|---|
| 397 |             if there is no listener or Listener::objectQueryLights returns NULL, it'll | 
|---|
| 398 |             query the light list from parent entity if it is present, or returns | 
|---|
| 399 |             SceneNode::findLights if it has parent scene node, otherwise it just returns | 
|---|
| 400 |             an empty list. | 
|---|
| 401 |         @par | 
|---|
| 402 |             The object internally caches the light list, so it will recalculate | 
|---|
| 403 |                         it only when object is moved, or lights that affect the frustum have | 
|---|
| 404 |                         been changed (@see SceneManager::_getLightsDirtyCounter), | 
|---|
| 405 |             but if listener exists, it will be called each time, so the listener  | 
|---|
| 406 |                         should implement their own cache mechanism to optimise performance. | 
|---|
| 407 |         @par | 
|---|
| 408 |             This method can be useful when implementing Renderable::getLights in case | 
|---|
| 409 |             the renderable is a part of the movable. | 
|---|
| 410 |         @returns The list of lights use to lighting this object. | 
|---|
| 411 |         */ | 
|---|
| 412 |         virtual const LightList& queryLights(void) const; | 
|---|
| 413 |  | 
|---|
| 414 |                 /// Define a default implementation of method from ShadowCaster which implements no shadows | 
|---|
| 415 |         EdgeData* getEdgeList(void) { return NULL; } | 
|---|
| 416 |                 /// Define a default implementation of method from ShadowCaster which implements no shadows | 
|---|
| 417 |                 bool hasEdgeList(void) { return false; } | 
|---|
| 418 |         /// Define a default implementation of method from ShadowCaster which implements no shadows | 
|---|
| 419 |         ShadowRenderableListIterator getShadowVolumeRenderableIterator( | 
|---|
| 420 |             ShadowTechnique shadowTechnique, const Light* light,  | 
|---|
| 421 |             HardwareIndexBufferSharedPtr* indexBuffer,  | 
|---|
| 422 |             bool extrudeVertices, Real extrusionDist, unsigned long flags = 0); | 
|---|
| 423 |                  | 
|---|
| 424 |         /** Overridden member from ShadowCaster. */ | 
|---|
| 425 |         const AxisAlignedBox& getLightCapBounds(void) const; | 
|---|
| 426 |         /** Overridden member from ShadowCaster. */ | 
|---|
| 427 |         const AxisAlignedBox& getDarkCapBounds(const Light& light, Real dirLightExtrusionDist) const; | 
|---|
| 428 |         /** Sets whether or not this object will cast shadows. | 
|---|
| 429 |         @remarks | 
|---|
| 430 |         This setting simply allows you to turn on/off shadows for a given object. | 
|---|
| 431 |         An object will not cast shadows unless the scene supports it in any case | 
|---|
| 432 |         (see SceneManager::setShadowTechnique), and also the material which is | 
|---|
| 433 |         in use must also have shadow casting enabled. By default all entities cast | 
|---|
| 434 |         shadows. If, however, for some reason you wish to disable this for a single  | 
|---|
| 435 |         object then you can do so using this method. | 
|---|
| 436 |         @note This method normally refers to objects which block the light, but | 
|---|
| 437 |         since Light is also a subclass of MovableObject, in that context it means | 
|---|
| 438 |         whether the light causes shadows itself. | 
|---|
| 439 |         */ | 
|---|
| 440 |         void setCastShadows(bool enabled) { mCastShadows = enabled; } | 
|---|
| 441 |         /** Returns whether shadow casting is enabled for this object. */ | 
|---|
| 442 |         bool getCastShadows(void) const { return mCastShadows; } | 
|---|
| 443 |         /** Get the distance to extrude for a point/spot light */ | 
|---|
| 444 |         Real getPointExtrusionDistance(const Light* l) const; | 
|---|
| 445 |                 /** Get the 'type flags' for this MovableObject. | 
|---|
| 446 |                 @remarks | 
|---|
| 447 |                         A type flag identifies the type of the MovableObject as a bitpattern.  | 
|---|
| 448 |                         This is used for categorical inclusion / exclusion in SceneQuery | 
|---|
| 449 |                         objects. By default, this method returns all ones for objects not  | 
|---|
| 450 |                         created by a MovableObjectFactory (hence always including them);  | 
|---|
| 451 |                         otherwise it returns the value assigned to the MovableObjectFactory. | 
|---|
| 452 |                         Custom objects which don't use MovableObjectFactory will need to  | 
|---|
| 453 |                         override this if they want to be included in queries. | 
|---|
| 454 |                 */ | 
|---|
| 455 |                 virtual uint32 getTypeFlags(void) const; | 
|---|
| 456 |  | 
|---|
| 457 |  | 
|---|
| 458 |  | 
|---|
| 459 |  | 
|---|
| 460 |  | 
|---|
| 461 |     }; | 
|---|
| 462 |  | 
|---|
| 463 |         /** Interface definition for a factory class which produces a certain | 
|---|
| 464 |                 kind of MovableObject, and can be registered with Root in order | 
|---|
| 465 |                 to allow all clients to produce new instances of this object, integrated | 
|---|
| 466 |                 with the standard Ogre processing. | 
|---|
| 467 |         */ | 
|---|
| 468 |         class _OgreExport MovableObjectFactory  | 
|---|
| 469 |         { | 
|---|
| 470 |         protected: | 
|---|
| 471 |                 /// Type flag, allocated if requested | 
|---|
| 472 |                 unsigned long mTypeFlag; | 
|---|
| 473 |  | 
|---|
| 474 |                 /// Internal implementation of create method - must be overridden | 
|---|
| 475 |                 virtual MovableObject* createInstanceImpl( | 
|---|
| 476 |                         const String& name, const NameValuePairList* params = 0) = 0; | 
|---|
| 477 |         public: | 
|---|
| 478 |                 MovableObjectFactory() : mTypeFlag(0xFFFFFFFF) {} | 
|---|
| 479 |                 virtual ~MovableObjectFactory() {} | 
|---|
| 480 |                 /// Get the type of the object to be created | 
|---|
| 481 |                 virtual const String& getType(void) const = 0; | 
|---|
| 482 |  | 
|---|
| 483 |                 /** Create a new instance of the object. | 
|---|
| 484 |                 @param name The name of the new object | 
|---|
| 485 |                 @param manager The SceneManager instance that will be holding the | 
|---|
| 486 |                         instance once created. | 
|---|
| 487 |                 @param params Name/value pair list of additional parameters required to  | 
|---|
| 488 |                         construct the object (defined per subtype). Optional. | 
|---|
| 489 |                 */ | 
|---|
| 490 |                 virtual MovableObject* createInstance( | 
|---|
| 491 |                         const String& name, SceneManager* manager,  | 
|---|
| 492 |                         const NameValuePairList* params = 0); | 
|---|
| 493 |                 /** Destroy an instance of the object */ | 
|---|
| 494 |                 virtual void destroyInstance(MovableObject* obj) = 0; | 
|---|
| 495 |  | 
|---|
| 496 |                 /** Does this factory require the allocation of a 'type flag', used to  | 
|---|
| 497 |                         selectively include / exclude this type from scene queries? | 
|---|
| 498 |                 @remarks | 
|---|
| 499 |                         The default implementation here is to return 'false', ie not to  | 
|---|
| 500 |                         request a unique type mask from Root. For objects that | 
|---|
| 501 |                         never need to be excluded in SceneQuery results, that's fine, since | 
|---|
| 502 |                         the default implementation of MovableObject::getTypeFlags is to return | 
|---|
| 503 |                         all ones, hence matching any query type mask. However, if you want the | 
|---|
| 504 |                         objects created by this factory to be filterable by queries using a  | 
|---|
| 505 |                         broad type, you have to give them a (preferably unique) type mask -  | 
|---|
| 506 |                         and given that you don't know what other MovableObject types are  | 
|---|
| 507 |                         registered, Root will allocate you one.  | 
|---|
| 508 |                 */ | 
|---|
| 509 |                 virtual bool requestTypeFlags(void) const { return false; } | 
|---|
| 510 |                 /** Notify this factory of the type mask to apply.  | 
|---|
| 511 |                 @remarks | 
|---|
| 512 |                         This should normally only be called by Root in response to | 
|---|
| 513 |                         a 'true' result from requestTypeMask. However, you can actually use | 
|---|
| 514 |                         it yourself if you're careful; for example to assign the same mask | 
|---|
| 515 |                         to a number of different types of object, should you always wish them | 
|---|
| 516 |                         to be treated the same in queries. | 
|---|
| 517 |                 */ | 
|---|
| 518 |                 void _notifyTypeFlags(unsigned long flag) { mTypeFlag = flag; } | 
|---|
| 519 |  | 
|---|
| 520 |                 /** Gets the type flag for this factory. | 
|---|
| 521 |                 @remarks | 
|---|
| 522 |                         A type flag is like a query flag, except that it applies to all instances | 
|---|
| 523 |                         of a certain type of object. | 
|---|
| 524 |                 */ | 
|---|
| 525 |                 unsigned long getTypeFlags(void) const { return mTypeFlag; } | 
|---|
| 526 |  | 
|---|
| 527 |         }; | 
|---|
| 528 |  | 
|---|
| 529 | } | 
|---|
| 530 | #endif | 
|---|