File: SkeletonState.h

package info (click to toggle)
mygui 3.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,224 kB
  • sloc: cpp: 118,031; ansic: 30,202; xml: 15,544; cs: 12,602; tcl: 776; python: 417; makefile: 34
file content (117 lines) | stat: -rw-r--r-- 2,348 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*!
	@file
	@author		Albert Semenov
	@date		08/2009
*/
#ifndef SKELETON_STATE_H_
#define SKELETON_STATE_H_

#include <Ogre.h>
#include "IAnimationNode.h"
#include "IAnimationGraph.h"

namespace animation
{

	class SkeletonState :
		public IAnimationNode
	{
	public:
		SkeletonState() :
			mState(0)
		{
		}

		SkeletonState(const std::string& _name, IAnimationGraph* _graph) :
			IAnimationNode(_name, _graph),
			mState(0)
		{
		}

		virtual ~SkeletonState()
		{
			if (mState != 0) mState->setEnabled(false);
		}

		virtual void setEvent(const std::string& _name, float _value = 0)
		{
			if (!mState)
			{
				updateState();
				if (!mState) return;
			}

			if (_name == "Start") mState->setEnabled(true);
			else if (_name == "Stop") mState->setEnabled(false);
			else if (_name == "Position") mState->setTimePosition(_value);
			else if (_name == "Weight") mState->setWeight(_value);
		}

		virtual void addConnection(const std::string& _eventout, IAnimationNode* _node, const std::string& _eventin)
		{
			mConnections.push_back(PairOut(_eventout, PairIn(_node, _eventin)));
		}

		virtual void setProperty(const std::string& _key, const std::string& _value)
		{
			if (_key == "StateName")
			{
				if (mState != 0) mState->setEnabled(false);
				mState = 0;
				mStateName = _value;
			}
		}

		virtual float getLength()
		{
			if (!mState)
			{
				updateState();
				if (!mState) return 0;
			}
			return mState->getLength();
		}

		float getWeight()
		{
			if (mState == 0) return 0;
			return mState->getWeight();
		}

		float getPosition()
		{
			if (mState == 0) return 0;
			return mState->getTimePosition();
		}

		bool isEnabled()
		{
			if (mState == 0) return false;
			return mState->getEnabled();
		}

	private:
		void updateState()
		{
			Ogre::Any any = getGraph()->getData("OwnerEntity");
			if (!any.isEmpty())
			{
				Ogre::Entity* entity = Ogre::any_cast<Ogre::Entity*>(any);
				entity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
				mState = entity->getAnimationState(mStateName);
			}
		}

	private:
		Ogre::AnimationState* mState;
		typedef std::pair<IAnimationNode*, std::string> PairIn;
		typedef std::pair<std::string, PairIn> PairOut;
		typedef std::vector<PairOut> VectorPairOut;
		VectorPairOut mConnections;

		std::string mStateName;
	};

} // namespace animation

#endif // SKELETON_STATE_H_