1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GRIM_ANIMATIONEMI_H
24 #define GRIM_ANIMATIONEMI_H
25 
26 #include "common/str.h"
27 #include "math/mathfwd.h"
28 #include "math/quat.h"
29 #include "engines/grim/animation.h"
30 #include "engines/grim/object.h"
31 #include "engines/grim/emi/skeleton.h"
32 
33 namespace Grim {
34 
35 struct AnimRotation {
36 	Math::Quaternion _quat;
37 	float _time;
38 };
39 
40 struct AnimTranslation {
41 	Math::Vector3d _vec;
42 	float _time;
43 };
44 
45 struct Bone {
46 	Common::String _boneName;
47 	int _operation;
48 	int _priority;
49 	int _c;
50 	int _count;
51 	AnimRotation *_rotations;
52 	AnimTranslation *_translations;
53 	Joint *_target;
BoneBone54 	Bone() : _rotations(NULL), _translations(NULL), _boneName(""), _operation(0), _target(NULL) {}
55 	~Bone();
56 	void loadBinary(Common::SeekableReadStream *data);
57 };
58 
59 class AnimationEmi : public Object {
60 	void loadAnimation(Common::SeekableReadStream *data);
61 public:
62 	Common::String _name;
63 	Common::String _fname;
64 	float _duration;
65 	int _numBones;
66 	Bone *_bones;
67 	AnimationEmi(const Common::String &filename, Common::SeekableReadStream *data);
68 	~AnimationEmi();
69 
getFilename()70 	const Common::String &getFilename() const { return _fname; }
71 };
72 
73 class AnimationStateEmi {
74 public:
75 	AnimationStateEmi(const Common::String &anim);
76 	~AnimationStateEmi();
77 
78 	void update(uint time);
79 	void computeWeights();
80 	void animate();
81 	void play();
82 	void stop();
83 	void setPaused(bool paused);
84 	void setLooping(bool loop);
85 	void setSkeleton(Skeleton *skel);
86 	void fade(Animation::FadeMode mode, int fadeLength);
87 	void advance(uint msecs);
88 	void saveState(SaveGame *state);
89 	void restoreState(SaveGame *state);
90 
91 private:
92 	void activate();
93 	void deactivate();
94 
95 	friend class Skeleton;
96 
97 	Skeleton *_skel;
98 	ObjectPtr<AnimationEmi> _anim;
99 	bool _looping;
100 	bool _active;
101 	bool _paused;
102 	int _time;
103 	float _fade;
104 	float _startFade;
105 	Animation::FadeMode _fadeMode;
106 	int _fadeLength;
107 	int *_boneJoints;
108 };
109 
110 } // end of namespace Grim
111 
112 #endif
113