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-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 #ifndef __InstancedEntity_H__
29 #define __InstancedEntity_H__
30 
31 #include "OgreMovableObject.h"
32 #include "OgreNode.h"
33 #include "OgreHeaderPrefix.h"
34 
35 namespace Ogre
36 {
78  {
79  friend class InstanceBatch;
80  friend class InstanceBatchShader;
81  friend class InstanceBatchHW;
82  friend class InstanceBatchHW_VTF;
83  friend class BaseInstanceBatchVTF;
84  protected:
85  uint16 mInstanceId; //Note it may change after defragmenting!
86  bool mInUse;
88 
91  Matrix4 *mBoneMatrices; //Local space
92  Matrix4 *mBoneWorldMatrices; //World space
94 
95  InstancedEntity* mSharedTransformEntity; //When not null, another InstancedEntity controls the skeleton
96 
100 
104 
106  // Parameters used for local transformation offset information
107  // The
109 
127 
128 
130  size_t getTransforms( Matrix4 *xform ) const;
132  size_t getTransforms3x4( float *xform ) const;
133 
135  bool findVisible( Camera *camera ) const;
136 
140 
143  void stopSharingTransformAsSlave( bool notifyMaster );
144 
146  void unlinkTransform( bool notifyMaster=true );
147 
149  void notifyUnlink( const InstancedEntity *slave );
150 
152  inline void markTransformDirty();
153 
156 
157  public:
158  InstancedEntity( InstanceBatch *batchOwner, uint32 instanceID, InstancedEntity* sharedTransformEntity = NULL);
159  virtual ~InstancedEntity();
160 
180 
189 
190  InstanceBatch* _getOwner() const { return mBatchOwner; }
191 
192  const String& getMovableType(void) const;
193 
194  const AxisAlignedBox& getBoundingBox(void) const;
195  Real getBoundingRadius(void) const;
196 
199  Real getSquaredViewDepth( const Camera* cam ) const;
200 
202  void _notifyMoved(void);
203  void _notifyAttached( Node* parent, bool isTagPoint = false );
204 
206  void _updateRenderQueue( RenderQueue* queue ) {}
207  void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false ) {}
208 
210  bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
212  SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
213 
218 
224  virtual bool _updateAnimation(void);
225 
227  void setTransformLookupNumber(uint16 num) { mTransformLookupNumber = num;}
228 
230  const Vector3& getPosition() const { return mPosition; }
232  void setPosition(const Vector3& position, bool doUpdate = true);
233 
235  const Quaternion& getOrientation() const { return mOrientation; }
237  void setOrientation(const Quaternion& orientation, bool doUpdate = true);
238 
240  const Vector3& getScale() const { return mScale; }
242  void setScale(const Vector3& scale, bool doUpdate = true);
243 
246 
249 
251  bool isInUse() const { return mInUse; }
253  void setInUse(bool used);
254 
256  virtual const Matrix4& _getParentNodeFullTransform(void) const {
257  assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
258  return mUseLocalTransform ? mFullLocalTransform :
259  mParentNode ? mParentNode->_getFullTransform() : Matrix4::IDENTITY;
260  }
261 
263  const Vector3& _getDerivedPosition() const {
264  assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
265  return mUseLocalTransform ? mDerivedLocalPosition :
266  mParentNode ? mParentNode->_getDerivedPosition() : Vector3::ZERO;
267  }
268 
270  virtual bool isInScene(void) const
271  {
272  //We assume that the instanced entity is in the scene if it is in use
273  //It is in the scene whether it has a parent node or not
274  return mInUse;
275  }
276 
288  void setCustomParam( unsigned char idx, const Vector4 &newParam );
289  const Vector4& getCustomParam( unsigned char idx );
290  };
291 }
292 
293 #include "OgreHeaderSuffix.h"
294 
295 #endif
#define _OgreExport
Definition: OgrePlatform.h:257
Class encapsulating a set of AnimationState objects.
Represents the state of an animation and the weight of its influence.
A 3D box aligned with the x/y/z axes.
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) and hardware instan...
This is technique requires true instancing hardware support.
This is the same technique the old "InstancedGeometry" implementation used (with improvements).
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
static const Matrix4 IDENTITY
Definition: OgreMatrix4.h:511
Abstract class defining a movable object in a scene.
Utility class to generate a sequentially numbered series of names.
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:65
Implementation of a Quaternion, i.e.
Class to manage the scene object rendering queue.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly.
A SkeletonInstance is a single instance of a Skeleton used by a world object.
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
static const Vector3 ZERO
Definition: OgreVector3.h:800
4-dimensional homogeneous vector.
Definition: OgreVector4.h:46
void setCustomParam(unsigned char idx, const Vector4 &newParam)
Sets the custom parameter for this instance.
void _updateRenderQueue(RenderQueue *queue)
Do nothing, InstanceBatch takes care of this.
Matrix4 mFullLocalTransform
Full world transform.
InstanceBatch * mBatchOwner
void _notifyAttached(Node *parent, bool isTagPoint=false)
Internal method called to notify the object that it has been attached to a node.
InstancedEntityVec mSharingPartners
AnimationState * getAnimationState(const String &name) const
void createSkeletonInstance()
Creates/destroys our own skeleton, also tells slaves to unlink if we're destroying.
Real getMaxScaleCoef() const
Returns the maximum derived scale coefficient among the xyz values.
virtual bool isInScene(void) const
const String & getMovableType(void) const
Returns the type name of this object.
Real getBoundingRadius(void) const
Retrieves the radius of the origin-centered bounding sphere for this object.
bool mNeedTransformUpdate
Tells if mFullTransform needs an updated.
Real mMaxScaleLocal
The maximum absolute scale for all dimension.
const Vector3 & _getDerivedPosition() const
Returns the derived position of the instanced entity including local transform.
Real getSquaredViewDepth(const Camera *cam) const
This is used by our batch owner to get the closest entity's depth, returns infinity when not attached...
InstancedEntity(InstanceBatch *batchOwner, uint32 instanceID, InstancedEntity *sharedTransformEntity=NULL)
const Vector3 & getPosition() const
Retrieve the position.
virtual bool _updateAnimation(void)
Called by InstanceBatch in his _updateRenderQueue to tell us we need to calculate our bone matrices.
size_t getTransforms(Matrix4 *xform) const
Returns number of matrices written to transform, assumes transform has enough space.
virtual ~InstancedEntity()
void setPosition(const Vector3 &position, bool doUpdate=true)
Set the position or the offset from the parent node if a parent node exists.
void setOrientation(const Quaternion &orientation, bool doUpdate=true)
Set the orientation or the offset from the parent node if a parent node exists.
InstancedEntity * mSharedTransformEntity
const Quaternion & getOrientation() const
Retrieve the orientation.
InstanceBatch * _getOwner() const
uint16 mTransformLookupNumber
Used in conjunction with bone matrix lookup.
bool mUseLocalTransform
Tells whether to use the local transform parameters.
void setScale(const Vector3 &scale, bool doUpdate=true)
Set the scale or the offset from the parent node if a parent node exists
bool mNeedAnimTransformUpdate
Tells if the animation world transform needs an update.
void stopSharingTransformAsSlave(bool notifyMaster)
When this entity is a slave, stopSharingTransform delegates to this function.
bool isInUse() const
Tells if the entity is in use.
static NameGenerator msNameGenerator
Incremented count for next name extension.
AnimationStateSet * getAllAnimationStates(void) const
Vector3 mPosition
Object position.
void setInUse(bool used)
Sets whether the entity is in use.
virtual const Matrix4 & _getParentNodeFullTransform(void) const
Returns the world transform of the instanced entity including local transform.
Quaternion mOrientation
Object orientation.
AnimationStateSet * mAnimationState
vector< InstancedEntity * >::type InstancedEntityVec
Stores the master when we're the slave, store our slaves when we're the master.
void unlinkTransform(bool notifyMaster=true)
Just unlinks, and tells our master we're no longer sharing.
const AxisAlignedBox & getBoundingBox(void) const
Retrieves the local axis-aligned bounding box for this object.
void updateTransforms()
Update the world transform and derived values.
Vector3 mScale
Object scale.
SkeletonInstance * mSkeletonInstance
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
void markTransformDirty()
Mark the transformation matrixes as dirty.
void _notifyMoved(void)
Overridden so we can tell the InstanceBatch it needs to update it's bounds.
const Vector3 & getScale() const
Retrieve the local scale.
unsigned long mFrameAnimationLastUpdated
SkeletonInstance * getSkeleton(void) const
void notifyUnlink(const InstancedEntity *slave)
Called when a slave has unlinked from us.
size_t getTransforms3x4(float *xform) const
Returns number of 32-bit values written.
bool shareTransformWith(InstancedEntity *slave)
Shares the entire transformation with another InstancedEntity.
const Vector4 & getCustomParam(unsigned char idx)
bool hasSkeleton(void) const
bool findVisible(Camera *camera) const
Returns true if this InstancedObject is visible to the current camera.
void setTransformLookupNumber(uint16 num)
Sets the transformation look up number.
float Real
Software floating point type.
unsigned short uint16
Definition: OgrePlatform.h:360
unsigned int uint32
Definition: OgrePlatform.h:359
_StringBase String

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.