Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Scene3D.hpp
1167 views
1
#ifndef SCENE3D_H
2
#define SCENE3D_H
3
4
namespace RSDK
5
{
6
7
#define RSDK_SIGNATURE_MDL (0x4C444D) // "MDL"
8
9
#define SCENE3D_COUNT (0x20)
10
#define MODEL_COUNT (0x100)
11
#define SCENE3D_VERT_COUNT (0x4000)
12
13
enum Scene3DDrawTypes {
14
S3D_WIREFRAME,
15
S3D_SOLIDCOLOR,
16
17
S3D_UNUSED_1,
18
S3D_UNUSED_2,
19
20
S3D_WIREFRAME_SHADED,
21
S3D_SOLIDCOLOR_SHADED,
22
23
S3D_SOLIDCOLOR_SHADED_BLENDED,
24
25
S3D_WIREFRAME_SCREEN,
26
S3D_SOLIDCOLOR_SCREEN,
27
28
S3D_WIREFRAME_SHADED_SCREEN,
29
S3D_SOLIDCOLOR_SHADED_SCREEN,
30
31
S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN,
32
};
33
34
struct ScanEdge {
35
int32 start;
36
int32 end;
37
38
int32 startR;
39
int32 endR;
40
int32 startG;
41
int32 endG;
42
int32 startB;
43
int32 endB;
44
};
45
46
struct Matrix {
47
int32 values[4][4];
48
};
49
50
struct ModelVertex {
51
int32 x;
52
int32 y;
53
int32 z;
54
55
int32 nx;
56
int32 ny;
57
int32 nz;
58
};
59
60
struct TexCoord {
61
float x;
62
float y;
63
};
64
65
struct Model {
66
RETRO_HASH_MD5(hash);
67
ModelVertex *vertices;
68
TexCoord *texCoords;
69
Color *colors;
70
uint16 *indices;
71
uint16 vertCount;
72
uint16 indexCount;
73
uint16 frameCount;
74
uint8 flags;
75
uint8 faceVertCount;
76
uint8 scope;
77
};
78
79
struct Scene3DVertex {
80
int32 x;
81
int32 y;
82
int32 z;
83
84
int32 nx;
85
int32 ny;
86
int32 nz;
87
88
int32 tx;
89
int32 ty;
90
91
uint32 color;
92
};
93
94
struct Scene3DFace {
95
int32 depth;
96
int32 index;
97
};
98
99
struct Scene3D {
100
RETRO_HASH_MD5(hash);
101
Scene3DVertex *vertices;
102
Scene3DVertex *normals;
103
Scene3DFace *faceBuffer;
104
uint8 *faceVertCounts;
105
106
int32 projectionX;
107
int32 projectionY;
108
109
int32 diffuseX;
110
int32 diffuseY;
111
int32 diffuseZ;
112
113
int32 diffuseIntensityX;
114
int32 diffuseIntensityY;
115
int32 diffuseIntensityZ;
116
117
int32 specularIntensityX;
118
int32 specularIntensityY;
119
int32 specularIntensityZ;
120
121
uint16 vertLimit;
122
uint16 vertexCount;
123
uint16 faceCount;
124
uint8 drawMode;
125
uint8 scope;
126
};
127
128
extern Model modelList[MODEL_COUNT];
129
extern Scene3D scene3DList[SCENE3D_COUNT];
130
131
extern ScanEdge scanEdgeBuffer[SCREEN_YSIZE * 2];
132
133
void ProcessScanEdge(int32 x1, int32 y1, int32 x2, int32 y2);
134
void ProcessScanEdgeClr(uint32 c1, uint32 c2, int32 x1, int32 y1, int32 x2, int32 y2);
135
136
void SetIdentityMatrix(Matrix *matrix);
137
void MatrixMultiply(Matrix *dest, Matrix *matrixA, Matrix *matrixB);
138
void MatrixTranslateXYZ(Matrix *Matrix, int32 x, int32 y, int32 z, bool32 setIdentity);
139
void MatrixScaleXYZ(Matrix *matrix, int32 scaleX, int32 scaleY, int32 scaleZ);
140
void MatrixRotateX(Matrix *matrix, int16 angle);
141
void MatrixRotateY(Matrix *matrix, int16 angle);
142
void MatrixRotateZ(Matrix *matrix, int16 angle);
143
void MatrixRotateXYZ(Matrix *matrix, int16 rotationX, int16 rotationY, int16 rotationZ);
144
void MatrixInverse(Matrix *dest, Matrix *matrix);
145
inline void MatrixCopy(Matrix *matDst, Matrix *matSrc) { memcpy(matDst, matSrc, sizeof(Matrix)); }
146
147
uint16 LoadMesh(const char *filepath, uint8 scope);
148
uint16 Create3DScene(const char *name, uint16 faceCnt, uint8 scope);
149
inline void Prepare3DScene(uint16 sceneID)
150
{
151
if (sceneID < SCENE3D_COUNT) {
152
Scene3D *scn = &scene3DList[sceneID];
153
154
scn->vertexCount = 0;
155
scn->faceCount = 0;
156
157
memset(scn->vertices, 0, sizeof(Scene3DVertex) * scn->vertLimit);
158
memset(scn->normals, 0, sizeof(Scene3DVertex) * scn->vertLimit);
159
memset(scn->faceVertCounts, 0, sizeof(uint8) * scn->vertLimit);
160
memset(scn->faceBuffer, 0, sizeof(Scene3DFace) * scn->vertLimit);
161
}
162
}
163
164
inline void SetMeshAnimation(uint16 model, Animator *animator, int16 speed, uint8 loopIndex, bool32 forceApply, int16 frameID)
165
{
166
if (model >= MODEL_COUNT) {
167
if (animator)
168
animator->frames = NULL;
169
170
return;
171
}
172
173
if (!animator)
174
return;
175
176
if (animator->animationID == model && !forceApply)
177
return;
178
179
animator->frames = (SpriteFrame *)1;
180
animator->timer = 0;
181
animator->frameID = frameID;
182
animator->frameCount = modelList[model].frameCount;
183
animator->speed = speed;
184
animator->prevAnimationID = animator->animationID;
185
animator->frameDuration = 0x100;
186
animator->loopIndex = loopIndex;
187
animator->animationID = model;
188
}
189
inline void SetDiffuseColor(uint16 sceneID, uint8 x, uint8 y, uint8 z)
190
{
191
if (sceneID < SCENE3D_COUNT) {
192
Scene3D *scn = &scene3DList[sceneID];
193
scn->diffuseX = x;
194
scn->diffuseY = y;
195
scn->diffuseZ = z;
196
}
197
}
198
inline void SetDiffuseIntensity(uint16 sceneID, uint8 x, uint8 y, uint8 z)
199
{
200
if (sceneID < SCENE3D_COUNT) {
201
Scene3D *scn = &scene3DList[sceneID];
202
scn->diffuseIntensityX = x;
203
scn->diffuseIntensityY = y;
204
scn->diffuseIntensityZ = z;
205
}
206
}
207
inline void SetSpecularIntensity(uint16 sceneID, uint8 x, uint8 y, uint8 z)
208
{
209
if (sceneID < SCENE3D_COUNT) {
210
Scene3D *scn = &scene3DList[sceneID];
211
scn->specularIntensityX = x;
212
scn->specularIntensityY = y;
213
scn->specularIntensityZ = z;
214
}
215
}
216
void AddModelToScene(uint16 modelFrames, uint16 sceneIndex, uint8 drawMode, Matrix *matWorld, Matrix *matView, color color);
217
void AddMeshFrameToScene(uint16 modelFrames, uint16 sceneIndex, Animator *animator, uint8 drawMode, Matrix *matWorld, Matrix *matView, color color);
218
void Sort3DDrawList(Scene3D *scn, int32 first, int32 last);
219
void Draw3DScene(uint16 sceneID);
220
221
inline void Clear3DScenes()
222
{
223
// Unload Models
224
for (int32 m = 0; m < MODEL_COUNT; ++m) {
225
if (modelList[m].scope != SCOPE_GLOBAL) {
226
MEM_ZERO(modelList[m]);
227
modelList[m].scope = SCOPE_NONE;
228
}
229
}
230
231
// Unload 3D Scenes
232
for (int32 s = 0; s < SCENE3D_COUNT; ++s) {
233
if (scene3DList[s].scope != SCOPE_GLOBAL) {
234
MEM_ZERO(scene3DList[s]);
235
scene3DList[s].scope = SCOPE_NONE;
236
}
237
}
238
}
239
240
#if RETRO_REV0U
241
#include "Legacy/Scene3DLegacy.hpp"
242
#endif
243
244
} // namespace RSDK
245
246
#endif
247
248