ScummVM API documentation
point3.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 ULTIMA8_MISC_POINT3_H
23 #define ULTIMA8_MISC_POINT3_H
24 
25 namespace Ultima {
26 namespace Ultima8 {
27 
28 struct Point3 {
29  int32 x, y, z;
30 
31  Point3() : x(0), y(0), z(0) {}
32  Point3(int32 nx, int32 ny, int32 nz) : x(nx), y(ny), z(nz) {}
33 
34  bool operator==(const Point3 &rhs) const { return equals(rhs); }
35  bool operator!=(const Point3 &rhs) const { return !equals(rhs); }
36 
37  bool equals(const Point3 &p) const {
38  return (x == p.x && y == p.y && z == p.z);
39  }
40 
41  Point3 operator+(const Point3 &delta) const { return Point3(x + delta.x, y + delta.y, z + delta.z); }
42  Point3 operator-(const Point3 &delta) const { return Point3(x - delta.x, y - delta.y, z - delta.z); }
43 
44  void operator+=(const Point3 &delta) {
45  x += delta.x;
46  y += delta.y;
47  z += delta.z;
48  }
49 
50  void operator-=(const Point3 &delta) {
51  x -= delta.x;
52  y -= delta.y;
53  z -= delta.z;
54  }
55 
56  int maxDistXYZ(const Point3 &other) const {
57  int xdiff = abs(x - other.x);
58  int ydiff = abs(y - other.y);
59  int zdiff = abs(z - other.z);
60  return MAX(xdiff, MAX(ydiff, zdiff));
61  }
62 
63  uint32 sqrDist(const Point3 &other) const {
64  int xdiff = abs(x - other.x);
65  int ydiff = abs(y - other.y);
66  int zdiff = abs(z - other.z);
67  return uint32(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
68  }
69 
70  void set(int32 nx, int32 ny, int32 nz) {
71  x = nx;
72  y = ny;
73  z = nz;
74  }
75 
76  void translate(int32 dx, int32 dy, int32 dz) {
77  x += dx;
78  y += dy;
79  z += dz;
80  }
81 
82  bool loadData(Common::ReadStream *rs, uint32 version) {
83  x = rs->readSint32LE();
84  y = rs->readSint32LE();
85  z = rs->readSint32LE();
86  return true;
87  }
88 
89  void saveData(Common::WriteStream *ws) {
90  ws->writeSint32LE(x);
91  ws->writeSint32LE(y);
92  ws->writeSint32LE(z);
93  }
94 };
95 
96 } // End of namespace Ultima8
97 } // End of namespace Ultima
98 
99 #endif
Definition: stream.h:77
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
Definition: point3.h:28
Definition: detection.h:27
Definition: stream.h:385
T MAX(T a, T b)
Definition: util.h:62
FORCEINLINE void writeSint32LE(int32 value)
Definition: stream.h:200