1 /* atlantis --- Shows moving 3D sea animals */
4 static const char sccsid[] = "@(#)swim.c 1.3 98/06/18 xlockmore";
7 /* Copyright (c) E. Lassauge, 1998. */
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and that
13 * both that copyright notice and this permission notice appear in
14 * supporting documentation.
16 * This file is provided AS IS with no warranties of any kind. The author
17 * shall have no liability with respect to the infringement of copyrights,
18 * trade secrets or any patents by this file or any part thereof. In no
19 * event will the author be liable for any lost revenue or profits or
20 * other special, indirect and consequential damages.
22 * The original code for this mode was written by Mark J. Kilgard
23 * as a demo for openGL programming.
25 * Porting it to xlock was possible by comparing the original Mesa's morph3d
26 * demo with it's ported version to xlock, so thanks for Marcelo F. Vianna
27 * (look at morph3d.c) for his indirect help.
29 * Thanks goes also to Brian Paul for making it possible and inexpensive
30 * to use OpenGL at home.
32 * My e-mail address is lassauge@users.sourceforge.net
34 * Eric Lassauge (May-13-1998)
39 * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
41 * Permission to use, copy, modify, and distribute this software for
42 * any purpose and without fee is hereby granted, provided that the above
43 * copyright notice appear in all copies and that both the copyright notice
44 * and this permission notice appear in supporting documentation, and that
45 * the name of Silicon Graphics, Inc. not be used in advertising
46 * or publicity pertaining to distribution of the software without specific,
47 * written prior permission.
49 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
50 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
51 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
52 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
53 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
54 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
55 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
56 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
57 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
58 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
59 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
60 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
62 * US Government Users Restricted Rights
63 * Use, duplication, or disclosure by the Government is subject to
64 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
65 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
66 * clause at DFARS 252.227-7013 and/or in similar or successor
67 * clauses in the FAR or the DOD or NASA FAR Supplement.
68 * Unpublished-- rights reserved under the copyright laws of the
69 * United States. Contractor/manufacturer is Silicon Graphics,
70 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
72 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
77 # include "xlockmoreI.h" /* from the xscreensaver distribution */
78 #else /* !STANDALONE */
79 # include "xlock.h" /* from the xlockmore distribution */
80 #endif /* !STANDALONE */
87 FishTransform(fishRec * fish)
90 glTranslatef(fish->y, fish->z, -fish->x);
91 glRotatef(-fish->psi, 0.0, 1.0, 0.0);
92 glRotatef(fish->theta, 1.0, 0.0, 0.0);
93 glRotatef(-fish->phi, 0.0, 0.0, 1.0);
97 WhalePilot(fishRec * fish, float whalespeed, Bool whaledir)
102 fish->psi += ((whaledir) ? -0.5 : 0.5);
104 fish->x += whalespeed * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
105 fish->y += whalespeed * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
106 fish->z += whalespeed * fish->v * sin(fish->theta / RAD);
110 SharkPilot(fishRec * fish, float sharkspeed)
112 float X, Y, Z, tpsi, ttheta, thetal;
118 X = fish->xt - fish->x;
119 Y = fish->yt - fish->y;
120 Z = fish->zt - fish->z;
122 thetal = fish->theta;
124 ttheta = RAD * atan(Z / (sqrt(X * X + Y * Y)));
126 if (ttheta > fish->theta + 0.25) {
128 } else if (ttheta < fish->theta - 0.25) {
131 if (fish->theta > 90.0) {
134 if (fish->theta < -90.0) {
137 fish->dtheta = fish->theta - thetal;
139 tpsi = RAD * atan2(Y, X);
143 if (fabs(tpsi - fish->psi) < 10.0) {
145 } else if (fabs(tpsi - fish->psi) < 45.0) {
146 if (fish->psi > tpsi) {
148 if (fish->psi < -180.0) {
151 } else if (fish->psi < tpsi) {
153 if (fish->psi > 180.0) {
158 if (NRAND(100) > 98) {
159 fish->sign = (fish->sign < 0 ? 1 : -1);
161 fish->psi += (fish->sign ? 1 : -1);
162 if (fish->psi > 180.0) {
165 if (fish->psi < -180.0) {
180 if ((fish->v > 1.0) && (!fish->spurt)) {
184 if (!(NRAND(400)) && (!fish->spurt)) {
193 if ((fish->v > 1.0) && (!fish->spurt)) {
198 fish->x += sharkspeed * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
199 fish->y += sharkspeed * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
200 fish->z += sharkspeed * fish->v * sin(fish->theta / RAD);
204 SharkMiss(atlantisstruct * ap, int i)
210 for (j = 0; j < ap->num_sharks; j++) {
212 X = ap->sharks[j].x - ap->sharks[i].x;
213 Y = ap->sharks[j].y - ap->sharks[i].y;
214 Z = ap->sharks[j].z - ap->sharks[i].z;
216 R = sqrt(X * X + Y * Y + Z * Z);
219 thetal = ap->sharks[i].theta;
221 if (R < ap->sharksize) {
223 ap->sharks[i].theta -= avoid;
225 ap->sharks[i].theta += avoid;
228 ap->sharks[i].dtheta += (ap->sharks[i].theta - thetal);