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 PointXZ {
329  float x = 0.0f, z = 0.0f;
330  static PointXZ readFromStream(Common::SeekableReadStream &stream) {
331  PointXZ result;
332  result.x = stream.readFloatLE();
333  result.z = stream.readFloatLE();
334  return result;
335  }
336 };
337 
338 // Struct for returning from "partial" functions mathematically
339 struct PointResult {
340  PointXZ result;
341  bool isValid = false;
342 };
343 
344 struct t3dPAN {
345  PointXZ a, b; // point A / B position
346  PointXZ backA, backB; // back to point A / B
347  uint16 near1 = 0; // panel near to A
348  uint16 near2 = 0; // panel near to B
349 };
350 
351 struct t3dPATHNODE {
352  PointXZ pos; // path node position
353  float dist = 0.0f; // distance from start
354  short oldp = 0; // last panel hit
355  short curp = 0; // cur panel hit
356 };
357 
358 struct t3dSTEPS {
359  t3dV3F Pos; // position
360  t3dF32 Angle = 0.0f; // angle
361  int16 curp = 0; // cur panel
362  int16 Act = 0, Frame = 0; // cur action and frame
363 
364  void reset() {
365  Pos = t3dV3F();
366  Angle = 0.0f;
367  curp = 0;
368  Act = 0;
369  Frame = 0;
370  }
371 };
372 
373 struct t3dWALK {
374  PointXZ Look; // Point on the bounds
375  PointXZ Cur; // Point perpendicular
376  t3dPAN *Panel = nullptr; // pointer to cur panel struct
377  t3dPATHNODE PathNode[T3D_MAX_PATHNODES] = {}; // path nodes list
378  t3dSTEPS WalkSteps[T3D_MAX_WALKSTEPS] = {}; // walk steps list
379  int32 CurrentStep = 0; // current step
380  int32 PanelNum = 0; // num panels
381  int32 NumPathNodes = 0; // num path nodes
382  int32 NumSteps = 0; // num steps
383  int16 CurPanel = 0, OldPanel = 0; // current panel
384  int16 CurAction = 0, CurFrame = 0; // cur action and frame
385  int32 Check = 0; // intersection check
386 };
387 
388 struct t3dMESH;
389 
390 struct t3dCHARACTER {
391  char Name[T3D_NAMELEN] = {}; // character name
392  t3dBODY *Body = nullptr; // caracter body
393  t3dBODY *Shadow = nullptr; // shadow struct
394  t3dMESH *Mesh = nullptr; // shortcut to first mesh
395  t3dBODY *CurRoom = nullptr; // character cur room
396  t3dV3F Pos; // char pos (world)
397  t3dV3F Dir; // char dir
398  t3dWALK Walk; // walk struct
399  uint8 Flags = 0; // char flags
400  SHADOWBOX *ShadowBox[T3D_MAX_SHADOWBOX_PER_CHAR] = {}; // active shadows
401  t3dF32 Radius = 0.0f, Height = 0.0f; // char dimension (for shadow)
402  int32 CurExpressionSet = 0; // current expression face set
403 };
404 
406  uint8 BlendPercent = 0;
407  int32 NumPathNodes = 0;
408  int32 CurrentStep = 0;
409  int32 NumSteps = 0;
410  int16 CurAction = 0, CurFrame = 0;
411  int16 mCurFrame = 0;
412  t3dF32 posy = 0.0f, mposy = 0.0f;
413  t3dM3X3F Matrix;
414 };
415 
416 } // End of namespace Watchmaker
417 
418 #endif // WATCHMAKER_T3D_H
Definition: t3d.h:295
Definition: t3d.h:390
Definition: t3d.h:128
Definition: types3d.h:38
Definition: 2d_stuff.h:30
Definition: t3d.h:339
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
Definition: t3d.h:286
Definition: t3d.h:344
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:405
Definition: work_dirs.h:30
void push_back(const T &element)
Definition: array.h:180
Definition: t3d.h:203
Definition: t3d.h:351
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
FORCEINLINE float readFloatLE()
Definition: stream.h:615
Definition: t3d.h:320
Definition: t3d.h:328
FORCEINLINE int16 readSint16LE()
Definition: stream.h:543
Definition: t3d.h:373
Definition: t3d.h:181
Definition: t3d.h:150
Definition: game.h:56
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:358
Definition: types3d.h:31