ScummVM API documentation
space.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 STARTREK_SPACE_H
23#define STARTREK_SPACE_H
24
25#include "fixedint.h"
26
27namespace StarTrek {
28
29template<typename T>
30struct TPoint {
31 T x;
32 T y;
33 T z;
34
35 TPoint() : x(0), y(0), z(0) {}
36 TPoint(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
37
38 int32 getDiagonal() {
39 return (int32)sqrt((double)x * x + y * y + z * z);
40 }
41
42 TPoint<T> operator+(const TPoint<T> &p) const {
43 TPoint<T> p2;
44 p2.x = x + p.x;
45 p2.y = y + p.y;
46 p2.z = z + p.z;
47 return p2;
48 }
49 TPoint<T> operator-(const TPoint<T> &p) const {
50 TPoint<T> p2;
51 p2.x = x - p.x;
52 p2.y = y - p.y;
53 p2.z = z - p.z;
54 return p2;
55 }
56 void operator+=(const TPoint &p) {
57 x += p.x;
58 y += p.y;
59 z += p.z;
60 }
61 void operator-=(const TPoint &p) {
62 x -= p.x;
63 y -= p.y;
64 z -= p.z;
65 }
66 T &operator[](int i) {
67 if (i == 0)
68 return x;
69 else if (i == 1)
70 return y;
71 else if (i == 2)
72 return z;
73
74 // Unknown Out of Range
75 assert(false);
76 return x;
77 }
78 T operator[](int i) const {
79 if (i == 0)
80 return x;
81 else if (i == 1)
82 return y;
83 else if (i == 2)
84 return z;
85
86 // Unknown Out of Range
87 assert(false);
88 return x;
89 }
90};
91
92typedef TPoint<int32> Point3;
95
96
97template<typename T>
98struct TMatrix {
99private:
100 T m[3];
101
102public:
103 TMatrix() {
104 for (int i = 0; i < 3; i++)
105 for (int j = 0; j < 3; j++)
106 m[i][j] = 0;
107 }
108 T &operator[](int i) {
109 return m[i];
110 };
111 T operator[](int i) const {
112 return m[i];
113 };
114
115 TMatrix operator*(const TMatrix &m2) const {
116 TMatrix ret;
117 for (int i = 0; i < 3; i++) {
118 for (int j = 0; j < 3; j++) {
119 ret[i][j] = 0;
120 for (int a = 0; a < 3; a++)
121 ret[i][j] += m[i][a] * m2[a][j];
122 }
123 }
124 return ret;
125 }
126
127 void operator*=(const TMatrix &m2) {
128 *this = *this * m2;
129 }
130
131 TMatrix<T> invert() const {
132 TMatrix<T> ret;
133 for (int i = 0; i < 3; i++) {
134 for (int j = 0; j < 3; j++) {
135 ret[i][j] = m[j][i];
136 }
137 }
138 return ret;
139 }
140};
141
143
144struct Star {
145 bool active;
146 Point3 pos;
147};
148
149// Struct for objects in space.
150// TODO: what does this stand for? Maybe rename it.
151struct R3 {
152 Point3 pos; // 0x0
153 Matrix matrix; // 0xc
154 int16 field1e; // 0x1e
155 int16 field20; // 0x20
156 int16 field22; // 0x22
157 int16 field24; // 0x24
158 Point3_Short speed; // 0x26
159 int32 funcPtr1; // 0x2c
160 int32 funcPtr2; // 0x30
161 int16 field34; // 0x34
162 Point3 field36; // 0x36
163 Matrix matrix2; // 0x42
164 int32 field54; // 0x54 (used for sorting by draw priority?)
165 int16 field58; // 0x58
166 int16 field5a; // 0x5a
167 Bitmap *bitmap; // 0x68 (was: shpFile)
168 // 0x6a (was: bitmapOffset)
169 double field80; // 0x80
170 double field88; // 0x88
171 double field90; // 0x90
172 double field98; // 0x98
173};
174
175// Maximum number of stars visible at once in the starfields
176#define NUM_STARS 16
177
178// Maximum number of R3 objects in space at once
179#define NUM_SPACE_OBJECTS 0x30
180
181} // End of namespace StarTrek
182
183#endif
Definition: action.h:27
Definition: bitmap.h:31
Definition: space.h:151
Definition: space.h:144
Definition: space.h:98
Definition: space.h:30