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-2013 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 #include "OgreHeaderPrefix.h"
00034 
00035 namespace Ogre
00036 {
00077     class _OgreExport InstancedEntity : public Ogre::MovableObject
00078     {
00079         friend class InstanceBatch;
00080         friend class InstanceBatchShader;
00081         friend class InstanceBatchHW;
00082         friend class InstanceBatchHW_VTF;
00083         friend class BaseInstanceBatchVTF;
00084     protected:
00085         uint16 mInstanceId; //Note it may change after defragmenting!
00086         bool mInUse;
00087         InstanceBatch *mBatchOwner;
00088 
00089         AnimationStateSet *mAnimationState;
00090         SkeletonInstance *mSkeletonInstance;
00091         Matrix4 *mBoneMatrices;  //Local space
00092         Matrix4 *mBoneWorldMatrices; //World space
00093         unsigned long mFrameAnimationLastUpdated;
00094 
00095         InstancedEntity* mSharedTransformEntity;    //When not null, another InstancedEntity controls the skeleton
00096                                                 
00099         uint16 mTransformLookupNumber;
00100 
00102         typedef vector<InstancedEntity*>::type InstancedEntityVec;
00103         InstancedEntityVec mSharingPartners;
00104 
00106         // Parameters used for local transformation offset information
00107         // The 
00109 
00111         Vector3 mPosition;
00112         Vector3 mDerivedLocalPosition;
00114         Quaternion mOrientation;
00116         Vector3 mScale;
00118         Real mMaxScaleLocal;
00120         Matrix4 mFullLocalTransform;
00122         bool mNeedTransformUpdate;
00124         bool mNeedAnimTransformUpdate;
00126         bool mUseLocalTransform;
00127 
00128 
00130         size_t getTransforms( Matrix4 *xform ) const;
00132         size_t getTransforms3x4( float *xform ) const;
00133 
00135         bool findVisible( Camera *camera ) const;
00136 
00138         void createSkeletonInstance();
00139         void destroySkeletonInstance();
00140 
00143         void stopSharingTransformAsSlave( bool notifyMaster );
00144 
00146         void unlinkTransform( bool notifyMaster=true );
00147 
00149         void notifyUnlink( const InstancedEntity *slave );
00150 
00152         inline void markTransformDirty();
00153 
00155         static NameGenerator msNameGenerator;
00156 
00157     public:
00158         InstancedEntity( InstanceBatch *batchOwner, uint32 instanceID, InstancedEntity* sharedTransformEntity = NULL);
00159         virtual ~InstancedEntity();
00160 
00179         bool shareTransformWith( InstancedEntity *slave );
00180 
00188         void stopSharingTransform();
00189 
00190         InstanceBatch* _getOwner() const { return mBatchOwner; }
00191 
00192         const String& getMovableType(void) const;
00193 
00194         const AxisAlignedBox& getBoundingBox(void) const;
00195         Real getBoundingRadius(void) const;
00196 
00199         Real getSquaredViewDepth( const Camera* cam ) const;
00200 
00202         void _notifyMoved(void);
00203         void _notifyAttached( Node* parent, bool isTagPoint = false );
00204 
00206         void _updateRenderQueue( RenderQueue* queue )   {}
00207         void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false ) {}
00208 
00210         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
00212         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
00213 
00215         AnimationState* getAnimationState(const String& name) const;
00217         AnimationStateSet* getAllAnimationStates(void) const;
00218 
00224         virtual bool _updateAnimation(void);
00225 
00227         void setTransformLookupNumber(uint16 num) { mTransformLookupNumber = num;}
00228 
00230         const Vector3& getPosition() const { return mPosition; }
00232         void setPosition(const Vector3& position, bool doUpdate = true);
00233 
00235         const Quaternion& getOrientation() const { return mOrientation; }
00237         void setOrientation(const Quaternion& orientation, bool doUpdate = true);
00238 
00240         const Vector3& getScale() const { return mScale; }
00242         void setScale(const Vector3& scale, bool doUpdate = true);
00243 
00245         Real getMaxScaleCoef() const;
00246 
00248         void updateTransforms();
00249 
00251         bool isInUse() const { return mInUse; }
00253         void setInUse(bool used);
00254 
00256         virtual const Matrix4& _getParentNodeFullTransform(void) const { 
00257             assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
00258             return mUseLocalTransform ? mFullLocalTransform :
00259                 mParentNode ? mParentNode->_getFullTransform() : Matrix4::IDENTITY;
00260         }
00261 
00263         const Vector3& _getDerivedPosition() const {
00264             assert((!mNeedTransformUpdate || !mUseLocalTransform) && "Transform data should be updated at this point");
00265             return mUseLocalTransform ? mDerivedLocalPosition :
00266                 mParentNode ? mParentNode->_getDerivedPosition() : Vector3::ZERO;
00267         }
00268 
00270         virtual bool isInScene(void) const
00271         {
00272             //We assume that the instanced entity is in the scene if it is in use
00273             //It is in the scene whether it has a parent node or not
00274             return mInUse;
00275         }
00276 
00288         void setCustomParam( unsigned char idx, const Vector4 &newParam );
00289         const Vector4& getCustomParam( unsigned char idx );
00290     };
00291 }
00292 
00293 #include "OgreHeaderSuffix.h"
00294 
00295 #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 Mon Jul 27 2020 13:40:43