space.c
11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*====================================================================
* space.c
*
* Copyright 1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
#include <ultra64.h>
#include <ultralog.h>
#include "gfx.h"
#include "matrix.h"
#include "mvtview.h"
#include "enterprise_mvt.h"
/*
* Mercury orbit parameters
*/
static float mercury_planet_radius = 40;
static float mercury_orbit_radius = 600;
static float mercury_vertical_off = 90;
static float mercury_angle = -15;
/*
* Venus orbit parameters
*/
static float venus_planet_radius = 50;
static float venus_orbit_radius = 700;
static float venus_vertical_off = 0;
static float venus_angle = -10;
/*
* Earth orbit parameters
*/
static float earth_planet_radius = 50;
static float earth_orbit_radius = 850;
static float earth_vertical_off = 0;
static float earth_angle = 5;
/*
* Enterprise parameters
*/
static float enterprise_mercury_orbit_radius = 10;
static float enterprise_mercury_angle = 102.5;
static float enterprise_mercury_speed = -2.5;
static float enterprise_mercury_pos[3];
static float enterprise_mercury_dir[3] = {-1.75,10,-2.1};
static float enterprise_mercury_rotation;
static float enterprise_venus_orbit_radius = 20;
static float enterprise_venus_angle = 180;
static float enterprise_venus_speed = -5;
static float enterprise_venus_pos[3];
static float enterprise_venus_dir[3] = {-2.5,10,0};
static float enterprise_venus_rotation;
static float enterprise_earth_orbit_radius = 20;
static float enterprise_earth_angle = 0;
static float enterprise_earth_speed = 2.5;
static float enterprise_earth_pos[3];
static float enterprise_earth_dir[3] = {0.5,5,0};
static float enterprise_earth_rotation;
/*
* Misc. parameters
*/
static float sun_radius = 50;
static int mercury_loop = 0;
static int venus_loop = 0;
static int earth_loop = 0;
static float speed_factor = 1.0;
/*
* MVT parameters
*/
static int xluback = 1;
static int interpolate = 1;
static float tdelta = 0.0;
static float mvt_scale = 0.05;
/*****************************************************************************
Initialize all MVTs.
*****************************************************************************/
static void
spaceInit(void)
{
MVTinit_template(0, enterprise, ENTERPRISE);
/*
* Instance all enterprise ships in the galaxy
*/
MVTcreate_group(0,MVT_NO_INDEP_ROT);
MVTinstance_object(0,
0.0, 0.0, 0.0, 0.0, /* will get offset by dynamic mtx */
ENTERPRISE_ANGLE_OFFSET, /* most probably zero */
1, /* do translates */
xluback, /* xlu background? */
interpolate, /* interpolate between samples */
mvt_scale, /* mvt/geometry scale */
tdelta, /* transition delta for t->g */
ENTERPRISE_TRANSITION_DIST); /* transition distance */
MVTcreate_group(0,MVT_NO_INDEP_ROT);
MVTinstance_object(1,
0.0, 0.0, 0.0, 0.0, /* will get offset by dynamic mtx */
ENTERPRISE_ANGLE_OFFSET, /* most probably zero */
1, /* do translates */
xluback, /* xlu background? */
interpolate, /* interpolate between samples */
mvt_scale, /* mvt/geometry scale */
tdelta, /* transition delta for t->g */
ENTERPRISE_TRANSITION_DIST); /* transition distance */
MVTcreate_group(0,MVT_NO_INDEP_ROT);
MVTinstance_object(2,
0.0, 0.0, 0.0, 0.0, /* will get offset by dynamic mtx */
ENTERPRISE_ANGLE_OFFSET, /* most probably zero */
1, /* do translates */
xluback, /* xlu background? */
interpolate, /* interpolate between samples */
mvt_scale, /* mvt/geometry scale */
tdelta, /* transition delta for t->g */
ENTERPRISE_TRANSITION_DIST); /* transition distance */
}
/*****************************************************************************
*****************************************************************************/
static void
drawPlanet(Mtx *viewing, Mtx *viewing_planet, Mtx *mtx,
int axis, float init_angle,
float planet_radius, float orbit_radius, float angle, float voff,
float planet_pos[3], Gfx *mtx_dl, Gfx *gfx_dl)
{
Mtx scale,trans,rot,rot_in_place;
if (orbit_radius != 0.0) {
/* compute planet rotation/position */
guTranslate(&trans, 0, orbit_radius, voff);
guRotate(&rot, angle, 0, 0, 1);
if (axis == 0)
guRotate(&rot_in_place, init_angle, 1, 0, 0);
else if (axis == 1)
guRotate(&rot_in_place, init_angle, 0, 1, 0);
else if (axis == 2)
guRotate(&rot_in_place, init_angle, 0, 0, 1);
guScale(&scale, planet_radius/100.0,
planet_radius/100.0,
planet_radius/100.0);
multMtx(mtx,&scale,&rot_in_place);
multMtx(mtx,mtx,&trans);
multMtx(viewing_planet,&rot,viewing);
planet_pos[0] = planet_pos[1] = planet_pos[2] = 0;
multMtxPos(planet_pos,&trans,planet_pos);
multMtxPos(planet_pos,&rot, planet_pos);
} else {
planet_pos[0] = planet_pos[1] = planet_pos[2] = 0;
copyMtx(viewing_planet,viewing);
guScale(mtx, planet_radius/100.0,
planet_radius/100.0,
planet_radius/100.0);
}
/* set matrices and draw geometry */
if (mtx_dl) gSPDisplayList(glistp++, mtx_dl);
if (gfx_dl) gSPDisplayList(glistp++, gfx_dl);
}
/*****************************************************************************
*****************************************************************************/
static void
MVTorbitShip(int object_id, float planet_pos[3], float planet_radius,
float planet_angle, float ship_orbit_radius, float ship_angle,
float init_rotation, float ship_pos[3], float *rotation)
{
Mtx ship_mtx,rotate_in_orbit,trans_to_orbit,trans_to_planet;
guRotate(&rotate_in_orbit,ship_angle,0.0,0.0,1.0);
guTranslate(&trans_to_orbit,0.0,planet_radius+ship_orbit_radius,0.0);
guTranslate(&trans_to_planet,planet_pos[0],planet_pos[1],planet_pos[2]);
makeIdentMtx(&ship_mtx);
multMtx(&ship_mtx,&ship_mtx,&trans_to_orbit);
multMtx(&ship_mtx,&ship_mtx,&rotate_in_orbit);
multMtx(&ship_mtx,&ship_mtx,&trans_to_planet);
ship_pos[0] = ship_pos[1] = ship_pos[2] = 0.0;
multMtxPos(ship_pos, &ship_mtx, ship_pos);
*rotation = ship_angle + init_rotation;
if (*rotation > 180) *rotation = -1*(360 - *rotation);
if (*rotation < -180) *rotation = 1*(*rotation + 360);
MVTset_position(object_id, ship_pos, *rotation);
}
/*****************************************************************************
*****************************************************************************/
static void
MVTdirectShip(int object_id, float ship_pos[3], float dir[3], float rotation)
{
ship_pos[0] += speed_factor*dir[0];
ship_pos[1] += speed_factor*dir[1];
ship_pos[2] += speed_factor*dir[2];
MVTset_position(object_id, ship_pos, rotation);
}
/*****************************************************************************
*****************************************************************************/
void
spaceMain(Dynamic *dynamicp, float eyept[3])
{
static u8 firstcall = 1;
float sun_pos[3];
float mercury_pos[3];
float venus_pos[3];
float earth_pos[3];
/*
* First time initialization
*/
if (firstcall) {
spaceInit();
firstcall = 0;
}
drawPlanet(&dynamicp->viewing, &dynamicp->viewing_sun, &dynamicp->sun,
0, 0.0, sun_radius, 0.0, 0.0,
0.0, sun_pos, sun_matrix, sun_dl);
drawPlanet(&dynamicp->viewing,&dynamicp->viewing_mercury,&dynamicp->mercury,
0, 0.0, mercury_planet_radius,mercury_orbit_radius,mercury_angle,
mercury_vertical_off, mercury_pos, mercury_matrix, mercury_dl);
drawPlanet(&dynamicp->viewing, &dynamicp->viewing_venus,
&dynamicp->venus, 2, -110.0 /*80.0*/,
venus_planet_radius, venus_orbit_radius, venus_angle,
venus_vertical_off, venus_pos,
venus_matrix, craterplanet_dl);
drawPlanet(&dynamicp->viewing, &dynamicp->viewing_earth, &dynamicp->earth,
0, 30.0, earth_planet_radius, earth_orbit_radius, earth_angle,
earth_vertical_off, earth_pos,
earth_matrix, earth_dl);
if (enterprise_mercury_angle <= 100) {
MVTdirectShip(0, enterprise_mercury_pos, enterprise_mercury_dir,
enterprise_mercury_rotation);
if (enterprise_mercury_pos[1] > 1000)
enterprise_mercury_angle = 180;
else
enterprise_mercury_angle = 100;
} else
MVTorbitShip(0,
mercury_pos, mercury_planet_radius, mercury_angle,
enterprise_mercury_orbit_radius, enterprise_mercury_angle,
-90.0, enterprise_mercury_pos, &enterprise_mercury_rotation);
if (enterprise_venus_angle <= 115) {
MVTdirectShip(1, enterprise_venus_pos, enterprise_venus_dir,
enterprise_venus_rotation);
if (enterprise_venus_pos[1] > 1300)
enterprise_venus_angle = 180;
else
enterprise_venus_angle = 115;
} else
MVTorbitShip(1,
venus_pos, venus_planet_radius, venus_angle,
enterprise_venus_orbit_radius, enterprise_venus_angle,
-90.0, enterprise_venus_pos, &enterprise_venus_rotation);
if (enterprise_earth_angle >= 266) {
MVTdirectShip(2, enterprise_earth_pos, enterprise_earth_dir,
enterprise_earth_rotation);
if (enterprise_earth_pos[1] > 1300)
enterprise_earth_angle = 0;
else
enterprise_earth_angle = 266;
}
else
MVTorbitShip(2,
earth_pos, earth_planet_radius, earth_angle,
enterprise_earth_orbit_radius, enterprise_earth_angle,
90.0, enterprise_earth_pos, &enterprise_earth_rotation);
MVTdraw(dynamicp, eyept);
/* compute for next ship orbit positions */
enterprise_mercury_angle += speed_factor*enterprise_mercury_speed;
enterprise_venus_angle += speed_factor*enterprise_venus_speed;
enterprise_earth_angle += speed_factor*enterprise_earth_speed;
if (enterprise_mercury_angle > 360)
enterprise_mercury_angle -= 360;
if (enterprise_mercury_angle < 0)
enterprise_mercury_angle += 360;
if (enterprise_venus_angle > 360)
enterprise_venus_angle -= 360;
if (enterprise_venus_angle < 0)
enterprise_venus_angle += 360;
if (enterprise_earth_angle > 360)
enterprise_earth_angle -= 360;
if (enterprise_earth_angle < 0)
enterprise_earth_angle += 360;
}