Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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);
00463         TagPoint* attachObjectToBone(const String &boneName, 
00464             MovableObject *pMovable, 
00465             const Quaternion &offsetOrientation = Quaternion::IDENTITY, 
00466             const Vector3 &offsetPosition = Vector3::ZERO);
00467 
00469         MovableObject* detachObjectFromBone(const String &movableName);
00470 
00477         void detachObjectFromBone(MovableObject* obj);
00478 
00480         void detachAllObjectsFromBone(void);
00481 
00482         typedef MapIterator<ChildObjectList> ChildObjectListIterator;
00484         ChildObjectListIterator getAttachedObjectIterator(void);
00486         Real getBoundingRadius(void) const;
00487 
00489         const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
00491         const Sphere& getWorldBoundingSphere(bool derive = false) const;
00492 
00501         void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
00502 
00504         bool getNormaliseNormals(void) const {return mNormaliseNormals; }
00505 
00506 
00508         EdgeData* getEdgeList(void);
00510         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
00511             ShadowTechnique shadowTechnique, const Light* light, 
00512             HardwareIndexBufferSharedPtr* indexBuffer, 
00513             bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
00514 
00516         const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
00518         unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
00520         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
00522         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
00534         bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; }
00535 
00537         void _notifyAttached(Node* parent, bool isTagPoint = false);
00545         int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
00557         int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
00573         void addSoftwareAnimationRequest(bool normalsAlso);
00582         void removeSoftwareAnimationRequest(bool normalsAlso);
00583 
00588         void shareSkeletonInstanceWith(Entity* entity);
00589 
00592         bool hasVertexAnimation(void) const;
00593 
00594 
00597         void stopSharingSkeletonInstance();
00598 
00599 
00603         inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
00604 
00609         inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
00610 
00621         void refreshAvailableAnimationState(void);
00622 
00630         void _updateAnimation(void);
00631 
00637         bool _isAnimated(void) const;
00638 
00641         bool _isSkeletonAnimated(void) const;
00642 
00652         VertexData* _getSkelAnimVertexData(void) const;
00661         VertexData* _getSoftwareVertexAnimVertexData(void) const;
00666         VertexData* _getHardwareVertexAnimVertexData(void) const;
00670         TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
00674         TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
00676         uint32 getTypeFlags(void) const;
00678         VertexData* getVertexDataForBinding(void);
00679 
00681         enum VertexDataBindChoice 
00682         {
00683             BIND_ORIGINAL,
00684             BIND_SOFTWARE_SKELETAL,
00685             BIND_SOFTWARE_MORPH,
00686             BIND_HARDWARE_MORPH
00687         };
00689         VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const;
00690 
00692         bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
00695         void _markBuffersUsedForAnimation(void);
00696 
00697 
00698     };
00699 
00701     class _OgreExport EntityFactory : public MovableObjectFactory
00702     {
00703     protected:
00704         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00705     public:
00706         EntityFactory() {}
00707         ~EntityFactory() {}
00708 
00709         static String FACTORY_TYPE_NAME;
00710 
00711         const String& getType(void) const;
00712         void destroyInstance( MovableObject* obj);  
00713 
00714     };
00715 
00716 } // namespace
00717 
00718 #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 Mar 12 14:37:40 2006