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