ScummVM API documentation
types3d.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_TYPES3D_H
23 #define WATCHMAKER_TYPES3D_H
24 
25 #include "common/stream.h"
26 #include "math/vector3d.h"
27 #include "watchmaker/types.h"
28 
29 namespace Watchmaker {
30 
31 struct t3dV2F {
32  t3dF32 x = 0.0f, y = 0.0f; // 2d Vector
33 public:
34  constexpr t3dV2F() = default;
35  constexpr t3dV2F(float _x, float _y, float z) : x(_x), y(_y) {}
36 };
37 
38 struct t3dV3F {
39  t3dF32 x = 0.0f, y = 0.0f, z = 0.0f; // 3d vector
40 public:
41  constexpr t3dV3F() = default;
42  constexpr t3dV3F(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
43  t3dV3F(const Math::Vector3d &vector) {
44  x = vector.x();
45  y = vector.y();
46  z = vector.z();
47  }
48  t3dV3F(Common::SeekableReadStream &stream) {
49  x = stream.readFloatLE(); // Legge Pos
50  y = stream.readFloatLE();
51  z = stream.readFloatLE();
52  }
53  static t3dV3F fromStreamAsBytes(Common::SeekableReadStream &stream) {
54  t3dF32 x = stream.readByte();
55  t3dF32 y = stream.readByte();
56  t3dF32 z = stream.readByte();
57  return t3dV3F(x, y, z);
58  }
59  t3dV3F operator+(const t3dV3F &rhs) const {
60  return t3dV3F(
61  x + rhs.x,
62  y + rhs.y,
63  z + rhs.z
64  );
65  }
66  t3dV3F operator-(const t3dV3F &rhs) const {
67  return t3dV3F(
68  x + rhs.x,
69  y + rhs.y,
70  z + rhs.z
71  );
72  }
73  t3dV3F operator-() const {
74  return t3dV3F(
75  -x,
76  -y,
77  -z
78  );
79  }
80  t3dV3F operator*(float scalar) const {
81  return t3dV3F(
82  x * scalar,
83  y * scalar,
84  z * scalar
85  );
86  }
87  t3dV3F &operator*=(float scalar) {
88  this->x *= scalar;
89  this->y *= scalar;
90  this->z *= scalar;
91  return *this;
92  }
93  bool operator==(const t3dV3F &rhs) const {
94  return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z;
95  }
96  bool operator!=(const t3dV3F &rhs) const {
97  return !(*this == rhs);
98  }
99 };
100 
101 struct t3dNORMAL {
102  t3dV3F n; //normal coords 12
103  t3dF32 tn = 0.0f; //normal coords in light space
104  t3dF32 dist = 0.0f; //dist from plane 4
105  t3dF32 tras_n = 0.0f; //transformed normal 4
106  uint8 flag = 0; //flags 1
107 public:
108  constexpr t3dNORMAL() = default;
110  n = t3dV3F(stream); // Direzione
111  dist = -stream.readFloatLE(); // Distanza-Dot
112  }
113 };
114 
116 typedef Common::Array<NormalPtr> NormalList; // TODO: Not necessarily the prettiest solution, but chosen to ensure that changes to copies are shared.
117 
118 } // End of namespace Watchmaker
119 
120 #endif // WATCHMAKER_TYPES3D_H
Definition: types3d.h:38
Definition: 2d_stuff.h:30
Definition: types3d.h:101
Definition: stream.h:745
byte readByte()
Definition: stream.h:434
FORCEINLINE float readFloatLE()
Definition: stream.h:615
Definition: types3d.h:31