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