ScummVM API documentation
spriter.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
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 * Spriter - 3D Renderer
22 */
23
24#ifndef TINSEL_SPRITER_H
25#define TINSEL_SPRITER_H
26
27#include "tinsel/dw.h"
28#include "common/rect.h"
29#include "common/stack.h"
30#include "common/str.h"
31
32#include "math/vector3d.h"
33#include "math/vector2d.h"
34#include "math/matrix4.h"
35
36#if defined(USE_TINYGL)
37#include "graphics/tinygl/tinygl.h"
38#endif
39
40namespace Tinsel {
41
43
44enum RenderProgramOp : uint16 {
45 MATRIX_DUPLICATE = 1,
46 MATRIX_REMOVE = 2,
47 UNUSED = 3,
48 TRANSFORM = 4,
49 TRANSLATE_X = 5,
50 TRANSLATE_Y = 6,
51 TRANSLATE_Z = 7,
52 TRANSLATE_XYZ = 8,
53 ROTATE_X = 9,
54 ROTATE_Y = 10,
55 ROTATE_Z = 11,
56 ROTATE_XYZ = 17,
57 STOP = 16,
58};
59
61 Common::String name;
62
63 uint meshNum;
64
65 uint translateTablesHunk;
66 uint translateTables;
67 uint translateNum;
68
69 uint rotateTablesHunk;
70 uint rotateTables;
71 uint rotateNum;
72
73 uint scaleTablesHunk;
74 uint scaleTables;
75 uint scaleNum;
76
77 uint maxFrame;
78};
79
80struct MeshInfo {
81 uint meshTablesHunk;
82 uint meshTables;
83
84 uint programHunk;
85 uint program;
86};
87
88struct Hunk {
90 Common::Array<uint> mappingIdx;
91 uint size;
92 uint flags;
93};
94
96
98
99struct Primitive {
100 uint indices[8];
101 uint color;
102 Math::Vector2d uv[4];
103 uint texture;
104};
105
106enum MeshPartType {
107 MESH_PART_TYPE_COLOR,
108 MESH_PART_TYPE_SOLID,
109 MESH_PART_TYPE_TEXTURE,
110};
111
112struct MeshPart {
113 MeshPartType type;
114 uint cull;
115 uint numVertices;
116 Common::Array<Primitive> primitives;
117};
118
119struct Mesh {
124};
125
126struct Meshes {
127 uint vertexCount;
128 uint normalCount;
129
130 Common::Array<Mesh> meshes;
131};
132
134
136 Vectors translations;
137 Vectors rotations;
138 Vectors scales;
139 Meshes meshes;
140};
141
142enum ModelFlags {
143 MODEL_HAS_TRANSLATION_TABLE = 1,
144 MODEL_HAS_SCALE_TABLE = 2,
145 MODEL_HAS_ROTATION_TABLE = 4
146};
147
148struct Model {
149 Hunks hunks;
150 Hunks hunksOverlay; // The game script can load additional data to supplement the main model. E.g. a special animation.
151 uint animationCount;
152 uint field_0xe;
153 uint field_0xf;
154 uint8* program;
155
156 // animation tables
157 AnimationData startTranslateTables;
158 AnimationData startRotateTables;
159 AnimationData startScaleTables;
160 AnimationData endTranslateTables;
161 AnimationData endRotateTables;
162 AnimationData endScaleTables;
163 int startFrame;
164 int endFrame;
165
166 uint flags;
167 uint field_0x32;
168 uint field_0x33;
169
170 ModelTables tables;
171
172 Math::Vector3d position;
173 Math::Vector3d rotation;
174 Math::Vector3d scale;
175
176 uint time; // interpolant
177};
178
179struct Viewport {
180 int ap;
181 float width;
182 float height;
183
184 Common::Rect rect;
185};
186
187struct View {
188 int centerX;
189 int centerY;
190
191 Common::Rect viewRect;
192 Common::Rect screenRect;
193
194 Viewport viewport;
195
196 Math::Vector3d position;
197 Math::Vector3d rotation;
198};
199
200class Spriter {
201private:
202 MatrixStack _modelMatrix;
203 MatrixStack* _currentMatrix;
204
206 AnimationInfo _animShadow;
207
208 MeshInfo _meshMain;
209 Common::Array<MeshInfo> _meshShadow;
210
211 View _view;
212
213 Common::Array<uint8> _palette;
214 Common::Array<uint8> _textureData;
215
216 bool _textureGenerated;
217#if defined(USE_TINYGL)
218 uint _texture[4];
219#endif
220
221 bool _modelIdle;
222
223 uint _animId;
224 uint _animSpeed;
225 uint _animDelay;
226 uint _animDelayMax;
227
228 uint _sequencesCount;
229
230 uint _direction;
231
232public:
233 Model _modelMain;
234 Model _modelShadow;
235
236public:
237 Spriter();
238 virtual ~Spriter();
239
240 void Init(int width, int height);
241 void SetCamera(int rotX, int rotY, int rotZ, int posX, int posY, int posZ, int cameraAp);
242 void TransformSceneXYZ(int x, int y, int z, int& xOut, int& yOut);
243 void Load(const Common::String& modelName, const Common::String& textureName);
244
245 void SetPalette(SCNHANDLE hPalette);
246
247 void SetSequence(uint animId, uint delay);
248 Common::Rect Draw(int direction, int x, int y, int z, int tDelta);
249
250private:
251 const Math::Matrix4& MatrixCurrent() const;
252
253 void MatrixReset();
254
255 void MatrixPop();
256 void MatrixPush();
257 void MatrixTranslate(float x, float y, float z);
258 void MatrixScale(float x, float y, float z);
259 void MatrixRotateX(float angle);
260 void MatrixRotateY(float angle);
261 void MatrixRotateZ(float angle);
262
263 void SetViewport(int ap);
264
265 // Loading of the model
266 void LoadH(const Common::String& modelName);
267 void LoadGBL(const Common::String& modelName);
268 void LoadRBH(const Common::String& modelName, Hunks& hunks);
269 void LoadVMC(const Common::String& textureName);
270
271 void UpdateTextures();
272
273 Meshes LoadMeshes(const Hunks &hunks, uint hunk, uint offset, int frame);
274 template<bool convert>
275 AnimationData LoadAnimationData(const Hunks &hunks, uint hunk, uint offset);
276 void InitModel(Model& model, MeshInfo& meshInfo, Common::Array<AnimationInfo>& animInfo, uint flags);
277
278 // Processing of the model
279 void RunRenderProgram(Model &model, bool preprocess);
280
281 void FindSimilarVertices(Mesh& mesh, Vectors& vertices, Common::Array<uint16>& sameVertices) const;
282 void MergeVertices(Mesh& mesh, Common::Array<uint16>& sameVertices);
283
284 void TransformMesh(Mesh& mesh, Vectors& vertices);
285 void CalculateNormals(Mesh& mesh, Vectors& vertices, Vectors &normals);
286
287 // Rendering
288 void RenderModel(Model& model);
289 void RenderMesh(Mesh& mesh, Vectors& vertices, Vectors &normals);
290 void RenderMeshPartColor(MeshPart& part, Vectors& vertices, Vectors &normals);
291 void RenderMeshPartTexture(MeshPart& part, Vectors& vertices, Vectors &normals);
292
293 // Animation
294 bool SetStartFrame(Model &model, const AnimationInfo &anim, int frame);
295 bool SetEndFrame(Model &model, const AnimationInfo &anim, int frame);
296};
297
298} // End of namespace Tinsel
299
300#endif // TINSEL_SPRITER_H
Definition: str.h:59
Definition: spriter.h:200
Definition: actors.h:36
uint32 SCNHANDLE
Definition: dw.h:31
Definition: rect.h:536
Definition: spriter.h:60
Definition: spriter.h:88
Definition: spriter.h:119
Definition: spriter.h:80
Definition: spriter.h:112
Definition: spriter.h:126
Definition: spriter.h:148
Definition: spriter.h:135
Definition: spriter.h:99
Definition: spriter.h:187
Definition: spriter.h:179