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