annotate Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/atlantis/swim.c @ 4648:0350b634c044

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