OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreInstancedEntity.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 #ifndef __InstancedEntity_H__
29 #define __InstancedEntity_H__
30 
31 #include "OgreMovableObject.h"
32 #include "OgreNode.h"
33 #include "OgreDualQuaternion.h"
35 #include "OgreHeaderPrefix.h"
36 
37 namespace Ogre
38 {
80  {
81  friend class InstanceBatch;
82  friend class InstanceBatchShader;
83  friend class InstanceBatchHW;
84  friend class InstanceBatchHW_VTF;
85  friend class BaseInstanceBatchVTF;
86  protected:
87  uint16 mInstanceId; //Note it may change after defragmenting!
88  bool mInUse;
90 
91 #ifdef OGRE_LEGACY_ANIMATIONS
92  AnimationStateSet *mAnimationState;
93  OldSkeletonInstance *mSkeletonInstance;
94  Matrix4 *mBoneMatrices; //Local space
95  Matrix4 *mBoneWorldMatrices; //World space
96  unsigned long mFrameAnimationLastUpdated;
97 #else
100 #endif
101 
102  InstancedEntity* mSharedTransformEntity; //When not null, another InstancedEntity controls the skeleton
103 
107 
111 
113  size_t getTransforms( Matrix4 *xform ) const;
115  size_t getTransforms3x4( float *xform ) const;
116 
121  FORCEINLINE void writeSingleTransform3x4( float * RESTRICT_ALIAS xform ) const;
122 
133  FORCEINLINE void writeAnimatedTransform3x4( float * RESTRICT_ALIAS xform,
134  Mesh::IndexMap::const_iterator boneIdxStart,
135  Mesh::IndexMap::const_iterator boneIdxEnd ) const;
136 
147  FORCEINLINE void writeLutTransform3x4( float * RESTRICT_ALIAS xform,
148  Mesh::IndexMap::const_iterator boneIdxStart,
149  Mesh::IndexMap::const_iterator boneIdxEnd ) const;
150 
161  FORCEINLINE void writeDualQuatTransform( float * RESTRICT_ALIAS xform,
162  Mesh::IndexMap::const_iterator boneIdxStart,
163  Mesh::IndexMap::const_iterator boneIdxEnd ) const;
164 
166  bool findVisible( Camera *camera ) const;
167 
169  void createSkeletonInstance();
170  void destroySkeletonInstance();
171 
174  void stopSharingTransformAsSlave( bool notifyMaster );
175 
177  void unlinkTransform( bool notifyMaster=true );
178 
180  void notifyUnlink( const InstancedEntity *slave );
181 
183  void setInUse(bool used);
184 
185  public:
186  InstancedEntity( IdType id, ObjectMemoryManager *objectMemoryManager, InstanceBatch *batchOwner,
187  uint32 instanceID,
188  #ifndef OGRE_LEGACY_ANIMATIONS
189  BoneMemoryManager *boneMemoryManager,
190  #endif
191  InstancedEntity* sharedTransformEntity = NULL );
192  virtual ~InstancedEntity();
193 
212  bool shareTransformWith( InstancedEntity *slave );
213 
221  void stopSharingTransform();
222 
223  InstanceBatch* _getOwner() const { return mBatchOwner; }
224 
225  const String& getMovableType(void) const;
226 
227  const AxisAlignedBox& getBoundingBox(void) const;
228 
231  Real getSquaredViewDepth( const Camera* cam ) const;
232 
234  virtual void _notifyStaticDirty(void) const;
235 
237  virtual void _notifyAttached( Node* parent );
238 
239 #ifndef OGRE_LEGACY_ANIMATIONS
240  virtual void _notifyParentNodeMemoryChanged(void);
241 #endif
242 
244  void _updateRenderQueue( RenderQueue* queue, Camera *camera, const Camera *lodCamera ) {}
245  void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false ) {}
246 
248  bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
249 
250 #ifdef OGRE_LEGACY_ANIMATIONS
251 
252  OldSkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
253 #else
254  SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
255 #endif
256 
257 #ifdef OGRE_LEGACY_ANIMATIONS
258 
259  AnimationState* getAnimationState(const String& name) const;
261  AnimationStateSet* getAllAnimationStates(void) const;
262 
268  bool _updateAnimation(void);
269 #endif
270 
272  void setTransformLookupNumber(uint16 num) { mTransformLookupNumber = num;}
273 
275  bool isInUse() const { return mInUse; }
276 
278  virtual bool isInScene(void) const
279  {
280  //We assume that the instanced entity is in the scene if it is in use
281  //It is in the scene whether it has a parent node or not
282  return mInUse;
283  }
284 
296  void setCustomParam( unsigned char idx, const Vector4 &newParam );
297  const Vector4& getCustomParam( unsigned char idx );
298  };
299 }
300 
301 #include "OgreInstancedEntity.inl"
302 
303 #include "OgreHeaderSuffix.h"
304 
305 #endif
Class encapsulating a set of AnimationState objects.
Wrap-around class that contains multiple ArrayMemoryManager, one per hierarchy depth.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
BoneMemoryManager * mBoneMemoryManager
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
#define _OgreExport
Definition: OgrePlatform.h:255
void _updateRenderQueue(RenderQueue *queue, Camera *camera, const Camera *lodCamera)
Do nothing, InstanceBatch takes care of this.
SkeletonInstance * mSkeletonInstance
void setTransformLookupNumber(uint16 num)
Sets the transformation look up number.
This is the same technique the old "InstancedGeometry" implementation used (with improvements).
A 3D box aligned with the x/y/z axes.
Represents the state of an animation and the weight of its influence.
SkeletonInstance * getSkeleton(void) const
InstancedEntity * mSharedTransformEntity
InstancedEntityVec mSharingPartners
bool hasSkeleton(void) const
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Abstract class defining a movable object in a scene.
vector< InstancedEntity * >::type InstancedEntityVec
Stores the master when we're the slave, store our slaves when we're the master.
#define RESTRICT_ALIAS
Definition: OgrePlatform.h:448
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
const unsigned short * const_iterator
Definition: OgreFastArray.h:95
InstanceBatch * mBatchOwner
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
bool isInUse() const
Tells if the entity is in use.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
virtual bool isInScene(void) const
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
Class to manage the scene object rendering queue.
#define FORCEINLINE
Definition: OgrePlatform.h:104
_StringBase String
Definition: OgreCommon.h:53
unsigned short uint16
Definition: OgrePlatform.h:421
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
A OldSkeletonInstance is a single instance of a Skeleton used by a world object.
uint16 mTransformLookupNumber
Used in conjunction with bone matrix lookup.
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
Instance of a Skeleton, main external interface for retrieving bone positions and applying animations...
This is technique requires true instancing hardware support.
InstanceBatch * _getOwner() const
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) and hardware instan...