1 | /** |
---|
2 | * (c) Copyright 1993, 1994, Silicon Graphics, Inc. |
---|
3 | * ALL RIGHTS RESERVED |
---|
4 | * Permission to use, copy, modify, and distribute this software for |
---|
5 | * any purpose and without fee is hereby granted, provided that the above |
---|
6 | * copyright notice appear in all copies and that both the copyright notice |
---|
7 | * and this permission notice appear in supporting documentation, and that |
---|
8 | * the name of Silicon Graphics, Inc. not be used in advertising |
---|
9 | * or publicity pertaining to distribution of the software without specific, |
---|
10 | * written prior permission. |
---|
11 | * |
---|
12 | * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" |
---|
13 | * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, |
---|
14 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR |
---|
15 | * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON |
---|
16 | * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, |
---|
17 | * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY |
---|
18 | * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, |
---|
19 | * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF |
---|
20 | * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN |
---|
21 | * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON |
---|
22 | * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE |
---|
23 | * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
24 | * |
---|
25 | * US Government Users Restricted Rights |
---|
26 | * Use, duplication, or disclosure by the Government is subject to |
---|
27 | * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph |
---|
28 | * (c)(1)(ii) of the Rights in Technical Data and Computer Software |
---|
29 | * clause at DFARS 252.227-7013 and/or in similar or successor |
---|
30 | * clauses in the FAR or the DOD or NASA FAR Supplement. |
---|
31 | * Unpublished-- rights reserved under the copyright laws of the |
---|
32 | * United States. Contractor/manufacturer is Silicon Graphics, |
---|
33 | * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. |
---|
34 | * |
---|
35 | * OpenGL(TM) is a trademark of Silicon Graphics, Inc. |
---|
36 | */ |
---|
37 | #include <math.h> |
---|
38 | #include <stdlib.h> |
---|
39 | #if defined(__APPLE__) |
---|
40 | #include <GLUT/glut.h> |
---|
41 | #else |
---|
42 | #include <GL/glut.h> |
---|
43 | #endif |
---|
44 | #include "atlantis.h" |
---|
45 | |
---|
46 | void |
---|
47 | FishTransform(fishRec * fish) |
---|
48 | { |
---|
49 | glTranslatef(fish->y, fish->z, -fish->x); |
---|
50 | glRotatef(-fish->psi, 0.0, 1.0, 0.0); |
---|
51 | glRotatef(fish->theta, 1.0, 0.0, 0.0); |
---|
52 | glRotatef(-fish->phi, 0.0, 0.0, 1.0); |
---|
53 | } |
---|
54 | |
---|
55 | void |
---|
56 | WhalePilot(fishRec * fish) |
---|
57 | { |
---|
58 | |
---|
59 | fish->phi = -20.0; |
---|
60 | fish->theta = 0.0; |
---|
61 | fish->psi -= 0.5; |
---|
62 | |
---|
63 | fish->x += WHALESPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD); |
---|
64 | fish->y += WHALESPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD); |
---|
65 | fish->z += WHALESPEED * fish->v * sin(fish->theta / RAD); |
---|
66 | } |
---|
67 | |
---|
68 | void |
---|
69 | SharkPilot(fishRec * fish) |
---|
70 | { |
---|
71 | static int sign = 1; |
---|
72 | float X, Y, Z, tpsi, ttheta, thetal; |
---|
73 | |
---|
74 | fish->xt = 60000.0; |
---|
75 | fish->yt = 0.0; |
---|
76 | fish->zt = 0.0; |
---|
77 | |
---|
78 | X = fish->xt - fish->x; |
---|
79 | Y = fish->yt - fish->y; |
---|
80 | Z = fish->zt - fish->z; |
---|
81 | |
---|
82 | thetal = fish->theta; |
---|
83 | |
---|
84 | ttheta = RAD * atan(Z / (sqrt(X * X + Y * Y))); |
---|
85 | |
---|
86 | if (ttheta > fish->theta + 0.25) { |
---|
87 | fish->theta += 0.5; |
---|
88 | } else if (ttheta < fish->theta - 0.25) { |
---|
89 | fish->theta -= 0.5; |
---|
90 | } |
---|
91 | if (fish->theta > 90.0) { |
---|
92 | fish->theta = 90.0; |
---|
93 | } |
---|
94 | if (fish->theta < -90.0) { |
---|
95 | fish->theta = -90.0; |
---|
96 | } |
---|
97 | fish->dtheta = fish->theta - thetal; |
---|
98 | |
---|
99 | tpsi = RAD * atan2(Y, X); |
---|
100 | |
---|
101 | fish->attack = 0; |
---|
102 | |
---|
103 | if (fabs(tpsi - fish->psi) < 10.0) { |
---|
104 | fish->attack = 1; |
---|
105 | } else if (fabs(tpsi - fish->psi) < 45.0) { |
---|
106 | if (fish->psi > tpsi) { |
---|
107 | fish->psi -= 0.5; |
---|
108 | if (fish->psi < -180.0) { |
---|
109 | fish->psi += 360.0; |
---|
110 | } |
---|
111 | } else if (fish->psi < tpsi) { |
---|
112 | fish->psi += 0.5; |
---|
113 | if (fish->psi > 180.0) { |
---|
114 | fish->psi -= 360.0; |
---|
115 | } |
---|
116 | } |
---|
117 | } else { |
---|
118 | if (rand() % 100 > 98) { |
---|
119 | sign = 1 - sign; |
---|
120 | } |
---|
121 | fish->psi += sign; |
---|
122 | if (fish->psi > 180.0) { |
---|
123 | fish->psi -= 360.0; |
---|
124 | } |
---|
125 | if (fish->psi < -180.0) { |
---|
126 | fish->psi += 360.0; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | if (fish->attack) { |
---|
131 | if (fish->v < 1.1) { |
---|
132 | fish->spurt = 1; |
---|
133 | } |
---|
134 | if (fish->spurt) { |
---|
135 | fish->v += 0.2; |
---|
136 | } |
---|
137 | if (fish->v > 5.0) { |
---|
138 | fish->spurt = 0; |
---|
139 | } |
---|
140 | if ((fish->v > 1.0) && (!fish->spurt)) { |
---|
141 | fish->v -= 0.2; |
---|
142 | } |
---|
143 | } else { |
---|
144 | if (!(rand() % 400) && (!fish->spurt)) { |
---|
145 | fish->spurt = 1; |
---|
146 | } |
---|
147 | if (fish->spurt) { |
---|
148 | fish->v += 0.05; |
---|
149 | } |
---|
150 | if (fish->v > 3.0) { |
---|
151 | fish->spurt = 0; |
---|
152 | } |
---|
153 | if ((fish->v > 1.0) && (!fish->spurt)) { |
---|
154 | fish->v -= 0.05; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | fish->x += SHARKSPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD); |
---|
159 | fish->y += SHARKSPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD); |
---|
160 | fish->z += SHARKSPEED * fish->v * sin(fish->theta / RAD); |
---|
161 | } |
---|
162 | |
---|
163 | void |
---|
164 | SharkMiss(int i) |
---|
165 | { |
---|
166 | int j; |
---|
167 | float avoid, thetal; |
---|
168 | float X, Y, Z, R; |
---|
169 | |
---|
170 | for (j = 0; j < NUM_SHARKS; j++) { |
---|
171 | if (j != i) { |
---|
172 | X = sharks[j].x - sharks[i].x; |
---|
173 | Y = sharks[j].y - sharks[i].y; |
---|
174 | Z = sharks[j].z - sharks[i].z; |
---|
175 | |
---|
176 | R = sqrt(X * X + Y * Y + Z * Z); |
---|
177 | |
---|
178 | avoid = 1.0; |
---|
179 | thetal = sharks[i].theta; |
---|
180 | |
---|
181 | if (R < SHARKSIZE) { |
---|
182 | if (Z > 0.0) { |
---|
183 | sharks[i].theta -= avoid; |
---|
184 | } else { |
---|
185 | sharks[i].theta += avoid; |
---|
186 | } |
---|
187 | } |
---|
188 | sharks[i].dtheta += (sharks[i].theta - thetal); |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|