浏览代码

Added SkeletalModel, now using std::vector

Thomas Buck 11 年前
父节点
当前提交
2e2c4e2693
共有 3 个文件被更改,包括 198 次插入0 次删除
  1. 94
    0
      include/SkeletalModel.h
  2. 1
    0
      src/CMakeLists.txt
  3. 103
    0
      src/SkeletalModel.cpp

+ 94
- 0
include/SkeletalModel.h 查看文件

@@ -0,0 +1,94 @@
1
+/*!
2
+ * \file include/SkeletalModel.h
3
+ * \brief This is the factored out skeletal model class
4
+ *
5
+ * \author Mongoose
6
+ * \author xythobuz
7
+ *
8
+ * \todo Start cutting off old hacks by simple force use of method interface.
9
+ * Also move the publicly exposed attributes out  =)
10
+ * Better animation system in general - this is memory wasteful
11
+ */
12
+
13
+#ifndef _SKELETALMODEL_H_
14
+#define _SKELETALMODEL_H_
15
+
16
+#include <vector>
17
+
18
+#include "math/math.h"
19
+
20
+typedef struct {
21
+    int mesh;
22
+    vec3_t off;
23
+    vec3_t rot;
24
+    char flag;
25
+} bone_tag_t;
26
+
27
+typedef struct {
28
+    std::vector<bone_tag_t *> tag;
29
+    vec3_t pos;
30
+    float yaw;
31
+} bone_frame_t;
32
+
33
+typedef struct {
34
+    int id;
35
+    char rate;
36
+    std::vector<bone_frame_t *> frame;
37
+} animation_frame_t;
38
+
39
+typedef struct {
40
+    int id;
41
+    bool tr4Overlay;
42
+    bool pigtails;
43
+    int ponytailId;
44
+    vec3_t ponytail;
45
+    int ponytailMeshId;
46
+    unsigned int ponytailNumMeshes;
47
+    float ponytailAngle;
48
+    float ponyOff;
49
+    float ponyOff2;
50
+    std::vector<animation_frame_t *> animation;
51
+} skeletal_model_t;
52
+
53
+/*!
54
+ * \brief This is the factored out skeletal model class
55
+ */
56
+class SkeletalModel {
57
+public:
58
+    /*!
59
+     * \brief Constructs an object of SkeletalModel
60
+     */
61
+    SkeletalModel();
62
+
63
+     /*!
64
+     * \brief Deconstructs an object of SkeletalModel
65
+     */
66
+    ~SkeletalModel();
67
+
68
+    int getAnimation();
69
+
70
+    int getFrame();
71
+
72
+    int getIdleAnimation();
73
+
74
+    void setModel(skeletal_model_t *mdl);
75
+
76
+    void setAnimation(int index);
77
+
78
+    void setFrame(int index);
79
+
80
+    void setIdleAnimation(int index);
81
+
82
+    unsigned int flags;
83
+    skeletal_model_t *model; //!< World render model
84
+    float time;              //!< Interpolation use
85
+    float lastTime;
86
+    float rate;              //!< \fixme temp cache this here for old animation system use
87
+
88
+private:
89
+    int mBoneFrame;      //!< Bone frame
90
+    int mAnimationFrame; //!< Animation frame
91
+    int mIdleAnimation;  //!< Idle animation
92
+};
93
+
94
+#endif

+ 1
- 0
src/CMakeLists.txt 查看文件

@@ -40,6 +40,7 @@ set (SRCS ${SRCS} "Menu.cpp")
40 40
 set (SRCS ${SRCS} "Mesh.cpp")
41 41
 set (SRCS ${SRCS} "OpenRaider.cpp")
42 42
 set (SRCS ${SRCS} "Particle.cpp")
43
+set (SRCS ${SRCS} "SkeletalModel.cpp")
43 44
 set (SRCS ${SRCS} "Sound.cpp")
44 45
 set (SRCS ${SRCS} "TombRaider.cpp")
45 46
 set (SRCS ${SRCS} "ViewVolume.cpp")

+ 103
- 0
src/SkeletalModel.cpp 查看文件

@@ -0,0 +1,103 @@
1
+/*!
2
+ * \file src/SkeletalModel.cpp
3
+ * \brief This is the factored out skeletal model class
4
+ *
5
+ * \author Mongoose
6
+ * \author xythobuz
7
+ */
8
+
9
+#include "SkeletalModel.h"
10
+
11
+SkeletalModel::SkeletalModel() {
12
+    model = NULL;
13
+    flags = 0;
14
+    mBoneFrame = 0;
15
+    mAnimationFrame = 0;
16
+    mIdleAnimation = 0;
17
+    time = 0.0f;
18
+    lastTime = 0.0f;
19
+    rate = 0.0f;
20
+}
21
+
22
+SkeletalModel::~SkeletalModel() {
23
+    if (model) {
24
+        for(std::vector<animation_frame_t>::size_type i = 0; i < model->animation.size(); i++) {
25
+            animation_frame_t *af = model->animation[i];
26
+
27
+            if (!af)
28
+                continue;
29
+
30
+            for(std::vector<bone_frame_t>::size_type j = 0; j < af->frame.size(); j++) {
31
+                bone_frame_t *bf = af->frame[j];
32
+
33
+                if (!bf)
34
+                    continue;
35
+
36
+                for(std::vector<bone_tag_t>::size_type k = 0; k < bf->tag.size(); k++) {
37
+                    if (bf->tag[i])
38
+                        delete bf->tag[i];
39
+                }
40
+
41
+                delete bf;
42
+            }
43
+
44
+            delete af;
45
+        }
46
+
47
+        // \fixme Causes "freeing already freed pointer" exception
48
+        delete model;
49
+    }
50
+}
51
+
52
+int SkeletalModel::getAnimation() {
53
+    return mAnimationFrame;
54
+}
55
+
56
+int SkeletalModel::getFrame() {
57
+    return mBoneFrame;
58
+}
59
+
60
+int SkeletalModel::getIdleAnimation() {
61
+    return mIdleAnimation;
62
+}
63
+
64
+void SkeletalModel::setModel(skeletal_model_t *mdl) {
65
+    if (mdl)
66
+        model = mdl;
67
+}
68
+
69
+void SkeletalModel::setAnimation(int index) {
70
+    if (!model) // index > (int)model->animation.size())
71
+        return;
72
+
73
+    animation_frame_t *a = model->animation[index];
74
+
75
+    if (a) {
76
+        mAnimationFrame = index;
77
+        mBoneFrame = 0;
78
+        rate = a->rate;
79
+    }
80
+}
81
+
82
+void SkeletalModel::setFrame(int index) {
83
+    if (!model)
84
+        return;
85
+
86
+    animation_frame_t *a = model->animation[mAnimationFrame];
87
+
88
+    if (a) { // index > (int)a->frame.size())
89
+        bone_frame_t *b = a->frame[index];
90
+
91
+        if (b)
92
+            mBoneFrame = index;
93
+    }
94
+}
95
+
96
+void SkeletalModel::setIdleAnimation(int index) {
97
+    if (!model)
98
+        return;
99
+
100
+    if (model->animation[index])
101
+        mIdleAnimation = index;
102
+}
103
+

正在加载...
取消
保存