[148] | 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-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE SOFTWARE. |
---|
| 26 | ----------------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef __MovableObject_H__ |
---|
| 30 | #define __MovableObject_H__ |
---|
| 31 | |
---|
| 32 | // Precompiler options |
---|
| 33 | #include "OgrePrerequisites.h" |
---|
| 34 | #include "OgreRenderQueue.h" |
---|
| 35 | #include "OgreAxisAlignedBox.h" |
---|
| 36 | #include "OgreSphere.h" |
---|
| 37 | #include "OgreShadowCaster.h" |
---|
| 38 | #include "OgreFactoryObj.h" |
---|
| 39 | #include "OgreAnimable.h" |
---|
| 40 | #include "OgreAny.h" |
---|
| 41 | #include "OgreUserObjectBindings.h" |
---|
| 42 | #include "OgreHeaderPrefix.h" |
---|
| 43 | |
---|
| 44 | namespace Ogre { |
---|
| 45 | |
---|
| 46 | // Forward declaration |
---|
| 47 | class MovableObjectFactory; |
---|
| 48 | |
---|
| 49 | /** \addtogroup Core |
---|
| 50 | * @{ |
---|
| 51 | */ |
---|
| 52 | /** \addtogroup Scene |
---|
| 53 | * @{ |
---|
| 54 | */ |
---|
| 55 | /** Abstract class defining a movable object in a scene. |
---|
| 56 | @remarks |
---|
| 57 | Instances of this class are discrete, relatively small, movable objects |
---|
| 58 | which are attached to SceneNode objects to define their position. |
---|
| 59 | */ |
---|
| 60 | class _OgreExport MovableObject : public ShadowCaster, public AnimableObject, public MovableAlloc |
---|
| 61 | { |
---|
| 62 | public: |
---|
| 63 | /** Listener which gets called back on MovableObject events. |
---|
| 64 | */ |
---|
| 65 | class _OgreExport Listener |
---|
| 66 | { |
---|
| 67 | public: |
---|
| 68 | Listener(void) {} |
---|
| 69 | virtual ~Listener() {} |
---|
| 70 | /** MovableObject is being destroyed */ |
---|
| 71 | virtual void objectDestroyed(MovableObject*) {} |
---|
| 72 | /** MovableObject has been attached to a node */ |
---|
| 73 | virtual void objectAttached(MovableObject*) {} |
---|
| 74 | /** MovableObject has been detached from a node */ |
---|
| 75 | virtual void objectDetached(MovableObject*) {} |
---|
| 76 | /** MovableObject has been moved */ |
---|
| 77 | virtual void objectMoved(MovableObject*) {} |
---|
| 78 | /** Called when the movable object of the camera to be used for rendering. |
---|
| 79 | @return |
---|
| 80 | true if allows queue for rendering, false otherwise. |
---|
| 81 | */ |
---|
| 82 | virtual bool objectRendering(const MovableObject*, const Camera*) { return true; } |
---|
| 83 | /** Called when the movable object needs to query a light list. |
---|
| 84 | @remarks |
---|
| 85 | If you want to customize light finding for this object, you should override |
---|
| 86 | this method and hook into MovableObject via MovableObject::setListener. |
---|
| 87 | Be aware that the default method caches results within a frame to |
---|
| 88 | prevent unnecessary recalculation, so if you override this you |
---|
| 89 | should provide your own caching to maintain performance. |
---|
| 90 | @note |
---|
| 91 | If you use texture shadows, there is an additional restriction - |
---|
| 92 | since the lights which should have shadow textures rendered for |
---|
| 93 | them are determined based on the entire frustum, and not per-object, |
---|
| 94 | it is important that the lights returned at the start of this |
---|
| 95 | list (up to the number of shadow textures available) are the same |
---|
| 96 | lights that were used to generate the shadow textures, |
---|
| 97 | and they are in the same order (particularly for additive effects). |
---|
| 98 | @note |
---|
| 99 | This method will not be called for additive stencil shadows since the |
---|
| 100 | light list cannot be varied per object with this technique. |
---|
| 101 | @return |
---|
| 102 | A pointer to a light list if you populated the light list yourself, or |
---|
| 103 | NULL to fall back on the default finding process. |
---|
| 104 | */ |
---|
| 105 | virtual const LightList* objectQueryLights(const MovableObject*) { return 0; } |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | protected: |
---|
| 109 | /// Name of this object |
---|
| 110 | String mName; |
---|
| 111 | /// Creator of this object (if created by a factory) |
---|
| 112 | MovableObjectFactory* mCreator; |
---|
| 113 | /// SceneManager holding this object (if applicable) |
---|
| 114 | SceneManager* mManager; |
---|
| 115 | /// node to which this object is attached |
---|
| 116 | Node* mParentNode; |
---|
| 117 | bool mParentIsTagPoint; |
---|
| 118 | /// Is this object visible? |
---|
| 119 | bool mVisible; |
---|
| 120 | /// Is debug display enabled? |
---|
| 121 | bool mDebugDisplay; |
---|
| 122 | /// Upper distance to still render |
---|
| 123 | Real mUpperDistance; |
---|
| 124 | Real mSquaredUpperDistance; |
---|
| 125 | // Minimum pixel size to still render |
---|
| 126 | Real mMinPixelSize; |
---|
| 127 | /// Hidden because of distance? |
---|
| 128 | bool mBeyondFarDistance; |
---|
| 129 | /// User objects binding. |
---|
| 130 | UserObjectBindings mUserObjectBindings; |
---|
| 131 | /// The render queue to use when rendering this object |
---|
| 132 | uint8 mRenderQueueID; |
---|
| 133 | /// Flags whether the RenderQueue's default should be used. |
---|
| 134 | bool mRenderQueueIDSet; |
---|
| 135 | /// The render queue group to use when rendering this object |
---|
| 136 | ushort mRenderQueuePriority; |
---|
| 137 | /// Flags whether the RenderQueue's default should be used. |
---|
| 138 | bool mRenderQueuePrioritySet; |
---|
| 139 | /// Flags determining whether this object is included / excluded from scene queries |
---|
| 140 | uint32 mQueryFlags; |
---|
| 141 | /// Flags determining whether this object is visible (compared to SceneManager mask) |
---|
| 142 | uint32 mVisibilityFlags; |
---|
| 143 | /// Cached world AABB of this object |
---|
| 144 | mutable AxisAlignedBox mWorldAABB; |
---|
| 145 | // Cached world bounding sphere |
---|
| 146 | mutable Sphere mWorldBoundingSphere; |
---|
| 147 | /// World space AABB of this object's dark cap |
---|
| 148 | mutable AxisAlignedBox mWorldDarkCapBounds; |
---|
| 149 | /// Does this object cast shadows? |
---|
| 150 | bool mCastShadows; |
---|
| 151 | |
---|
| 152 | /// Does rendering this object disabled by listener? |
---|
| 153 | bool mRenderingDisabled; |
---|
| 154 | /// MovableObject listener - only one allowed (no list) for size & performance reasons. */ |
---|
| 155 | Listener* mListener; |
---|
| 156 | |
---|
| 157 | /// List of lights for this object |
---|
| 158 | mutable LightList mLightList; |
---|
| 159 | /// The last frame that this light list was updated in |
---|
| 160 | mutable ulong mLightListUpdated; |
---|
| 161 | |
---|
| 162 | /// the light mask defined for this movable. This will be taken into consideration when deciding which light should affect this movable |
---|
| 163 | uint32 mLightMask; |
---|
| 164 | |
---|
| 165 | // Static members |
---|
| 166 | /// Default query flags |
---|
| 167 | static uint32 msDefaultQueryFlags; |
---|
| 168 | /// Default visibility flags |
---|
| 169 | static uint32 msDefaultVisibilityFlags; |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | public: |
---|
| 174 | /// Constructor |
---|
| 175 | MovableObject(); |
---|
| 176 | |
---|
| 177 | /// Named constructor |
---|
| 178 | MovableObject(const String& name); |
---|
| 179 | /** Virtual destructor - read Scott Meyers if you don't know why this is needed. |
---|
| 180 | */ |
---|
| 181 | virtual ~MovableObject(); |
---|
| 182 | |
---|
| 183 | /** Notify the object of it's creator (internal use only) */ |
---|
| 184 | virtual void _notifyCreator(MovableObjectFactory* fact) { mCreator = fact; } |
---|
| 185 | /** Get the creator of this object, if any (internal use only) */ |
---|
| 186 | virtual MovableObjectFactory* _getCreator(void) const { return mCreator; } |
---|
| 187 | /** Notify the object of it's manager (internal use only) */ |
---|
| 188 | virtual void _notifyManager(SceneManager* man) { mManager = man; } |
---|
| 189 | /** Get the manager of this object, if any (internal use only) */ |
---|
| 190 | virtual SceneManager* _getManager(void) const { return mManager; } |
---|
| 191 | |
---|
| 192 | /** Returns the name of this object. */ |
---|
| 193 | virtual const String& getName(void) const { return mName; } |
---|
| 194 | |
---|
| 195 | /** Returns the type name of this object. */ |
---|
| 196 | virtual const String& getMovableType(void) const = 0; |
---|
| 197 | |
---|
| 198 | /** Returns the node to which this object is attached. |
---|
| 199 | @remarks |
---|
| 200 | A MovableObject may be attached to either a SceneNode or to a TagPoint, |
---|
| 201 | the latter case if it's attached to a bone on an animated entity. |
---|
| 202 | Both are Node subclasses so this method will return either. |
---|
| 203 | */ |
---|
| 204 | virtual Node* getParentNode(void) const; |
---|
| 205 | |
---|
| 206 | /** Returns the scene node to which this object is attached. |
---|
| 207 | @remarks |
---|
| 208 | A MovableObject may be attached to either a SceneNode or to a TagPoint, |
---|
| 209 | the latter case if it's attached to a bone on an animated entity. |
---|
| 210 | This method will return the scene node of the parent entity |
---|
| 211 | if the latter is true. |
---|
| 212 | */ |
---|
| 213 | virtual SceneNode* getParentSceneNode(void) const; |
---|
| 214 | |
---|
| 215 | /// Gets whether the parent node is a TagPoint (or a SceneNode) |
---|
| 216 | virtual bool isParentTagPoint() const { return mParentIsTagPoint; } |
---|
| 217 | |
---|
| 218 | /** Internal method called to notify the object that it has been attached to a node. |
---|
| 219 | */ |
---|
| 220 | virtual void _notifyAttached(Node* parent, bool isTagPoint = false); |
---|
| 221 | |
---|
| 222 | /** Returns true if this object is attached to a SceneNode or TagPoint. */ |
---|
| 223 | virtual bool isAttached(void) const; |
---|
| 224 | |
---|
| 225 | /** Detaches an object from a parent SceneNode or TagPoint, if attached. */ |
---|
| 226 | virtual void detachFromParent(void); |
---|
| 227 | |
---|
| 228 | /** Returns true if this object is attached to a SceneNode or TagPoint, |
---|
| 229 | and this SceneNode / TagPoint is currently in an active part of the |
---|
| 230 | scene graph. */ |
---|
| 231 | virtual bool isInScene(void) const; |
---|
| 232 | |
---|
| 233 | /** Internal method called to notify the object that it has been moved. |
---|
| 234 | */ |
---|
| 235 | virtual void _notifyMoved(void); |
---|
| 236 | |
---|
| 237 | /** Internal method to notify the object of the camera to be used for the next rendering operation. |
---|
| 238 | @remarks |
---|
| 239 | Certain objects may want to do specific processing based on the camera position. This method notifies |
---|
| 240 | them in case they wish to do this. |
---|
| 241 | */ |
---|
| 242 | virtual void _notifyCurrentCamera(Camera* cam); |
---|
| 243 | |
---|
| 244 | /** Retrieves the local axis-aligned bounding box for this object. |
---|
| 245 | @remarks |
---|
| 246 | This bounding box is in local coordinates. |
---|
| 247 | */ |
---|
| 248 | virtual const AxisAlignedBox& getBoundingBox(void) const = 0; |
---|
| 249 | |
---|
| 250 | /** Retrieves the radius of the origin-centered bounding sphere |
---|
| 251 | for this object. |
---|
| 252 | */ |
---|
| 253 | virtual Real getBoundingRadius(void) const = 0; |
---|
| 254 | |
---|
| 255 | /** Retrieves the axis-aligned bounding box for this object in world coordinates. */ |
---|
| 256 | virtual const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const; |
---|
| 257 | /** Retrieves the worldspace bounding sphere for this object. */ |
---|
| 258 | virtual const Sphere& getWorldBoundingSphere(bool derive = false) const; |
---|
| 259 | /** Internal method by which the movable object must add Renderable subclass instances to the rendering queue. |
---|
| 260 | @remarks |
---|
| 261 | The engine will call this method when this object is to be rendered. The object must then create one or more |
---|
| 262 | Renderable subclass instances which it places on the passed in Queue for rendering. |
---|
| 263 | */ |
---|
| 264 | virtual void _updateRenderQueue(RenderQueue* queue) = 0; |
---|
| 265 | |
---|
| 266 | /** Tells this object whether to be visible or not, if it has a renderable component. |
---|
| 267 | @note An alternative approach of making an object invisible is to detach it |
---|
| 268 | from it's SceneNode, or to remove the SceneNode entirely. |
---|
| 269 | Detaching a node means that structurally the scene graph changes. |
---|
| 270 | Once this change has taken place, the objects / nodes that have been |
---|
| 271 | removed have less overhead to the visibility detection pass than simply |
---|
| 272 | making the object invisible, so if you do this and leave the objects |
---|
| 273 | out of the tree for a long time, it's faster. However, the act of |
---|
| 274 | detaching / reattaching nodes is in itself more expensive than |
---|
| 275 | setting an object visibility flag, since in the latter case |
---|
| 276 | structural changes are not made. Therefore, small or frequent visibility |
---|
| 277 | changes are best done using this method; large or more longer term |
---|
| 278 | changes are best done by detaching. |
---|
| 279 | */ |
---|
| 280 | virtual void setVisible(bool visible); |
---|
| 281 | |
---|
| 282 | /** Gets this object whether to be visible or not, if it has a renderable component. |
---|
| 283 | @remarks |
---|
| 284 | Returns the value set by MovableObject::setVisible only. |
---|
| 285 | */ |
---|
| 286 | virtual bool getVisible(void) const; |
---|
| 287 | |
---|
| 288 | /** Returns whether or not this object is supposed to be visible or not. |
---|
| 289 | @remarks |
---|
| 290 | Takes into account both upper rendering distance and visible flag. |
---|
| 291 | */ |
---|
| 292 | virtual bool isVisible(void) const; |
---|
| 293 | |
---|
| 294 | /** Sets the distance at which the object is no longer rendered. |
---|
| 295 | @note Camera::setUseRenderingDistance() needs to be called for this parameter to be used. |
---|
| 296 | @param dist Distance beyond which the object will not be rendered |
---|
| 297 | (the default is 0, which means objects are always rendered). |
---|
| 298 | */ |
---|
| 299 | virtual void setRenderingDistance(Real dist) { |
---|
| 300 | mUpperDistance = dist; |
---|
| 301 | mSquaredUpperDistance = mUpperDistance * mUpperDistance; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /** Gets the distance at which batches are no longer rendered. */ |
---|
| 305 | virtual Real getRenderingDistance(void) const { return mUpperDistance; } |
---|
| 306 | |
---|
| 307 | /** Sets the minimum pixel size an object needs to be in both screen axes in order to be rendered |
---|
| 308 | @note Camera::setUseMinPixelSize() needs to be called for this parameter to be used. |
---|
| 309 | @param pixelSize Number of minimum pixels |
---|
| 310 | (the default is 0, which means objects are always rendered). |
---|
| 311 | */ |
---|
| 312 | virtual void setRenderingMinPixelSize(Real pixelSize) { |
---|
| 313 | mMinPixelSize = pixelSize; |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | /** Returns the minimum pixel size an object needs to be in both screen axes in order to be rendered |
---|
| 317 | */ |
---|
| 318 | virtual Real getRenderingMinPixelSize() const { |
---|
| 319 | return mMinPixelSize; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | /** @deprecated use UserObjectBindings::setUserAny via getUserObjectBindings() instead. |
---|
| 323 | Sets any kind of user value on this object. |
---|
| 324 | @remarks |
---|
| 325 | This method allows you to associate any user value you like with |
---|
| 326 | this MovableObject. This can be a pointer back to one of your own |
---|
| 327 | classes for instance. |
---|
| 328 | */ |
---|
| 329 | OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); } |
---|
| 330 | |
---|
| 331 | /** @deprecated use UserObjectBindings::getUserAny via getUserObjectBindings() instead. |
---|
| 332 | Retrieves the custom user value associated with this object. |
---|
| 333 | */ |
---|
| 334 | OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); } |
---|
| 335 | |
---|
| 336 | /** Return an instance of user objects binding associated with this class. |
---|
| 337 | You can use it to associate one or more custom objects with this class instance. |
---|
| 338 | @see UserObjectBindings::setUserAny. |
---|
| 339 | */ |
---|
| 340 | UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; } |
---|
| 341 | |
---|
| 342 | /** Return an instance of user objects binding associated with this class. |
---|
| 343 | You can use it to associate one or more custom objects with this class instance. |
---|
| 344 | @see UserObjectBindings::setUserAny. |
---|
| 345 | */ |
---|
| 346 | const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; } |
---|
| 347 | |
---|
| 348 | /** Sets the render queue group this entity will be rendered through. |
---|
| 349 | @remarks |
---|
| 350 | Render queues are grouped to allow you to more tightly control the ordering |
---|
| 351 | of rendered objects. If you do not call this method, all Entity objects default |
---|
| 352 | to the default queue (RenderQueue::getDefaultQueueGroup), which is fine for most objects. You may want to alter this |
---|
| 353 | if you want this entity to always appear in front of other objects, e.g. for |
---|
| 354 | a 3D menu system or such. |
---|
| 355 | @par |
---|
| 356 | See RenderQueue for more details. |
---|
| 357 | @param queueID Enumerated value of the queue group to use. See the |
---|
| 358 | enum RenderQueueGroupID for what kind of values can be used here. |
---|
| 359 | */ |
---|
| 360 | virtual void setRenderQueueGroup(uint8 queueID); |
---|
| 361 | |
---|
| 362 | /** Sets the render queue group and group priority this entity will be rendered through. |
---|
| 363 | @remarks |
---|
| 364 | Render queues are grouped to allow you to more tightly control the ordering |
---|
| 365 | of rendered objects. Within a single render group there another type of grouping |
---|
| 366 | called priority which allows further control. If you do not call this method, |
---|
| 367 | all Entity objects default to the default queue and priority |
---|
| 368 | (RenderQueue::getDefaultQueueGroup, RenderQueue::getDefaultRenderablePriority), |
---|
| 369 | which is fine for most objects. You may want to alter this if you want this entity |
---|
| 370 | to always appear in front of other objects, e.g. for a 3D menu system or such. |
---|
| 371 | @par |
---|
| 372 | See RenderQueue for more details. |
---|
| 373 | @param queueID Enumerated value of the queue group to use. See the |
---|
| 374 | enum RenderQueueGroupID for what kind of values can be used here. |
---|
| 375 | @param priority The priority within a group to use. |
---|
| 376 | */ |
---|
| 377 | virtual void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority); |
---|
| 378 | |
---|
| 379 | /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */ |
---|
| 380 | virtual uint8 getRenderQueueGroup(void) const; |
---|
| 381 | |
---|
| 382 | /// return the full transformation of the parent sceneNode or the attachingPoint node |
---|
| 383 | virtual const Matrix4& _getParentNodeFullTransform(void) const; |
---|
| 384 | |
---|
| 385 | /** Sets the query flags for this object. |
---|
| 386 | @remarks |
---|
| 387 | When performing a scene query, this object will be included or excluded according |
---|
| 388 | to flags on the object and flags on the query. This is a bitwise value, so only when |
---|
| 389 | a bit on these flags is set, will it be included in a query asking for that flag. The |
---|
| 390 | meaning of the bits is application-specific. |
---|
| 391 | */ |
---|
| 392 | virtual void setQueryFlags(uint32 flags) { mQueryFlags = flags; } |
---|
| 393 | |
---|
| 394 | /** As setQueryFlags, except the flags passed as parameters are appended to the |
---|
| 395 | existing flags on this object. */ |
---|
| 396 | virtual void addQueryFlags(uint32 flags) { mQueryFlags |= flags; } |
---|
| 397 | |
---|
| 398 | /** As setQueryFlags, except the flags passed as parameters are removed from the |
---|
| 399 | existing flags on this object. */ |
---|
| 400 | virtual void removeQueryFlags(uint32 flags) { mQueryFlags &= ~flags; } |
---|
| 401 | |
---|
| 402 | /// Returns the query flags relevant for this object |
---|
| 403 | virtual uint32 getQueryFlags(void) const { return mQueryFlags; } |
---|
| 404 | |
---|
| 405 | /** Set the default query flags for all future MovableObject instances. |
---|
| 406 | */ |
---|
| 407 | static void setDefaultQueryFlags(uint32 flags) { msDefaultQueryFlags = flags; } |
---|
| 408 | |
---|
| 409 | /** Get the default query flags for all future MovableObject instances. |
---|
| 410 | */ |
---|
| 411 | static uint32 getDefaultQueryFlags() { return msDefaultQueryFlags; } |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | /** Sets the visibility flags for this object. |
---|
| 415 | @remarks |
---|
| 416 | As well as a simple true/false value for visibility (as seen in setVisible), |
---|
| 417 | you can also set visibility flags which when 'and'ed with the SceneManager's |
---|
| 418 | visibility mask can also make an object invisible. |
---|
| 419 | */ |
---|
| 420 | virtual void setVisibilityFlags(uint32 flags) { mVisibilityFlags = flags; } |
---|
| 421 | |
---|
| 422 | /** As setVisibilityFlags, except the flags passed as parameters are appended to the |
---|
| 423 | existing flags on this object. */ |
---|
| 424 | virtual void addVisibilityFlags(uint32 flags) { mVisibilityFlags |= flags; } |
---|
| 425 | |
---|
| 426 | /** As setVisibilityFlags, except the flags passed as parameters are removed from the |
---|
| 427 | existing flags on this object. */ |
---|
| 428 | virtual void removeVisibilityFlags(uint32 flags) { mVisibilityFlags &= ~flags; } |
---|
| 429 | |
---|
| 430 | /// Returns the visibility flags relevant for this object |
---|
| 431 | virtual uint32 getVisibilityFlags(void) const { return mVisibilityFlags; } |
---|
| 432 | |
---|
| 433 | /** Set the default visibility flags for all future MovableObject instances. |
---|
| 434 | */ |
---|
| 435 | static void setDefaultVisibilityFlags(uint32 flags) { msDefaultVisibilityFlags = flags; } |
---|
| 436 | |
---|
| 437 | /** Get the default visibility flags for all future MovableObject instances. |
---|
| 438 | */ |
---|
| 439 | static uint32 getDefaultVisibilityFlags() { return msDefaultVisibilityFlags; } |
---|
| 440 | |
---|
| 441 | /** Sets a listener for this object. |
---|
| 442 | @remarks |
---|
| 443 | Note for size and performance reasons only one listener per object |
---|
| 444 | is allowed. |
---|
| 445 | */ |
---|
| 446 | virtual void setListener(Listener* listener) { mListener = listener; } |
---|
| 447 | |
---|
| 448 | /** Gets the current listener for this object. |
---|
| 449 | */ |
---|
| 450 | virtual Listener* getListener(void) const { return mListener; } |
---|
| 451 | |
---|
| 452 | /** Gets a list of lights, ordered relative to how close they are to this movable object. |
---|
| 453 | @remarks |
---|
| 454 | By default, this method gives the listener a chance to populate light list first, |
---|
| 455 | if there is no listener or Listener::objectQueryLights returns NULL, it'll |
---|
| 456 | query the light list from parent entity if it is present, or returns |
---|
| 457 | SceneNode::findLights if it has parent scene node, otherwise it just returns |
---|
| 458 | an empty list. |
---|
| 459 | @par |
---|
| 460 | The object internally caches the light list, so it will recalculate |
---|
| 461 | it only when object is moved, or lights that affect the frustum have |
---|
| 462 | been changed (@see SceneManager::_getLightsDirtyCounter), |
---|
| 463 | but if listener exists, it will be called each time, so the listener |
---|
| 464 | should implement their own cache mechanism to optimise performance. |
---|
| 465 | @par |
---|
| 466 | This method can be useful when implementing Renderable::getLights in case |
---|
| 467 | the renderable is a part of the movable. |
---|
| 468 | @return The list of lights use to lighting this object. |
---|
| 469 | */ |
---|
| 470 | virtual const LightList& queryLights(void) const; |
---|
| 471 | |
---|
| 472 | /** Get a bitwise mask which will filter the lights affecting this object |
---|
| 473 | @remarks |
---|
| 474 | By default, this mask is fully set meaning all lights will affect this object |
---|
| 475 | */ |
---|
| 476 | virtual uint32 getLightMask()const { return mLightMask; } |
---|
| 477 | /** Set a bitwise mask which will filter the lights affecting this object |
---|
| 478 | @remarks |
---|
| 479 | This mask will be compared against the mask held against Light to determine |
---|
| 480 | if a light should affect a given object. |
---|
| 481 | By default, this mask is fully set meaning all lights will affect this object |
---|
| 482 | */ |
---|
| 483 | virtual void setLightMask(uint32 lightMask); |
---|
| 484 | |
---|
| 485 | /** Returns a pointer to the current list of lights for this object. |
---|
| 486 | @remarks |
---|
| 487 | You should not modify this list outside of MovableObject::Listener::objectQueryLights |
---|
| 488 | (say if you want to use it to implement this method, and use the pointer |
---|
| 489 | as a return value) and for reading it's only accurate as at the last frame. |
---|
| 490 | */ |
---|
| 491 | virtual LightList* _getLightList() { return &mLightList; } |
---|
| 492 | |
---|
| 493 | /// Define a default implementation of method from ShadowCaster which implements no shadows |
---|
| 494 | EdgeData* getEdgeList(void) { return NULL; } |
---|
| 495 | /// Define a default implementation of method from ShadowCaster which implements no shadows |
---|
| 496 | bool hasEdgeList(void) { return false; } |
---|
| 497 | /// Define a default implementation of method from ShadowCaster which implements no shadows |
---|
| 498 | ShadowRenderableListIterator getShadowVolumeRenderableIterator( |
---|
| 499 | ShadowTechnique shadowTechnique, const Light* light, |
---|
| 500 | HardwareIndexBufferSharedPtr* indexBuffer, size_t* indexBufferUsedSize, |
---|
| 501 | bool extrudeVertices, Real extrusionDist, unsigned long flags = 0); |
---|
| 502 | |
---|
| 503 | /** Overridden member from ShadowCaster. */ |
---|
| 504 | const AxisAlignedBox& getLightCapBounds(void) const; |
---|
| 505 | /** Overridden member from ShadowCaster. */ |
---|
| 506 | const AxisAlignedBox& getDarkCapBounds(const Light& light, Real dirLightExtrusionDist) const; |
---|
| 507 | /** Sets whether or not this object will cast shadows. |
---|
| 508 | @remarks |
---|
| 509 | This setting simply allows you to turn on/off shadows for a given object. |
---|
| 510 | An object will not cast shadows unless the scene supports it in any case |
---|
| 511 | (see SceneManager::setShadowTechnique), and also the material which is |
---|
| 512 | in use must also have shadow casting enabled. By default all entities cast |
---|
| 513 | shadows. If, however, for some reason you wish to disable this for a single |
---|
| 514 | object then you can do so using this method. |
---|
| 515 | @note This method normally refers to objects which block the light, but |
---|
| 516 | since Light is also a subclass of MovableObject, in that context it means |
---|
| 517 | whether the light causes shadows itself. |
---|
| 518 | */ |
---|
| 519 | void setCastShadows(bool enabled) { mCastShadows = enabled; } |
---|
| 520 | /** Returns whether shadow casting is enabled for this object. */ |
---|
| 521 | bool getCastShadows(void) const { return mCastShadows; } |
---|
| 522 | /** Returns whether the Material of any Renderable that this MovableObject will add to |
---|
| 523 | the render queue will receive shadows. |
---|
| 524 | */ |
---|
| 525 | bool getReceivesShadows(); |
---|
| 526 | |
---|
| 527 | /** Get the distance to extrude for a point/spot light */ |
---|
| 528 | Real getPointExtrusionDistance(const Light* l) const; |
---|
| 529 | /** Get the 'type flags' for this MovableObject. |
---|
| 530 | @remarks |
---|
| 531 | A type flag identifies the type of the MovableObject as a bitpattern. |
---|
| 532 | This is used for categorical inclusion / exclusion in SceneQuery |
---|
| 533 | objects. By default, this method returns all ones for objects not |
---|
| 534 | created by a MovableObjectFactory (hence always including them); |
---|
| 535 | otherwise it returns the value assigned to the MovableObjectFactory. |
---|
| 536 | Custom objects which don't use MovableObjectFactory will need to |
---|
| 537 | override this if they want to be included in queries. |
---|
| 538 | */ |
---|
| 539 | virtual uint32 getTypeFlags(void) const; |
---|
| 540 | |
---|
| 541 | /** Method to allow a caller to abstractly iterate over the Renderable |
---|
| 542 | instances that this MovableObject will add to the render queue when |
---|
| 543 | asked, if any. |
---|
| 544 | @param visitor Pointer to a class implementing the Renderable::Visitor |
---|
| 545 | interface which will be called back for each Renderable which will |
---|
| 546 | be queued. Bear in mind that the state of the Renderable instances |
---|
| 547 | may not be finalised depending on when you call this. |
---|
| 548 | @param debugRenderables If false, only regular renderables will be visited |
---|
| 549 | (those for normal display). If true, debug renderables will be |
---|
| 550 | included too. |
---|
| 551 | */ |
---|
| 552 | virtual void visitRenderables(Renderable::Visitor* visitor, |
---|
| 553 | bool debugRenderables = false) = 0; |
---|
| 554 | |
---|
| 555 | /** Sets whether or not the debug display of this object is enabled. |
---|
| 556 | @remarks |
---|
| 557 | Some objects aren't visible themselves but it can be useful to display |
---|
| 558 | a debug representation of them. Or, objects may have an additional |
---|
| 559 | debug display on top of their regular display. This option enables / |
---|
| 560 | disables that debug display. Objects that are not visible never display |
---|
| 561 | debug geometry regardless of this setting. |
---|
| 562 | */ |
---|
| 563 | virtual void setDebugDisplayEnabled(bool enabled) { mDebugDisplay = enabled; } |
---|
| 564 | /// Gets whether debug display of this object is enabled. |
---|
| 565 | virtual bool isDebugDisplayEnabled(void) const { return mDebugDisplay; } |
---|
| 566 | |
---|
| 567 | |
---|
| 568 | |
---|
| 569 | |
---|
| 570 | |
---|
| 571 | }; |
---|
| 572 | |
---|
| 573 | /** Interface definition for a factory class which produces a certain |
---|
| 574 | kind of MovableObject, and can be registered with Root in order |
---|
| 575 | to allow all clients to produce new instances of this object, integrated |
---|
| 576 | with the standard Ogre processing. |
---|
| 577 | */ |
---|
| 578 | class _OgreExport MovableObjectFactory : public MovableAlloc |
---|
| 579 | { |
---|
| 580 | protected: |
---|
| 581 | /// Type flag, allocated if requested |
---|
| 582 | uint32 mTypeFlag; |
---|
| 583 | |
---|
| 584 | /// Internal implementation of create method - must be overridden |
---|
| 585 | virtual MovableObject* createInstanceImpl( |
---|
| 586 | const String& name, const NameValuePairList* params = 0) = 0; |
---|
| 587 | public: |
---|
| 588 | MovableObjectFactory() : mTypeFlag(0xFFFFFFFF) {} |
---|
| 589 | virtual ~MovableObjectFactory() {} |
---|
| 590 | /// Get the type of the object to be created |
---|
| 591 | virtual const String& getType(void) const = 0; |
---|
| 592 | |
---|
| 593 | /** Create a new instance of the object. |
---|
| 594 | @param name The name of the new object |
---|
| 595 | @param manager The SceneManager instance that will be holding the |
---|
| 596 | instance once created. |
---|
| 597 | @param params Name/value pair list of additional parameters required to |
---|
| 598 | construct the object (defined per subtype). Optional. |
---|
| 599 | */ |
---|
| 600 | virtual MovableObject* createInstance( |
---|
| 601 | const String& name, SceneManager* manager, |
---|
| 602 | const NameValuePairList* params = 0); |
---|
| 603 | /** Destroy an instance of the object */ |
---|
| 604 | virtual void destroyInstance(MovableObject* obj) = 0; |
---|
| 605 | |
---|
| 606 | /** Does this factory require the allocation of a 'type flag', used to |
---|
| 607 | selectively include / exclude this type from scene queries? |
---|
| 608 | @remarks |
---|
| 609 | The default implementation here is to return 'false', ie not to |
---|
| 610 | request a unique type mask from Root. For objects that |
---|
| 611 | never need to be excluded in SceneQuery results, that's fine, since |
---|
| 612 | the default implementation of MovableObject::getTypeFlags is to return |
---|
| 613 | all ones, hence matching any query type mask. However, if you want the |
---|
| 614 | objects created by this factory to be filterable by queries using a |
---|
| 615 | broad type, you have to give them a (preferably unique) type mask - |
---|
| 616 | and given that you don't know what other MovableObject types are |
---|
| 617 | registered, Root will allocate you one. |
---|
| 618 | */ |
---|
| 619 | virtual bool requestTypeFlags(void) const { return false; } |
---|
| 620 | /** Notify this factory of the type mask to apply. |
---|
| 621 | @remarks |
---|
| 622 | This should normally only be called by Root in response to |
---|
| 623 | a 'true' result from requestTypeMask. However, you can actually use |
---|
| 624 | it yourself if you're careful; for example to assign the same mask |
---|
| 625 | to a number of different types of object, should you always wish them |
---|
| 626 | to be treated the same in queries. |
---|
| 627 | */ |
---|
| 628 | void _notifyTypeFlags(uint32 flag) { mTypeFlag = flag; } |
---|
| 629 | |
---|
| 630 | /** Gets the type flag for this factory. |
---|
| 631 | @remarks |
---|
| 632 | A type flag is like a query flag, except that it applies to all instances |
---|
| 633 | of a certain type of object. |
---|
| 634 | */ |
---|
| 635 | uint32 getTypeFlags(void) const { return mTypeFlag; } |
---|
| 636 | |
---|
| 637 | }; |
---|
| 638 | /** @} */ |
---|
| 639 | /** @} */ |
---|
| 640 | |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | #include "OgreHeaderSuffix.h" |
---|
| 644 | |
---|
| 645 | #endif |
---|