Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OgreEntity.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://ogre.sourceforge.net/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef __Entity_H__
00026 #define __Entity_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 #include "OgreCommon.h"
00030 
00031 #include "OgreString.h"
00032 #include "OgreMovableObject.h"
00033 #include "OgreQuaternion.h"
00034 #include "OgreVector3.h"
00035 #include "OgreHardwareBufferManager.h"
00036 #include "OgreMesh.h"
00037 
00038 namespace Ogre {
00070     class _OgreExport Entity: public MovableObject
00071     {
00072         // Allow EntityFactory full access
00073         friend class EntityFactory;
00074         friend class SubEntity;
00075     public:
00076         typedef std::set<Entity*> EntitySet;
00077 
00078     protected:
00079 
00082         Entity();
00085         Entity( const String& name, MeshPtr& mesh);
00086 
00089         MeshPtr mMesh;
00090 
00093         typedef std::vector<SubEntity*> SubEntityList;
00094         SubEntityList mSubEntityList;
00095 
00096 
00098         AnimationStateSet* mAnimationState;
00099 
00100 
00102         TempBlendedBufferInfo mTempSkelAnimInfo;
00104         VertexData* mSkelAnimVertexData;
00106         TempBlendedBufferInfo mTempVertexAnimInfo;
00108         VertexData* mSoftwareVertexAnimVertexData;
00112         VertexData* mHardwareVertexAnimVertexData;
00114         bool mVertexAnimationAppliedThisFrame;
00116         bool mPreparedForShadowVolumes;
00117 
00120         const VertexData* findBlendedVertexData(const VertexData* orig);
00123         SubEntity* findSubEntityForVertexData(const VertexData* orig);
00124 
00127         void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info);
00129         VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source);
00131         void prepareTempBlendBuffers(void);
00134         void markBuffersUnusedForAnimation(void);
00138         void restoreBuffersForUnusedAnimation(bool hardwareAnimation);
00139 
00141         Matrix4 *mBoneWorldMatrices;
00143         Matrix4 *mBoneMatrices;
00144         unsigned short mNumBoneMatrices;
00146         unsigned long mFrameAnimationLastUpdated;
00147 
00149         void updateAnimation(void);
00150 
00154         unsigned long *mFrameBonesLastUpdated;
00155 
00161         EntitySet* mSharedSkeletonEntities;
00162 
00164         void cacheBoneMatrices(void);
00165 
00167         bool mDisplaySkeleton;
00169         bool mHardwareAnimation;
00171         ushort mHardwarePoseCount;
00173         bool mVertexProgramInUse;
00175         int mSoftwareAnimationRequests;
00177         int mSoftwareAnimationNormalsRequests;
00178 
00179 
00181         ushort mMeshLodIndex;
00182 
00184         Real mMeshLodFactorInv;
00186         ushort mMinMeshLodIndex;
00188         ushort mMaxMeshLodIndex;
00189 
00191         Real mMaterialLodFactorInv;
00193         ushort mMinMaterialLodIndex;
00195         ushort mMaxMaterialLodIndex;
00196 
00202         typedef std::vector<Entity*> LODEntityList;
00203         LODEntityList mLodEntityList;
00204 
00207         SkeletonInstance* mSkeletonInstance;
00208 
00210         Matrix4 mLastParentXform;
00211 
00213         void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist);
00214 
00216         void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint);
00217 
00219         void detachObjectImpl(MovableObject* pObject);
00220 
00222         void detachAllObjectsImpl(void);
00223 
00225         void reevaluateVertexProcessing(void);
00226 
00228         void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows);
00230         void initHardwareAnimationElements(VertexData* vdata,
00231             ushort numberOfElements);
00233         bool tempVertexAnimBuffersBound(void) const;
00235         bool tempSkelAnimBuffersBound(bool requestNormals) const;
00236 
00237     public:
00239         typedef std::map<String, MovableObject*> ChildObjectList;
00240     protected:
00241         ChildObjectList mChildObjectList;
00242 
00243 
00245         mutable AxisAlignedBox mFullBoundingBox;
00246 
00247         bool mNormaliseNormals;
00248 
00249         ShadowRenderableList mShadowRenderables;
00250 
00252         class _OgreExport EntityShadowRenderable : public ShadowRenderable
00253         {
00254         protected:
00255             Entity* mParent;
00256             // Shared link to position buffer
00257             HardwareVertexBufferSharedPtr mPositionBuffer;
00258             // Shared link to w-coord buffer (optional)
00259             HardwareVertexBufferSharedPtr mWBuffer;
00260             // Link to current vertex data used to bind (maybe changes)
00261             const VertexData* mCurrentVertexData;
00262             // Original position buffer source binding
00263             unsigned short mOriginalPosBufferBinding;
00265             SubEntity* mSubEntity;
00266 
00267 
00268         public:
00269             EntityShadowRenderable(Entity* parent,
00270                 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
00271                 bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false);
00272             ~EntityShadowRenderable();
00274             void getWorldTransforms(Matrix4* xform) const;
00276             const Quaternion& getWorldOrientation(void) const;
00278             const Vector3& getWorldPosition(void) const;
00279             HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
00280             HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
00282             void rebindPositionBuffer(const VertexData* vertexData, bool force);
00284             bool isVisible(void) const;
00285 
00286         };
00287     public:
00290         ~Entity();
00291 
00294         const MeshPtr& getMesh(void) const;
00295 
00298         SubEntity* getSubEntity(unsigned int index) const;
00299 
00303         SubEntity* getSubEntity( const String& name ) const;
00304 
00307         unsigned int getNumSubEntities(void) const;
00308 
00318         Entity* clone( const String& newName ) const;
00319 
00328         void setMaterialName(const String& name);
00329 
00332         void _notifyCurrentCamera(Camera* cam);
00333 
00335         void setRenderQueueGroup(uint8 queueID);
00336 
00339         const AxisAlignedBox& getBoundingBox(void) const;
00340 
00342         AxisAlignedBox getChildObjectsBoundingBox(void) const;
00343 
00346         void _updateRenderQueue(RenderQueue* queue);
00347 
00349         const String& getMovableType(void) const;
00350 
00357         AnimationState* getAnimationState(const String& name) const;
00367         AnimationStateSet* getAllAnimationStates(void) const;
00368 
00371         void setDisplaySkeleton(bool display);
00372 
00375         bool getDisplaySkeleton(void) const;
00376 
00377 
00383         Entity* getManualLodLevel(size_t index) const;
00384 
00390         size_t getNumManualLodLevels(void) const;
00391 
00418         void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
00419 
00446         void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
00447 
00451         void setPolygonModeOverrideable(bool PolygonModeOverrideable);
00466         TagPoint* attachObjectToBone(const String &boneName,
00467             MovableObject *pMovable,
00468             const Quaternion &offsetOrientation = Quaternion::IDENTITY,
00469             const Vector3 &offsetPosition = Vector3::ZERO);
00470 
00475         MovableObject* detachObjectFromBone(const String &movableName);
00476 
00483         void detachObjectFromBone(MovableObject* obj);
00484 
00486         void detachAllObjectsFromBone(void);
00487 
00488         typedef MapIterator<ChildObjectList> ChildObjectListIterator;
00490         ChildObjectListIterator getAttachedObjectIterator(void);
00492         Real getBoundingRadius(void) const;
00493 
00495         const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
00497         const Sphere& getWorldBoundingSphere(bool derive = false) const;
00498 
00507         void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
00508 
00510         bool getNormaliseNormals(void) const {return mNormaliseNormals; }
00511 
00512 
00514         EdgeData* getEdgeList(void);
00516         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
00517             ShadowTechnique shadowTechnique, const Light* light,
00518             HardwareIndexBufferSharedPtr* indexBuffer,
00519             bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
00520 
00522         const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
00524         unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
00526         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
00528         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
00540         bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; }
00541 
00543         void _notifyAttached(Node* parent, bool isTagPoint = false);
00551         int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
00563         int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
00579         void addSoftwareAnimationRequest(bool normalsAlso);
00588         void removeSoftwareAnimationRequest(bool normalsAlso);
00589 
00594         void shareSkeletonInstanceWith(Entity* entity);
00595 
00598         bool hasVertexAnimation(void) const;
00599 
00600 
00603         void stopSharingSkeletonInstance();
00604 
00605 
00609         inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
00610 
00615         inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
00616 
00627         void refreshAvailableAnimationState(void);
00628 
00636         void _updateAnimation(void);
00637 
00643         bool _isAnimated(void) const;
00644 
00647         bool _isSkeletonAnimated(void) const;
00648 
00658         VertexData* _getSkelAnimVertexData(void) const;
00667         VertexData* _getSoftwareVertexAnimVertexData(void) const;
00672         VertexData* _getHardwareVertexAnimVertexData(void) const;
00676         TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
00680         TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
00682         uint32 getTypeFlags(void) const;
00684         VertexData* getVertexDataForBinding(void);
00685 
00687         enum VertexDataBindChoice
00688         {
00689             BIND_ORIGINAL,
00690             BIND_SOFTWARE_SKELETAL,
00691             BIND_SOFTWARE_MORPH,
00692             BIND_HARDWARE_MORPH
00693         };
00695         VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const;
00696 
00698         bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
00701         void _markBuffersUsedForAnimation(void);
00702 
00703 
00704     };
00705 
00707     class _OgreExport EntityFactory : public MovableObjectFactory
00708     {
00709     protected:
00710         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00711     public:
00712         EntityFactory() {}
00713         ~EntityFactory() {}
00714 
00715         static String FACTORY_TYPE_NAME;
00716 
00717         const String& getType(void) const;
00718         void destroyInstance( MovableObject* obj);
00719 
00720     };
00721 
00722 } // namespace
00723 
00724 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Nov 12 10:50:10 2006