OgreInstancedEntity.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __InstancedEntity_H__
00029 #define __InstancedEntity_H__
00030 
00031 #include "OgreMovableObject.h"
00032 #include "OgreNode.h"
00033 
00034 namespace Ogre
00035 {
00076     class _OgreExport InstancedEntity : public Ogre::MovableObject
00077     {
00078         friend class InstanceBatch;
00079         friend class InstanceBatchShader;
00080         friend class InstanceBatchHW;
00081         friend class InstanceBatchHW_VTF;
00082         friend class BaseInstanceBatchVTF;
00083     protected:
00084         uint16 mInstanceId; //Note it may change after defragmenting!
00085         bool mInUse;
00086         InstanceBatch *mBatchOwner;
00087 
00088         AnimationStateSet *mAnimationState;
00089         SkeletonInstance *mSkeletonInstance;
00090         Matrix4 *mBoneMatrices;  //Local space
00091         Matrix4 *mBoneWorldMatrices; //World space
00092         unsigned long mFrameAnimationLastUpdated;
00093 
00094         InstancedEntity* mSharedTransformEntity;    //When not null, another InstancedEntity controls the skeleton
00095                                                 
00098         uint16 mTransformLookupNumber;
00099 
00101         typedef vector<InstancedEntity*>::type InstancedEntityVec;
00102         InstancedEntityVec mSharingPartners;
00103 
00105         // Parameters used for local transformation offset information
00106         // The 
00108 
00110         Vector3 mPosition;
00111         Vector3 mDerivedLocalPosition;
00113         Quaternion mOrientation;
00115         Vector3 mScale;
00117         Real mMaxScaleLocal;
00119         Matrix4 mFullLocalTransform;
00121         bool mNeedTransformUpdate;
00123         bool mNeedAnimTransformUpdate;
00125         bool mUseLocalTransform;
00126 
00127 
00129         size_t getTransforms( Matrix4 *xform ) const;
00131         size_t getTransforms3x4( float *xform ) const;
00132 
00134         bool findVisible( Camera *camera ) const;
00135 
00137         void createSkeletonInstance();
00138         void destroySkeletonInstance();
00139 
00141         void unlinkTransform();
00142 
00144         void notifyUnlink( const InstancedEntity *slave );
00145 
00147         inline void markTransformDirty();
00148 
00150         static NameGenerator msNameGenerator;
00151 
00152     public:
00153         InstancedEntity( InstanceBatch *batchOwner, uint32 instanceID, InstancedEntity* sharedTransformEntity = NULL);
00154         virtual ~InstancedEntity();
00155 
00174         bool shareTransformWith( InstancedEntity *slave );
00175 
00183         void stopSharingTransform();
00184 
00185         InstanceBatch* _getOwner() const { return mBatchOwner; }
00186 
00187         const String& getMovableType(void) const;
00188 
00189         const AxisAlignedBox& getBoundingBox(void) const;
00190         Real getBoundingRadius(void) const;
00191 
00194         Real getSquaredViewDepth( const Camera* cam ) const;
00195 
00197         void _notifyMoved(void);
00198         void _notifyAttached( Node* parent, bool isTagPoint = false );
00199 
00201         void _updateRenderQueue( RenderQueue* queue )   {}
00202         void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false ) {}
00203 
00205         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
00207         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
00208 
00210         AnimationState* getAnimationState(const String& name) const;
00212         AnimationStateSet* getAllAnimationStates(void) const;
00213 
00219         virtual bool _updateAnimation(void);
00220 
00222         void setTransformLookupNumber(uint16 num) { mTransformLookupNumber = num;}
00223 
00225         const Vector3& getPosition() const { return mPosition; }
00227         void setPosition(const Vector3& position, bool doUpdate = true);
00228 
00230         const Quaternion& getOrientation() const { return mOrientation; }
00232         void setOrientation(const Quaternion& orientation, bool doUpdate = true);
00233 
00235         const Vector3& getScale() const { return mScale; }
00237         void setScale(const Vector3& scale, bool doUpdate = true);
00238 
00240         Real getMaxScaleCoef() const;
00241 
00243         void updateTransforms();
00244 
00246         bool isInUse() const { return mInUse; }
00248         void setInUse(bool used);
00249 
00251         virtual const Matrix4& _getParentNodeFullTransform(void) const { 
00252             assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
00253             return mUseLocalTransform ? mFullLocalTransform :
00254                 mParentNode ? mParentNode->_getFullTransform() : Matrix4::IDENTITY;
00255         }
00256 
00258         const Vector3& _getDerivedPosition() const {
00259             assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
00260             return mUseLocalTransform ? mDerivedLocalPosition :
00261                 mParentNode ? mParentNode->_getDerivedPosition() : Vector3::ZERO;
00262         }
00263 
00265         virtual bool isInScene(void) const
00266         {
00267             //We assume that the instanced entity is in the scene if it is in use
00268             //It is in the scene whether it has a parent node or not
00269             return mInUse;
00270         }
00271 
00272 
00273 
00274     };
00275 }
00276 
00277 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012