OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreMovableObject.h
Go to the documentation of this file.
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-2014 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 "OgreAxisAlignedBox.h"
35 #include "OgreSphere.h"
36 #include "OgreAnimable.h"
37 #include "OgreSceneNode.h"
39 #include "OgreId.h"
40 #include "OgreVisibilityFlags.h"
41 #include "OgreLodStrategy.h"
42 #include "OgreHeaderPrefix.h"
43 
44 namespace Ogre {
46 
47  // Forward declaration
49 
63  {
64  public:
69  {
70  public:
71  Listener(void) {}
72  virtual ~Listener() {}
74  virtual void objectDestroyed(MovableObject*) {}
76  virtual void objectAttached(MovableObject*) {}
78  virtual void objectDetached(MovableObject*) {}
79  };
80 
81  protected:
92 
93  //One for each submesh/material/Renderable
96  unsigned char mCurrentMeshLod;
98 
103 
106 
109 
112 
115 
116 #ifndef NDEBUG
117  mutable bool mCachedAabbOutOfDate;
118 #endif
119 
122 
123  // Static members
128 
129  protected:
130  Aabb updateSingleWorldAabb();
131  float updateSingleWorldRadius();
132 
133  public:
140  size_t mGlobalIndex;
142  size_t mParentIndex;
143 
145  MovableObject( IdType id, ObjectMemoryManager *objectMemoryManager,
146  uint8 renderQueueId );
147 
151  MovableObject( ObjectData *objectDataPtrs );
152 
155  virtual ~MovableObject();
156 
158  void _notifyManager(SceneManager* man) { mManager = man; }
160  SceneManager* _getManager(void) const { return mManager; }
161 
163  void setName( const String &name ) { mName = name; }
164 
166  const String& getName(void) const { return mName; }
167 
169  virtual const String& getMovableType(void) const = 0;
170 
172  Node* getParentNode(void) const { return mParentNode; }
173 
174  inline SceneNode* getParentSceneNode(void) const;
175 
178  virtual void _notifyAttached( Node* parent );
179 
181  bool isAttached(void) const { return mParentNode != 0; }
182 
184  void detachFromParent(void);
185 
187  virtual void _notifyParentNodeMemoryChanged(void) {}
188 
190  bool isStatic() const;
191 
208  bool setStatic( bool bStatic );
209 
212  virtual void _notifyStaticDirty(void) const {}
213 
219  virtual void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera) = 0;
220 
225  static void updateAllBounds( const size_t numNodes, ObjectData t );
226 
245  static void cullFrustum( const size_t numNodes, ObjectData t, const Frustum *frustum,
246  uint32 sceneVisibilityFlags, MovableObjectArray &outCulledObjects,
247  const Camera *lodCamera );
248 
250  virtual void instanceBatchCullFrustumThreaded( const Frustum *frustum, const Camera *lodCamera,
251  uint32 combinedVisibilityFlags ) {}
252 
267  static void cullLights( const size_t numNodes, ObjectData t, LightListInfo &outGlobalLightList,
268  const FrustumVec &frustums , const FrustumVec &cubemapFrustums );
269 
277  static void buildLightList( const size_t numNodes, ObjectData t,
278  const LightListInfo &globalLightList );
279 
280  static void calculateCastersBox( const size_t numNodes, ObjectData t,
281  uint32 sceneVisibilityFlags, AxisAlignedBox *outBox );
282 
283  friend void LodStrategy::lodUpdateImpl( const size_t numNodes, ObjectData t,
284  const Camera *camera, Real bias ) const;
285  friend void LodStrategy::lodSet( ObjectData &t, Real lodValues[ARRAY_PACKED_REALS] );
286 
301  inline void setVisible( bool visible );
302 
307  inline bool getVisible(void) const;
308 
313  bool isVisible(void) const;
314 
321  inline void setRenderingDistance(Real dist);
322 
324  inline Real getRenderingDistance(void) const;
325 
331  void setRenderingMinPixelSize(Real pixelSize) {
332  mMinPixelSize = pixelSize;
333  }
334 
338  Real getRenderingMinPixelSize() const { return mMinPixelSize; }
339 
344  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
345 
350  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
351 
364  virtual void setRenderQueueGroup(uint8 queueID);
365 
381  virtual void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority);
382 
384  uint8 getRenderQueueGroup(void) const;
385 
387  ObjectData& _getObjectData() { return mObjectData; }
388 
390  const Matrix4& _getParentNodeFullTransform(void) const;
391 
396  Aabb getLocalAabb(void) const;
397 
402  void setLocalAabb(const Aabb box);
403 
410  Aabb getWorldAabb() const;
411 
419  Aabb getWorldAabbUpdated();
420 
427  float getWorldRadius() const;
428 
436  float getWorldRadiusUpdated();
437 
445  inline void setQueryFlags(uint32 flags);
446 
449  inline void addQueryFlags(uint32 flags);
450 
453  inline void removeQueryFlags(uint32 flags);
454 
456  inline uint32 getQueryFlags(void) const;
457 
460  static void setDefaultQueryFlags(uint32 flags) { msDefaultQueryFlags = flags; }
461 
464  static uint32 getDefaultQueryFlags() { return msDefaultQueryFlags; }
465 
466 
474  inline void setVisibilityFlags(uint32 flags);
475 
478  inline void addVisibilityFlags(uint32 flags);
479 
482  inline void removeVisibilityFlags(uint32 flags);
483 
487  inline uint32 getVisibilityFlags(void) const;
488 
491  inline static void setDefaultVisibilityFlags(uint32 flags);
492 
495  static uint32 getDefaultVisibilityFlags() { return msDefaultVisibilityFlags; }
496 
502  void setListener(Listener* listener) { mListener = listener; }
503 
506  Listener* getListener(void) const { return mListener; }
507 
513  const LightList& queryLights(void) const { return mLightList; }
514 
519  inline uint32 getLightMask()const;
526  inline void setLightMask(uint32 lightMask);
527 
534  LightList* _getLightList() { return &mLightList; }
535 
536  const FastArray<unsigned char>& getCurrentMaterialLod(void) const { return mCurrentMaterialLod; }
537 
550  inline void setCastShadows( bool enabled );
552  inline bool getCastShadows(void) const;
556  bool getReceivesShadows();
557 
569  virtual void visitRenderables(Renderable::Visitor* visitor,
570  bool debugRenderables = false) = 0;
571 
580  virtual void setDebugDisplayEnabled(bool enabled) { mDebugDisplay = enabled; }
582  virtual bool isDebugDisplayEnabled(void) const { return mDebugDisplay; }
583 
584 
585 #ifndef NDEBUG
586  void _setCachedAabbOutOfDate(void) { mCachedAabbOutOfDate = true; }
587  bool isCachedAabbOutOfDate() const { return mCachedAabbOutOfDate; }
588 #endif
589 
590  };
591 
598  {
599  protected:
601  virtual MovableObject* createInstanceImpl( IdType id, ObjectMemoryManager *objectMemoryManager,
602  const NameValuePairList* params = 0) = 0;
603  public:
607  virtual const String& getType(void) const = 0;
608 
615  virtual MovableObject* createInstance( IdType id, ObjectMemoryManager *objectMemoryManager,
616  SceneManager* manager, const NameValuePairList* params = 0);
618  virtual void destroyInstance(MovableObject* obj) = 0;
619  };
620 
622  {
623  static const String msMovableType;
624  public:
626  {
627  }
628 
629  virtual const String& getMovableType(void) const
630  {
631  return msMovableType;
632  }
633  virtual void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera) {}
634  virtual void visitRenderables(Renderable::Visitor* visitor,
635  bool debugRenderables = false) {}
636  };
637 
641 }
642 
643 #include "OgreHeaderSuffix.h"
644 
645 #include "OgreMovableObject.inl"
646 
647 #endif
virtual void instanceBatchCullFrustumThreaded(const Frustum *frustum, const Camera *lodCamera, uint32 combinedVisibilityFlags)
InstancingTheadedCullingMethod,
unsigned char uint8
Definition: OgrePlatform.h:422
Node * getParentNode(void) const
Returns the node to which this object is attached.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
virtual void objectDetached(MovableObject *)
MovableObject has been detached from a node.
Represents the transform of a single object, arranged in SoA (Structure of Arrays) ...
void _setCachedAabbOutOfDate(void)
const FastArray< Real > c_DefaultLodMesh
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
float Real
Software floating point type.
const FastArray< unsigned char > & getCurrentMaterialLod(void) const
unsigned int uint32
Definition: OgrePlatform.h:420
#define _OgreExport
Definition: OgrePlatform.h:255
const String & getName(void) const
Returns the name of this object.
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:580
UserObjectBindings mUserObjectBindings
User objects binding.
static uint32 getDefaultVisibilityFlags()
Get the default visibility flags for all future MovableObject instances.
bool mDebugDisplay
Is debug display enabled?
virtual const String & getMovableType(void) const
Returns the type name of this object.
virtual void objectAttached(MovableObject *)
MovableObject has been attached to a node.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
Manages the organisation and rendering of a 'scene' i.e.
const UserObjectBindings & getUserObjectBindings() const
Return an instance of user objects binding associated with this class.
A 3D box aligned with the x/y/z axes.
ObjectData & _getObjectData()
Returns a direct access to the ObjectData state.
bool isAttached(void) const
Returns true if this object is attached to a Node.
Defines an interface to classes which have one or more AnimableValue instances to expose...
Definition: OgreAnimable.h:234
virtual void objectDestroyed(MovableObject *)
MovableObject is being destroyed.
virtual void _updateRenderQueue(RenderQueue *queue, Camera *camera, const Camera *lodCamera)
Internal method by which the movable object must add Renderable subclass instances to the rendering q...
ObjectMemoryManager * mObjectMemoryManager
The memory manager used to allocate the ObjectData.
Interface definition for a factory class which produces a certain kind of MovableObject, and can be registered with Root in order to allow all clients to produce new instances of this object, integrated with the standard Ogre processing.
static const String msMovableType
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Listener which gets called back on MovableObject events.
Abstract class defining a movable object in a scene.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:53
unsigned char mCurrentMeshLod
static uint32 msDefaultVisibilityFlags
Default visibility flags.
virtual void setDebugDisplayEnabled(bool enabled)
Sets whether or not the debug display of this object is enabled.
Holds all lights in SoA after being culled over all frustums.
Definition: OgreCommon.h:555
ObjectData mObjectData
All the object data needed in SoA form.
virtual void lodUpdateImpl(const size_t numNodes, ObjectData t, const Camera *camera, Real bias) const =0
virtual bool isDebugDisplayEnabled(void) const
Gets whether debug display of this object is enabled.
void setListener(Listener *listener)
Sets a listener for this object.
Listener * getListener(void) const
Gets the current listener for this object.
virtual void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
size_t mGlobalIndex
Index in the vector holding this MO reference (could be our parent node, or a global array tracking a...
vector< Frustum * >::type FrustumVec
FastArray< FastArray< Real > const * > mLodMaterial
void setRenderingMinPixelSize(Real pixelSize)
Sets the minimum pixel size an object needs to be in both screen axes in order to be rendered...
static void lodSet(ObjectData &t, Real lodValues[ARRAY_PACKED_REALS])
static uint32 getDefaultQueryFlags()
Get the default query flags for all future MovableObject instances.
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
virtual void _notifyParentNodeMemoryChanged(void)
Node::_callMemoryChangeListeners
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
AoS (array of structures) version of ArrayAabb.
Definition: C/OgreAabb.h:78
static uint32 msDefaultQueryFlags
Default query flags.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
FastArray< Real > const * mLodMesh
#define ARRAY_PACKED_REALS
FastArray< unsigned char > mCurrentMaterialLod
SceneManager * mManager
SceneManager holding this object (if applicable)
unsigned short ushort
Real getRenderingMinPixelSize() const
Returns the minimum pixel size an object needs to be in both screen axes in order to be rendered...
FastArray< MovableObject * > MovableObjectArray
SceneManager::cullFrustum
const LightList & queryLights(void) const
Gets a list of lights, ordered relative to how close they are to this movable object.
uint8 mRenderQueueID
The render queue to use when rendering this object.
virtual void _notifyStaticDirty(void) const
Called by SceneManager when it is telling we're a static MovableObject being dirty Don't call this di...
LightList mLightList
List of lights for this object.
size_t mParentIndex
Index in the vector holding this MO reference (could be our parent node, or a global array tracking a...
LightList * _getLightList()
Returns a pointer to the current list of lights for this object.
Class to manage the scene object rendering queue.
static void setDefaultQueryFlags(uint32 flags)
Set the default query flags for all future MovableObject instances.
void _notifyManager(SceneManager *man)
Notify the object of it's manager (internal use only)
Real mMinPixelSize
Minimum pixel size to still render.
void setName(const String &name)
Sets a custom name for this node.
bool isCachedAabbOutOfDate() const
_StringBase String
Definition: OgreCommon.h:53
SceneManager * _getManager(void) const
Get the manager of this object, if any (internal use only)
Node * mParentNode
Node to which this object is attached.
String mName
Friendly name of this object, can be empty.
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
Listener * mListener
MovableObject listener - only one allowed (no list) for size & performance reasons.
Class that provides convenient interface to establish a linkage between custom user application objec...
ushort mRenderQueuePriority
The render queue group to use when rendering this object.