OpenMW
apps/openmw/mwrender/npcanimation.hpp
Go to the documentation of this file.
00001 #ifndef _GAME_RENDER_NPCANIMATION_H
00002 #define _GAME_RENDER_NPCANIMATION_H
00003 
00004 #include "animation.hpp"
00005 
00006 #include "../mwworld/inventorystore.hpp"
00007 
00008 namespace ESM
00009 {
00010     struct NPC;
00011 }
00012 
00013 namespace MWRender
00014 {
00015 
00016 class SayAnimationValue : public Ogre::ControllerValue<Ogre::Real>
00017 {
00018 private:
00019     MWWorld::Ptr mReference;
00020 public:
00021     SayAnimationValue(MWWorld::Ptr reference) : mReference(reference) {}
00022 
00023     virtual Ogre::Real getValue() const;
00024     virtual void setValue(Ogre::Real value)
00025     { }
00026 };
00027 
00028 class NpcAnimation : public Animation, public MWWorld::InventoryStoreListener
00029 {
00030 public:
00031     virtual void equipmentChanged() { updateParts(); }
00032     virtual void permanentEffectAdded(const ESM::MagicEffect *magicEffect, bool isNew, bool playSound);
00033 
00034 public:
00035     typedef std::map<ESM::PartReferenceType,std::string> PartBoneMap;
00036 
00037     enum ViewMode {
00038         VM_Normal,
00039         VM_FirstPerson,
00040         VM_HeadOnly
00041     };
00042 
00043 private:
00044     static const PartBoneMap sPartList;
00045 
00046     bool mListenerDisabled;
00047 
00048     // Bounded Parts
00049     NifOgre::ObjectScenePtr mObjectParts[ESM::PRT_Count];
00050 
00051     const ESM::NPC *mNpc;
00052     std::string    mHeadModel;
00053     std::string    mHairModel;
00054     ViewMode       mViewMode;
00055     bool mShowWeapons;
00056     bool mShowCarriedLeft;
00057 
00058     int mVisibilityFlags;
00059 
00060     int mPartslots[ESM::PRT_Count];  //Each part slot is taken by clothing, armor, or is empty
00061     int mPartPriorities[ESM::PRT_Count];
00062 
00063     Ogre::Vector3 mFirstPersonOffset;
00064 
00065     Ogre::SharedPtr<SayAnimationValue> mSayAnimationValue;
00066 
00067     float mAlpha;
00068 
00069     void updateNpcBase();
00070 
00071     NifOgre::ObjectScenePtr insertBoundedPart(const std::string &model, int group, const std::string &bonename,
00072                                           bool enchantedGlow, Ogre::Vector3* glowColor=NULL);
00073 
00074     void removeIndividualPart(ESM::PartReferenceType type);
00075     void reserveIndividualPart(ESM::PartReferenceType type, int group, int priority);
00076 
00077     bool addOrReplaceIndividualPart(ESM::PartReferenceType type, int group, int priority, const std::string &mesh,
00078                                     bool enchantedGlow=false, Ogre::Vector3* glowColor=NULL);
00079     void removePartGroup(int group);
00080     void addPartGroup(int group, int priority, const std::vector<ESM::PartReference> &parts,
00081                                     bool enchantedGlow=false, Ogre::Vector3* glowColor=NULL);
00082 
00083     void applyAlpha(float alpha, Ogre::Entity* ent, NifOgre::ObjectScenePtr scene);
00084 
00085 public:
00096     NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener = false,
00097                  ViewMode viewMode=VM_Normal);
00098     virtual ~NpcAnimation();
00099 
00100     virtual Ogre::Vector3 runAnimation(float timepassed);
00101 
00102     virtual void showWeapons(bool showWeapon);
00103     virtual void showCarriedLeft(bool showa);
00104 
00105     void setViewMode(ViewMode viewMode);
00106 
00107     void updateParts();
00108 
00112     void addFirstPersonOffset(const Ogre::Vector3 &offset);
00113 
00115     void rebuild();
00116 
00118     virtual void setAlpha(float alpha);
00119 
00121     virtual void preRender (Ogre::Camera* camera);
00122 };
00123 
00124 }
00125 
00126 #endif