1 /* atlantis --- Shows moving 3D sea animals */
3 #if !defined( lint ) && !defined( SABER )
4 static const char sccsid[] = "@(#)whale.c 1.1 98/05/13 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.
79 # include "xlockmoreI.h" /* from the xscreensaver distribution */
80 #else /* !STANDALONE */
81 # include "xlock.h" /* from the xlockmore distribution */
82 #endif /* !STANDALONE */
90 FishTransform(fishRec * fish)
93 glTranslatef(fish->y, fish->z, -fish->x);
94 glRotatef(-fish->psi, 0.0, 1.0, 0.0);
95 glRotatef(fish->theta, 1.0, 0.0, 0.0);
96 glRotatef(-fish->phi, 0.0, 0.0, 1.0);
100 WhalePilot(fishRec * fish)
107 fish->x += WHALESPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
108 fish->y += WHALESPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
109 fish->z += WHALESPEED * fish->v * sin(fish->theta / RAD);
113 SharkPilot(fishRec * fish)
116 float X, Y, Z, tpsi, ttheta, thetal;
122 X = fish->xt - fish->x;
123 Y = fish->yt - fish->y;
124 Z = fish->zt - fish->z;
126 thetal = fish->theta;
128 ttheta = RAD * atan(Z / (sqrt(X * X + Y * Y)));
130 if (ttheta > fish->theta + 0.25) {
132 } else if (ttheta < fish->theta - 0.25) {
135 if (fish->theta > 90.0) {
138 if (fish->theta < -90.0) {
141 fish->dtheta = fish->theta - thetal;
143 tpsi = RAD * atan2(Y, X);
147 if (fabs(tpsi - fish->psi) < 10.0) {
149 } else if (fabs(tpsi - fish->psi) < 45.0) {
150 if (fish->psi > tpsi) {
152 if (fish->psi < -180.0) {
155 } else if (fish->psi < tpsi) {
157 if (fish->psi > 180.0) {
162 if (NRAND(100) > 98) {
166 if (fish->psi > 180.0) {
169 if (fish->psi < -180.0) {
184 if ((fish->v > 1.0) && (!fish->spurt)) {
188 if (!(NRAND(400)) && (!fish->spurt)) {
197 if ((fish->v > 1.0) && (!fish->spurt)) {
202 fish->x += SHARKSPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
203 fish->y += SHARKSPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
204 fish->z += SHARKSPEED * fish->v * sin(fish->theta / RAD);
208 SharkMiss(atlantisstruct *ap, int i)
214 for (j = 0; j < NUM_SHARKS; j++) {
216 X = ap->sharks[j].x - ap->sharks[i].x;
217 Y = ap->sharks[j].y - ap->sharks[i].y;
218 Z = ap->sharks[j].z - ap->sharks[i].z;
220 R = sqrt(X * X + Y * Y + Z * Z);
223 thetal = ap->sharks[i].theta;
227 ap->sharks[i].theta -= avoid;
229 ap->sharks[i].theta += avoid;
232 ap->sharks[i].dtheta += (ap->sharks[i].theta - thetal);