ScummVM API documentation
model.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM 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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef STARK_MODEL_MODEL_H
23 #define STARK_MODEL_MODEL_H
24 
25 #include "common/array.h"
26 #include "common/str.h"
27 
28 #include "math/ray.h"
29 #include "math/vector3d.h"
30 
31 namespace Stark {
32 
33 namespace Gfx {
34 class TextureSet;
35 }
36 
37 class ArchiveReadStream;
38 
39 class VertNode {
40 public:
41  Math::Vector3d _pos1, _pos2;
42  Math::Vector3d _normal;
43  float _texS, _texT;
44  uint32 _bone1, _bone2;
45  float _boneWeight;
46 };
47 
48 struct Face {
49  uint32 materialId;
50  Common::Array<uint32> vertexIndices;
51 
52  Face() : materialId(0) {}
53 };
54 
55 struct Material {
56  Common::String name;
57  Common::String texture;
58  float r, g, b;
59  bool doubleSided;
60 
61  Material() : r(0), g(0), b(0), doubleSided(false) {};
62 };
63 
64 class BoneNode {
65 public:
66  BoneNode() : _parent(-1), _idx(0), _u1(0) {}
67  ~BoneNode() { }
68 
70  bool intersectRay(const Math::Ray &ray) const;
71 
73  void expandModelSpaceBB(Math::AABB &aabb) const;
74 
75  Common::String _name;
76  float _u1;
77  Common::Array<uint32> _children;
78  int _parent;
79  uint32 _idx;
80 
81  Math::Vector3d _animPos;
82  Math::Quaternion _animRot;
83 
85  Math::AABB _boundingBox;
86 };
87 
91 class Model {
92 public:
93  Model();
94  ~Model();
95 
99  void readFromStream(ArchiveReadStream *stream);
100 
101  const Common::Array<VertNode *> &getVertices() const { return _vertices; }
102  const Common::Array<Face *> &getFaces() const { return _faces; }
103  const Common::Array<Material *> &getMaterials() const { return _materials; }
104  const Common::Array<BoneNode *> &getBones() const { return _bones; };
105 
107  bool intersectRay(const Math::Ray &ray) const;
108 
110  void updateBoundingBox();
111 
113  Math::AABB getBoundingBox() const;
114 
115 private:
116  void buildBonesBoundingBoxes();
117  void buildBoneBoundingBox(BoneNode *bone) const;
118  void readBones(ArchiveReadStream *stream);
119 
120  Common::String _name;
121  uint32 _u1;
122  float _u2;
123 
124  Common::Array<VertNode *> _vertices;
125  Common::Array<Material *> _materials;
126  Common::Array<Face *> _faces;
128  Math::AABB _boundingBox;
129 };
130 
131 } // End of namespace Stark
132 
133 #endif // STARK_MODEL_MODEL_H
Definition: str.h:59
Definition: model.h:91
Definition: model.h:64
Math::AABB _boundingBox
Definition: model.h:85
Definition: model.h:48
Definition: console.h:27
Definition: model.h:39
Definition: model.h:55
Definition: archiveloader.h:46