ScummVM API documentation
t3d.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 WATCHMAKER_T3D_H
23 #define WATCHMAKER_T3D_H
24 
25 #include "common/array.h"
26 #include "common/stream.h"
27 #include "watchmaker/render.h"
28 #include "watchmaker/types.h"
29 #include "watchmaker/3d/types3d.h"
30 
31 namespace Watchmaker {
32 
33 //************************************************************************************************************************
34 // defines
35 //************************************************************************************************************************
36 
37 #define T3D_PI 3.14159265358979323846f
38 #define T3D_2PI (3.14159265358979323846f*2.0f)
39 #define DEGREE_TO_RADIANS(x) ((x)*T3D_PI/180.0f)
40 #define RADIANS_TO_DEGREE(x) ((x)*180.0f/T3D_PI)
41 
42 #define T3D_NAMELEN 32 // default name len
43 #define T3D_MAX_LEVELS 5 // max bounds level per room
44 #define T3D_MAX_PATHNODES 1000 // max path nodes per walk
45 #define T3D_MAX_WALKSTEPS 4000 // max walk steps per walk
46 #define T3D_MAX_BLOCK_MESHES 3 // max block meshes per room
47 #define T3D_MAX_CHARACTERS 26 // max characters
48 #define T3D_MAX_SHADOWBOX_PER_CHAR 10 // max shadow box per character
49 
50 // Normal Array Define; used in flag field
51 #define T3D_NORMAL_INVISIBLE (1<<0) // invisible
52 #define T3D_NORMAL_VISIBLE (1<<1) // visible
53 
54 //Matrices flags
55 #define T3D_MATRIX_IDENTITY (1<<0) // is identical
56 
57 //Faces flags - additional to T3D_MATERIAL_FLAGS
58 #define T3D_FACE_VISIBLE (1<<13) // is visiuble
59 #define T3D_FACE_CASTSHADOWS (1<<14) // cast shadows
60 #define T3D_FACE_RECEIVESHADOWS (1<<15) // receive shadows
61 
62 //Mesh flags
63 #define T3D_MESH_CASTSHADOWS (1<<0) // Mesh cast shadow
64 #define T3D_MESH_RECEIVESHADOWS (1<<1) // Mesh receive shadows
65 #define T3D_MESH_NOLIGHTMAP (1<<2) // Mesh without lightmap
66 #define T3D_MESH_VISIBLE (1<<3) // Mesh visible
67 #define T3D_MESH_NOBOUNDBOX (1<<4) // Disable BoundBox check
68 #define T3D_MESH_NOPORTALCHECK (1<<5) // Disable Portal check
69 #define T3D_MESH_HIDDEN (1<<6) // Mesh Hidden
70 #define T3D_MESH_DEFAULTANIM (1<<7) // if takes animartions from the default set
71 #define T3D_MESH_CHARACTER (1<<8) // set if mesh is part of a character
72 #define T3D_MESH_PORTAL (1<<9) // mesh is a portal
73 #define T3D_MESH_MIRROR (1<<10) // mesh is a mirror
74 #define T3D_MESH_INVISIBLEFROMSECT (1<<11) // mesh is VISIBLE form the current sector
75 #define T3D_MESH_RAYBAN (1<<12) // mesh reject ray detection
76 #define T3D_MESH_ABS_ANIM (1<<13) // se animazione e' assoluta o relativa
77 #define T3D_MESH_LAST_DEFAULTANIM (1<<14) // if last frame was DEFAULTANIM
78 #define T3D_MESH_RECEIVERIPPLES (1<<15) // Mesh accepts ripples on it's material texture
79 #define T3D_MESH_WAVESTEXTURE (1<<16) // Waves textures on all the material textures
80 #define T3D_MESH_POOLWATER (1<<17) // Mesh accepts swimming pool water fx
81 #define T3D_MESH_PREPROCESSPORTAL (1<<18) // Preprocess portal for mesh visibilities
82 #define T3D_MESH_CASTREALTIMESHADOWS (1<<19) // Mesh calc realtime shadows using shadows-volumes
83 #define T3D_MESH_UPDATEVB (1<<20) // needs to update materail VB
84 #define T3D_MESH_ONLYINMIRRORS (1<<21) // appears only in mirrors
85 #define T3D_MESH_VIEWONLYPORTAL (1<<22) // if it's a View Only portal
86 #define T3D_MESH_PORTALPROCESSED (1<<23) // if it was just processed by another portal
87 #define T3D_MESH_ALWAYSVISIBLE (1<<24) // if this mesh is always visible
88 #define T3D_MESH_SOLARVARIATION (1<<25) // if change when sun moves
89 
90 //Light flags
91 #define T3D_LIGHT_SPOTLIGHT (1<<0) // is a spot
92 #define T3D_LIGHT_LIGHTON (1<<1) // light is on
93 #define T3D_LIGHT_ATTENUATION (1<<2) // is attenuated
94 #define T3D_LIGHT_CASTSHADOWS (1<<3) // cast shadows
95 #define T3D_LIGHT_PULSE (1<<4) // is flicking
96 #define T3D_LIGHT_ALLLIGHTSOFF (1<<5) // turn off all the lights in the room
97 #define T3D_LIGHT_FLARE (1<<6) // is a flare
98 #define T3D_LIGHT_CANDLESMOKE (1<<7) // light from a moving candle
99 #define T3D_LIGHT_REALTIME (1<<8) // affects realtime objects
100 #define T3D_LIGHT_SUN (1<<9) // if it's the sunlight position
101 #define T3D_LIGHT_SOLARVARIATION (1<<10) // if change when sun moves
102 #define T3D_LIGHT_OFF_MORNING (1<<11) // disable during the morning
103 #define T3D_LIGHT_OFF_AFTERNOON (1<<12) // disable during the afternoon
104 #define T3D_LIGHT_OFF_EVENING (1<<13) // disable during the evening
105 #define T3D_LIGHT_OFF_NIGHT (1<<14) // disable during the night
106 
107 // Character flags
108 #define T3D_CHARACTER_HIDE (1<<0) // is hidden
109 #define T3D_CHARACTER_ENABLEDINMIRROR (1<<1) // is in first person but enabled in the mirror
110 #define T3D_CHARACTER_CASTREALTIMESHADOWS (1<<2) // cast real time shadows
111 #define T3D_CHARACTER_REALTIMELIGHTING (1<<3) // needs realtime lighting
112 #define T3D_CHARACTER_VOLUMETRICLIGHTING (1<<4) // needs realtime volumetric lighting
113 #define T3D_CHARACTER_BNDHIDE (1<<5) // don't use char BND
114 #define T3D_CHARACTER_DIARYDISABLE (1<<6) // diable diary
115 
116 struct t3dM3X3F {
117  t3dF32 M[9] = {}; // Matrix 3 x 3
118  uint8 Flags = 0; // flags: if identity
119  constexpr t3dM3X3F() = default;
120 };
121 
122 struct t3dBONE {
123  t3dM3X3F *Matrix = nullptr; // matrix list
124  t3dV3F *Trasl = nullptr; // traslation list
125  Common::Array<int32> ModVertices; // modified vertices list
126 };
127 
128 struct t3dBONEANIM {
129  t3dBONE *BoneTable = nullptr; // bones list
130  t3dF32 *Dist = nullptr; // distanca form start frame (for walk and default)
131  uint16 NumBones = 0; // num bones
132  uint16 NumFrames = 0; // num frames
133 
134  t3dBONEANIM() = default;
135  t3dBONEANIM(const t3dBONEANIM &other) = default;
136  t3dBONEANIM& operator=(const t3dBONEANIM &rhs) = default;
137  t3dBONEANIM(t3dBONEANIM &&old) :
138  BoneTable(old.BoneTable),
139  Dist(old.Dist),
140  NumBones(old.NumBones),
141  NumFrames(old.NumFrames) {
142 
143  old.BoneTable = nullptr;
144  old.Dist = nullptr;
145  old.NumBones = 0;
146  old.NumFrames = 0;
147  }
148 };
149 
150 struct t3dMODVERTS {
151  uint16 NumVert = 0; // vertex indices in mesh
152  uint16 NumBone = 0; // modified by bone number
154  NumVert = stream.readSint32LE();
155  NumBone = stream.readSint32LE();
156  }
157 };
158 
159 struct t3dMORPH {
160  struct t3dMORPHVERT {
161  uint32 _index = 0; // vertex indices in mesh
162  t3dV3F _v; // new vertex coords
164  _index = (uint32)stream.readSint16LE(); // Legge indice vertice
165  _v = t3dV3F(stream); // legge nuova posizione
166  }
167  };
168 
169  Common::Array<t3dMORPHVERT> _morphModVertices; // morph verteices list
171  int morphNumModVertices = stream.readSint16LE(); // Legge e alloca numero vertici che si muovono
172  _morphModVertices.reserve(morphNumModVertices);
173  if (morphNumModVertices) {
174  for (int j = 0; j < morphNumModVertices; j++) {
175  _morphModVertices.push_back(t3dMORPHVERT(stream));
176  }
177  }
178  }
179 };
180 
181 struct t3dVERTEX {
182  t3dV3F p; // Coordinate vertice in Obj-space 12
183  uint8 r = 0; // Preilluminazione R vertice 1
184  uint8 g = 0; // Preilluminazione G vertice 1
185  uint8 b = 0; // Preilluminazione B vertice 1 15
186 };
187 
189  uint8 PathIndex = 0; // path number in room
190  uint8 NumCamera = 0; // num destination camera
191  int8 Direction = 0; // path direction: source->dest or dest->source
192 public:
193  explicit t3dPathCamera(Common::SeekableReadStream &stream);
194 };
195 
197  t3dV3F TopLeft, BottomRight; // world coords of camera grid
198  uint16 Row = 0, Col = 0; // number of cells
199  t3dV3F CellDim; // cell dimensiom
200  Common::Array<uint8> Grid; // grid
201 };
202 
204  uint16 NumPoints() {
205  return PList.size(); // num points in path
206  }
207  Common::Array<t3dV3F> PList; // points list
208  uint32 CarrelloDist = 0; // if carrello: max distance from the target
209 public:
210  explicit t3dCAMERAPATH(Common::SeekableReadStream &stream);
211 };
212 
213 struct t3dCAMERA {
214  t3dV3F Source; // camera eye
215  t3dV3F Target; // camera target
216  t3dV3F MaxTarget; // original 3dsmax target
217  t3dV3F NormalizedDir; // cam direction
218  t3dF32 Fov; // cam field of view
219  t3dV2F Center; // cam center
220  t3dM3X3F Matrix; // cam view matrix
221  t3dF32 NearClipPlane, FarClipPlane; // camera planes
222  uint8 Index; // cam index 9in room
223  Common::Array<t3dPathCamera> CameraPaths;
224 
225  uint8 NumAvailablePaths() const {
226  return CameraPaths.size();
227  }
228 
229 public:
230  t3dCAMERA() {
231  reset();
232  }
233 
234  explicit t3dCAMERA(Common::SeekableReadStream &stream);
235 
236  void reset() {
237  Source = t3dV3F();
238  Target = t3dV3F();
239  MaxTarget = t3dV3F();
240  NormalizedDir = t3dV3F();
241  Fov = 0.0f;
242  Center = t3dV2F();
243  Matrix = t3dM3X3F();
244  NearClipPlane = 0.0f, FarClipPlane = 0.0f;
245  Index = 0;
246  CameraPaths.clear();
247  }
248 
249  void normalizedSight();
250 };
251 
252 struct t3dVolLights {
253  t3dF32 CellsSize = 0.0f; // cell cube dimension
254  uint32 xcells = 0; // number of cells for x dir
255  uint32 ycells = 0; // number of cells for y dir
256  uint32 zcells = 0; // number of cells for z dir
257  Common::Array<uint8> VolMap; // volumetric map
258 };
259 
260 struct t3dBODY;
261 
262 struct t3dParticle {
263  uint16 ParticleIndex;
264  uint16 Num;
265  t3dF32 Lung;
266  t3dF32 Size;
267  t3dF32 Seg1;
268  t3dF32 Seg2;
269  t3dF32 Dim1;
270  t3dF32 Dim2;
271  t3dF32 Speed;
272  t3dF32 Speed1;
273  t3dF32 Speed2;
274  t3dF32 Caos;
275  t3dF32 Caos1;
276  t3dF32 Caos2;
277  uint32 Delay;
278  uint8 OR1, Type;
279  t3dF32 R1, G1, B1;
280  t3dF32 R2, G2, B2;
281  t3dF32 R3, G3, B3;
282 public:
283  explicit t3dParticle(Common::SeekableReadStream &stream);
284 };
285 
286 struct t3dAnimLight {
287  Common::Array<gVertex *> VisVerts; // pointer to visible vertices from lights
288  uint16 NumVisVerts() const {
289  return VisVerts.size(); // num visible vertices from lights
290  }
291  //t3dU32 *SavedLightColor; // pointer to original vartex illumination
292  int8 LastRandomizer; // randomizer for flicker effects
293 };
294 
295 struct t3dLIGHT {
296  uint32 Type; // light type
297  t3dV3F Source; // source
298  t3dV3F Target; // target
299  t3dF32 Multiplier; // light multiplier
300  t3dF32 NearRange, FarRange; // attenuation ranges
301  t3dF32 HotSpot, FallOff; // spot ranges
302  t3dV3F Color; // orig color
303  uint8 Flicker; // flicker activated
304  uint8 FlickerDelay = 0; // flicker delay
305  int8 LightRandomizer = 0; // flicker randomizer
306  Common::SharedPtr<t3dParticle> Particle; // paticles attached
307  t3dF32 FlareSize = 0; // flare size
308  gMaterial Material[2]; // flare material
309  t3dAnimLight AnimLight; // animation attached
310  t3dV3F SolarColor[4]; // Ambient color value for solar movement
311  t3dV3F SolarPos[4]; // Position movements due to solar movement
312 public:
313  t3dLIGHT(WGame &game, t3dBODY *b, WorkDirs &workDirs, Common::SeekableReadStream &stream);
314 private:
315  void setupVisibleVerticesFromLight(t3dBODY *b);
316  void SetVisibleFromLight(gVertex *v);
317 };
318 typedef t3dLIGHT *LightPtr;
319 
320 struct t3dPLIGHT {
321  uint8 Num = 0; // index positional light in room
322  t3dV3F Pos; // position (world)
323  t3dV3F Dir; // destination (world)
324 public:
325  explicit t3dPLIGHT(Common::SeekableReadStream &stream);
326 };
327 
328 struct t3dPAN {
329  t3dF32 x1 = 0.0f, z1 = 0.0f; // point A position
330  t3dF32 x2 = 0.0f, z2 = 0.0f; // point B position
331  t3dF32 bx1 = 0.0f, bz1 = 0.0f; // back to point A
332  t3dF32 bx2 = 0.0f, bz2 = 0.0f; // back to point B
333  uint16 near1 = 0; // panel near to A
334  uint16 near2 = 0; // panel near to B
335 };
336 
337 struct t3dPATHNODE {
338  float x = 0.0f, z = 0.0f; // path node position
339  float dist = 0.0f; // distance from start
340  short oldp = 0; // last panel hit
341  short curp = 0; // cur panel hit
342 };
343 
344 struct t3dSTEPS {
345  t3dV3F Pos; // position
346  t3dF32 Angle = 0.0f; // angle
347  int16 curp = 0; // cur panel
348  int16 Act = 0, Frame = 0; // cur action and frame
349 
350  void reset() {
351  Pos = t3dV3F();
352  Angle = 0.0f;
353  curp = 0;
354  Act = 0;
355  Frame = 0;
356  }
357 };
358 
359 struct t3dWALK {
360  t3dF32 LookX = 0.0f, LookZ = 0.0f; // Point on the bounds
361  t3dF32 CurX = 0.0f, CurZ = 0.0f; // Point perpendicular
362  t3dPAN *Panel = nullptr; // pointer to cur panel struct
363  t3dPATHNODE PathNode[T3D_MAX_PATHNODES] = {}; // path nodes list
364  t3dSTEPS WalkSteps[T3D_MAX_WALKSTEPS] = {}; // walk steps list
365  int32 CurrentStep = 0; // current step
366  int32 PanelNum = 0; // num panels
367  int32 NumPathNodes = 0; // num path nodes
368  int32 NumSteps = 0; // num steps
369  int16 CurPanel = 0, OldPanel = 0; // current panel
370  int16 CurAction = 0, CurFrame = 0; // cur action and frame
371  int32 Check = 0; // intersection check
372 };
373 
374 struct t3dMESH;
375 
376 struct t3dCHARACTER {
377  char Name[T3D_NAMELEN] = {}; // character name
378  t3dBODY *Body = nullptr; // caracter body
379  t3dBODY *Shadow = nullptr; // shadow struct
380  t3dMESH *Mesh = nullptr; // shortcut to first mesh
381  t3dBODY *CurRoom = nullptr; // character cur room
382  t3dV3F Pos; // char pos (world)
383  t3dV3F Dir; // char dir
384  t3dWALK Walk; // walk struct
385  uint8 Flags = 0; // char flags
386  SHADOWBOX *ShadowBox[T3D_MAX_SHADOWBOX_PER_CHAR] = {}; // active shadows
387  t3dF32 Radius = 0.0f, Height = 0.0f; // char dimension (for shadow)
388  int32 CurExpressionSet = 0; // current expression face set
389 };
390 
392  uint8 BlendPercent = 0;
393  int32 NumPathNodes = 0;
394  int32 CurrentStep = 0;
395  int32 NumSteps = 0;
396  int16 CurAction = 0, CurFrame = 0;
397  int16 mCurFrame = 0;
398  t3dF32 posy = 0.0f, mposy = 0.0f;
399  t3dM3X3F Matrix;
400 };
401 
402 } // End of namespace Watchmaker
403 
404 #endif // WATCHMAKER_T3D_H
Definition: t3d.h:295
Definition: t3d.h:376
Definition: t3d.h:128
Definition: types3d.h:38
Definition: 2d_stuff.h:30
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
Definition: t3d.h:286
Definition: t3d.h:328
Definition: vertex.h:33
void clear()
Definition: array.h:320
Definition: t3d.h:262
Definition: t3d.h:196
Definition: stream.h:745
Type
Definition: log.h:33
Definition: t3d.h:391
Definition: work_dirs.h:30
void push_back(const T &element)
Definition: array.h:180
Definition: t3d.h:203
Definition: t3d.h:337
Definition: t3d.h:252
void reserve(size_type newCapacity)
Definition: array.h:396
Definition: t3d_body.h:32
Definition: render.h:100
Definition: t3d_mesh.h:30
size_type size() const
Definition: array.h:315
Definition: t3d.h:320
FORCEINLINE int16 readSint16LE()
Definition: stream.h:543
Definition: t3d.h:359
Definition: t3d.h:181
Definition: t3d.h:150
Definition: game.h:55
Definition: t3d.h:159
Definition: material.h:39
Definition: t3d.h:213
Definition: ptr.h:159
Definition: t3d.h:122
Definition: t3d.h:188
Definition: t3d.h:116
Definition: t3d.h:344
Definition: types3d.h:31