ScummVM API documentation
tilevect.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 * Based on the original sources
22 * Faery Tale II -- The Halls of the Dead
23 * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24 */
25
26#ifndef SAGA2_TILEVECT_H
27#define SAGA2_TILEVECT_H
28
29namespace Saga2 {
30
31// This routine returns a random vector between two bounding vectors
32
33inline TilePoint randomVector(TilePoint minv, TilePoint maxv) {
34 return TilePoint(
35 RANDOM(minv.u, maxv.u),
36 RANDOM(minv.v, maxv.v),
37 RANDOM(minv.z, maxv.z));
38}
39
40// Routine to get an orthogonal vector in the uv plane to an existing vector
41
42inline TilePoint rightVector(TilePoint tp, bool which = 0) {
43 return TilePoint(
44 tp.v * (which ? 1 : -1),
45 tp.u * (which ? -1 : 1),
46 0);
47}
48
49// Routine to force the magnitude of a vector to a value
50
51inline void setMagnitude(TilePoint &tp, int32 newMag) {
52 if (tp.magnitude()) {
53 int32 nu = (tp.u * newMag) / tp.magnitude();
54 int32 nv = (tp.v * newMag) / tp.magnitude();
55 tp = TilePoint(nu, nv, tp.z);
56 } else {
57 tp = TilePoint(1, 1, 0);
58 }
59}
60
61// returns an arbitrary 'side' designation for a line and a point
62// the only determination that can be made from this value is that
63// any other points returning the same value for the same line will
64// be on the same 'side' of the line as the first
65// note that this is flat in uv-space (no z)
66
67
68inline bool sideOf(const TilePoint &p1, // point 1 used to define the line
69 const TilePoint &p2, // point 2 used to define the line
70 const TilePoint &pp) { // the point to get the 'side' of
71 int32 m;
72 if (p1.u - p2.u == 0)
73 return pp.u > p1.u;
74 m = (p1.v - p2.v) / (p1.u - p2.u);
75 return m * pp.u + p1.v > m * p1.u + pp.v;
76}
77
78// determines whether or not two points are on the same side of a
79// line
80
81
82inline bool sameSide(const TilePoint &p1, // point 1 used to define the line
83 const TilePoint &p2, // point 2 used to define the line
84 const TilePoint &pa, // the first point (to check)
85 const TilePoint &pb) { // the second point (to check against)
86 return sideOf(p1, p2, pa) == sideOf(p1, p2, pb);
87}
88
89// Get the lowest u,v, and z in either of 2,3 or 4 points
90
91inline TilePoint MinTilePoint(
92 const TilePoint &c1,
93 const TilePoint &c2) {
94 return TilePoint(MIN(c1.u, c2.u), MIN(c1.v, c2.v), MIN(c1.z, c2.z));
95}
96
97inline TilePoint MinTilePoint(const TilePoint &c1, const TilePoint &c2, const TilePoint &c3) {
98 return MinTilePoint(MinTilePoint(c1, c2), c3);
99}
100
101inline TilePoint MinTilePoint(const TilePoint &c1, const TilePoint &c2,
102 const TilePoint &c3, const TilePoint &c4) {
103 return MinTilePoint(MinTilePoint(c1, c2), MinTilePoint(c3, c4));
104}
105
106// Get the highest u,v, and z in either of 2,3 or 4 points
107
108inline TilePoint MaxTilePoint(
109 const TilePoint &c1,
110 const TilePoint &c2) {
111 return TilePoint(MAX(c1.u, c2.u), MAX(c1.v, c2.v), MAX(c1.z, c2.z));
112}
113
114inline TilePoint MaxTilePoint(const TilePoint &c1, const TilePoint &c2, const TilePoint &c3) {
115 return MaxTilePoint(MaxTilePoint(c1, c2), c3);
116}
117
118inline TilePoint MaxTilePoint(const TilePoint &c1, const TilePoint &c2,
119 const TilePoint &c3, const TilePoint &c4) {
120 return MaxTilePoint(MaxTilePoint(c1, c2), MaxTilePoint(c3, c4));
121}
122
123} // end of namespace Saga2
124
125#endif
T MIN(T a, T b)
Definition: util.h:63
T MAX(T a, T b)
Definition: util.h:66