OgreInstancedEntity.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __InstancedEntity_H__
#define __InstancedEntity_H__
#include "OgreMovableObject.h"
#include "OgreNode.h"
#include "OgreHeaderPrefix.h"
namespace Ogre
{
class _OgreExport InstancedEntity : public Ogre::MovableObject
{
friend class InstanceBatch;
friend class InstanceBatchShader;
friend class InstanceBatchHW;
friend class InstanceBatchHW_VTF;
friend class BaseInstanceBatchVTF;
protected:
uint16 mInstanceId; //Note it may change after defragmenting!
bool mInUse;
InstanceBatch *mBatchOwner;
AnimationStateSet *mAnimationState;
SkeletonInstance *mSkeletonInstance;
Matrix4 *mBoneMatrices; //Local space
Matrix4 *mBoneWorldMatrices; //World space
unsigned long mFrameAnimationLastUpdated;
InstancedEntity* mSharedTransformEntity; //When not null, another InstancedEntity controls the skeleton
uint16 mTransformLookupNumber;
typedef vector<InstancedEntity*>::type InstancedEntityVec;
InstancedEntityVec mSharingPartners;
// Parameters used for local transformation offset information
// The
Vector3 mPosition;
Vector3 mDerivedLocalPosition;
Quaternion mOrientation;
Vector3 mScale;
Real mMaxScaleLocal;
Matrix4 mFullLocalTransform;
bool mNeedTransformUpdate;
bool mNeedAnimTransformUpdate;
bool mUseLocalTransform;
size_t getTransforms( Matrix4 *xform ) const;
size_t getTransforms3x4( float *xform ) const;
bool findVisible( Camera *camera ) const;
void createSkeletonInstance();
void destroySkeletonInstance();
void stopSharingTransformAsSlave( bool notifyMaster );
void unlinkTransform( bool notifyMaster=true );
void notifyUnlink( const InstancedEntity *slave );
inline void markTransformDirty();
static NameGenerator msNameGenerator;
public:
InstancedEntity( InstanceBatch *batchOwner, uint32 instanceID, InstancedEntity* sharedTransformEntity = NULL);
virtual ~InstancedEntity();
bool shareTransformWith( InstancedEntity *slave );
void stopSharingTransform();
InstanceBatch* _getOwner() const { return mBatchOwner; }
const String& getMovableType(void) const;
const AxisAlignedBox& getBoundingBox(void) const;
Real getBoundingRadius(void) const;
Real getSquaredViewDepth( const Camera* cam ) const;
void _notifyMoved(void);
void _notifyAttached( Node* parent, bool isTagPoint = false );
void _updateRenderQueue( RenderQueue* queue ) {}
void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false ) {}
bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
AnimationState* getAnimationState(const String& name) const;
AnimationStateSet* getAllAnimationStates(void) const;
virtual bool _updateAnimation(void);
void setTransformLookupNumber(uint16 num) { mTransformLookupNumber = num;}
const Vector3& getPosition() const { return mPosition; }
void setPosition(const Vector3& position, bool doUpdate = true);
const Quaternion& getOrientation() const { return mOrientation; }
void setOrientation(const Quaternion& orientation, bool doUpdate = true);
const Vector3& getScale() const { return mScale; }
void setScale(const Vector3& scale, bool doUpdate = true);
Real getMaxScaleCoef() const;
void updateTransforms();
bool isInUse() const { return mInUse; }
void setInUse(bool used);
virtual const Matrix4& _getParentNodeFullTransform(void) const {
assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
return mUseLocalTransform ? mFullLocalTransform :
mParentNode ? mParentNode->_getFullTransform() : Matrix4::IDENTITY;
}
const Vector3& _getDerivedPosition() const {
assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
return mUseLocalTransform ? mDerivedLocalPosition :
mParentNode ? mParentNode->_getDerivedPosition() : Vector3::ZERO;
}
virtual bool isInScene(void) const
{
//We assume that the instanced entity is in the scene if it is in use
//It is in the scene whether it has a parent node or not
return mInUse;
}
void setCustomParam( unsigned char idx, const Vector4 &newParam );
const Vector4& getCustomParam( unsigned char idx );
};
}
#include "OgreHeaderSuffix.h"
#endif
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::MovableObject
Abstract class defining a movable object in a scene.
Definition: OgreMovableObject.h:60
Ogre::InstancedEntity::mBoneWorldMatrices
Matrix4 * mBoneWorldMatrices
Definition: OgreInstancedEntity.h:92
Ogre::InstancedEntity::mNeedTransformUpdate
bool mNeedTransformUpdate
Tells if mFullTransform needs an updated.
Definition: OgreInstancedEntity.h:122
Ogre::InstanceBatchHW_VTF
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) and hardware instan...
Definition: OgreInstanceBatchHW_VTF.h:60
Ogre::InstancedEntity::_getDerivedPosition
const Vector3 & _getDerivedPosition() const
Returns the derived position of the instanced entity including local transform.
Definition: OgreInstancedEntity.h:263
OgreMovableObject.h
Ogre::InstancedEntity::mDerivedLocalPosition
Vector3 mDerivedLocalPosition
Definition: OgreInstancedEntity.h:112
Ogre::Quaternion
Implementation of a Quaternion, i.e.
Definition: OgreQuaternion.h:57
Ogre::InstancedEntity::mTransformLookupNumber
uint16 mTransformLookupNumber
Used in conjunction with bone matrix lookup.
Definition: OgreInstancedEntity.h:99
Ogre::InstancedEntity::_getParentNodeFullTransform
virtual const Matrix4 & _getParentNodeFullTransform(void) const
Returns the world transform of the instanced entity including local transform.
Definition: OgreInstancedEntity.h:256
Ogre::Matrix4::IDENTITY
static const Matrix4 IDENTITY
Definition: OgreMatrix4.h:511
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::InstancedEntity::mSharedTransformEntity
InstancedEntity * mSharedTransformEntity
Definition: OgreInstancedEntity.h:95
Ogre::InstancedEntity::setTransformLookupNumber
void setTransformLookupNumber(uint16 num)
Sets the transformation look up number.
Definition: OgreInstancedEntity.h:227
Ogre::NameGenerator
Utility class to generate a sequentially numbered series of names.
Definition: OgreNameGenerator.h:56
Ogre::InstancedEntity::msNameGenerator
static NameGenerator msNameGenerator
Incremented count for next name extension.
Definition: OgreInstancedEntity.h:155
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::InstancedEntity::getScale
const Vector3 & getScale() const
Retrieve the local scale.
Definition: OgreInstancedEntity.h:240
Ogre::RenderQueue
Class to manage the scene object rendering queue.
Definition: OgreRenderQueue.h:92
Ogre::InstancedEntity::mMaxScaleLocal
Real mMaxScaleLocal
The maximum absolute scale for all dimension.
Definition: OgreInstancedEntity.h:118
Ogre::InstancedEntity::mSharingPartners
InstancedEntityVec mSharingPartners
Definition: OgreInstancedEntity.h:103
Ogre::InstancedEntity::mOrientation
Quaternion mOrientation
Object orientation.
Definition: OgreInstancedEntity.h:114
Ogre::InstancedEntity::mFullLocalTransform
Matrix4 mFullLocalTransform
Full world transform.
Definition: OgreInstancedEntity.h:120
Ogre::InstancedEntity::visitRenderables
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
Definition: OgreInstancedEntity.h:207
Ogre::AnimationStateSet
Class encapsulating a set of AnimationState objects.
Definition: OgreAnimationState.h:196
Ogre::InstancedEntity::getSkeleton
SkeletonInstance * getSkeleton(void) const
Definition: OgreInstancedEntity.h:212
Ogre::InstancedEntity::mUseLocalTransform
bool mUseLocalTransform
Tells whether to use the local transform parameters.
Definition: OgreInstancedEntity.h:126
Ogre::Matrix4
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::InstancedEntity::getPosition
const Vector3 & getPosition() const
Retrieve the position.
Definition: OgreInstancedEntity.h:230
Ogre::InstancedEntity::isInScene
virtual bool isInScene(void) const
Definition: OgreInstancedEntity.h:270
OgreNode.h
Ogre::InstancedEntity::mBatchOwner
InstanceBatch * mBatchOwner
Definition: OgreInstancedEntity.h:87
Ogre::SkeletonInstance
A SkeletonInstance is a single instance of a Skeleton used by a world object.
Definition: OgreSkeletonInstance.h:53
Ogre::Renderable::Visitor
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
Definition: OgreRenderable.h:377
Ogre::Node
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:64
Ogre::InstancedEntity::isInUse
bool isInUse() const
Tells if the entity is in use.
Definition: OgreInstancedEntity.h:251
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::InstancedEntity::hasSkeleton
bool hasSkeleton(void) const
Definition: OgreInstancedEntity.h:210
Ogre::InstancedEntity::getOrientation
const Quaternion & getOrientation() const
Retrieve the orientation.
Definition: OgreInstancedEntity.h:235
Ogre::InstancedEntity::InstancedEntityVec
vector< InstancedEntity * >::type InstancedEntityVec
Stores the master when we&#39;re the slave, store our slaves when we&#39;re the master.
Definition: OgreInstancedEntity.h:102
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
OgreHeaderSuffix.h
Ogre::InstancedEntity::mInstanceId
uint16 mInstanceId
Definition: OgreInstancedEntity.h:85
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::InstanceBatch
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Definition: OgreInstanceBatch.h:88
Ogre::InstancedEntity::mScale
Vector3 mScale
Object scale.
Definition: OgreInstancedEntity.h:116
Ogre::InstancedEntity::mSkeletonInstance
SkeletonInstance * mSkeletonInstance
Definition: OgreInstancedEntity.h:90
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::InstancedEntity::mNeedAnimTransformUpdate
bool mNeedAnimTransformUpdate
Tells if the animation world transform needs an update.
Definition: OgreInstancedEntity.h:124
Ogre::InstancedEntity::mAnimationState
AnimationStateSet * mAnimationState
Definition: OgreInstancedEntity.h:89
Ogre::InstancedEntity::mPosition
Vector3 mPosition
Object position.
Definition: OgreInstancedEntity.h:111
Ogre::vector
Definition: OgrePrerequisites.h:491
OgreHeaderPrefix.h
Ogre::InstancedEntity::_getOwner
InstanceBatch * _getOwner() const
Definition: OgreInstancedEntity.h:190
Ogre::BaseInstanceBatchVTF
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
Definition: OgreInstanceBatchVTF.h:74
Ogre::AnimationState
Represents the state of an animation and the weight of its influence.
Definition: OgreAnimationState.h:54
Ogre::InstanceBatchShader
This is the same technique the old "InstancedGeometry" implementation used (with improvements).
Definition: OgreInstanceBatchShader.h:66
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::InstancedEntity
Definition: OgreInstancedEntity.h:77
Ogre::InstancedEntity::mInUse
bool mInUse
Definition: OgreInstancedEntity.h:86
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::InstanceBatchHW
This is technique requires true instancing hardware support.
Definition: OgreInstanceBatchHW.h:61
Ogre::InstancedEntity::mFrameAnimationLastUpdated
unsigned long mFrameAnimationLastUpdated
Definition: OgreInstancedEntity.h:93
Ogre::InstancedEntity::mBoneMatrices
Matrix4 * mBoneMatrices
Definition: OgreInstancedEntity.h:91
Ogre::InstancedEntity::_updateRenderQueue
void _updateRenderQueue(RenderQueue *queue)
Do nothing, InstanceBatch takes care of this.
Definition: OgreInstancedEntity.h:206
Ogre::Vector3::ZERO
static const Vector3 ZERO
Definition: OgreVector3.h:800

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