summaryrefslogtreecommitdiffstats
path: root/src/animation/AnimBlendSequence.h
blob: b370c5c66070cb904228b906ede0a1edbb74b1d1 (plain) (blame)
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
#pragma once

#include "Quaternion.h"

// TODO: put them somewhere else?
struct KeyFrame {
	CQuaternion rotation;
	float deltaTime;	// relative to previous key frame
};

struct KeyFrameTrans : KeyFrame {
	CVector translation;
};

struct KeyFrameCompressed {
	int16 rot[4];		// 4096
	int16 deltaTime;	// 60

	void GetRotation(CQuaternion *quat){
		float scale = 1.0f/4096.0f;
		quat->x = rot[0]*scale;
		quat->y = rot[1]*scale;
		quat->z = rot[2]*scale;
		quat->w = rot[3]*scale;
	}
	void SetRotation(const CQuaternion &quat){
		rot[0] = quat.x * 4096.0f;
		rot[1] = quat.y * 4096.0f;
		rot[2] = quat.z * 4096.0f;
		rot[3] = quat.w * 4096.0f;
	}
	float GetDeltaTime(void) { return deltaTime/60.0f; }
	void SetTime(float t) { deltaTime = t*60.0f + 0.5f; }
};

struct KeyFrameTransCompressed : KeyFrameCompressed {
	int16 trans[3];		// 1024

	void GetTranslation(CVector *vec) {
		float scale = 1.0f/1024.0f;
		vec->x = trans[0]*scale;
		vec->y = trans[1]*scale;
		vec->z = trans[2]*scale;
	}
	void SetTranslation(const CVector &vec){
		trans[0] = vec.x*1024.0f;
		trans[1] = vec.y*1024.0f;
		trans[2] = vec.z*1024.0f;
	}
};


// The sequence of key frames of one animated node
class CAnimBlendSequence
{
public:
	enum {
		KF_ROT = 1,
		KF_TRANS = 2
	};
	int32 type;
	char name[24];
	int32 numFrames;
	int16 boneTag;
	void *keyFrames;
	void *keyFramesCompressed;

	CAnimBlendSequence(void);
	virtual ~CAnimBlendSequence(void);
	void SetName(char *name);
	void SetNumFrames(int numFrames, bool translation, bool compressed);
	void RemoveQuaternionFlips(void);
	KeyFrame *GetKeyFrame(int n) {
		return type & KF_TRANS ?
			&((KeyFrameTrans*)keyFrames)[n] :
			&((KeyFrame*)keyFrames)[n];
	}
	KeyFrameCompressed *GetKeyFrameCompressed(int n) {
		return type & KF_TRANS ?
			&((KeyFrameTransCompressed*)keyFramesCompressed)[n] :
			&((KeyFrameCompressed*)keyFramesCompressed)[n];
	}
	bool HasTranslation(void) { return !!(type & KF_TRANS); }
	void Uncompress(void);
	void CompressKeyframes(void);
	void RemoveUncompressedData(void);

	void SetBoneTag(int tag) { boneTag = tag; }
};
VALIDATE_SIZE(CAnimBlendSequence, 0x30);