home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Encyclopedia of Graphics File Formats Companion
/
GFF_CD.ISO
/
formats
/
ttddd
/
spec
/
t3d_doc
/
waterfal.lzh
/
WATER.C
next >
Wrap
C/C++ Source or Header
|
1992-08-18
|
7KB
|
214 lines
#include <stdio.h>
#include <exec/types.h>
#include <math.h>
#include <stdlib.h>
#define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
/* WATERFALL.C
by Steve Worley
June 1991
Makes a series of objects which when "played" sequentially in Imagine,
creates a waterfall-like cascade. This is very much a hack and is
unpolished and unsupported, but so many people bugged me to let them
play with the code, I am making this freely distributable.
Quick directions: This is about all you'll get: I do not want to "support" this
code and answer a lot of questions about it, so this is about all you'll get
for docs. :-) Sorry.
The idea is to generate a series of objects, like 200 or so. Each of these
objects is just a large grouped set of perfect spheres.
If these objects are each shown for one frame, and the objects differ only
by the positions of the individual spheres, the result will be an animated
bunch of spheres moving around. This program computes the motion of the spheres
through a physical simulation. Some of the statements are pretty hardwired,
like setting velocity = 9.82 (this is the acceleration of gravity in M/S) and
the size and color of the spheres. Messy coding? You bet, but I never expected
to release this. :-)
This program outputs a zillion small files numbered sequentially and ending
with the extension "ttddd." These are to be read in by Glenn Lewis' fine
TTDDD program which will convert them into Imagine objects. (I wrote a little
script that I used ADOS's "execute" on.
Then you need to load these into Imagine. Start a new project, make it 200
frames (or however long). Add a new actor by loading the first of the outputted
waterfall objects. In Action, change the actor bar for the object to start and
end on frame one. Use "Add" mode and add a new bar to the actor subrow from
frame 2 to frame 2, using the filename of the SECOND waterfall object.
Add frame 3, object three, frame 4, object 4, etc. This sounds amazingly
annoying to do, and that's true. :-) But it is pretty fast: I did 250 frames
in about 20 minutes.
Anyway, "save changes" then set up your camera and lights in Detail, and
render a preview... tah dah!
Enjoy. Please remember this is a hack and nothing polished. As for
support, well, you're on your own.
-Steve
*/
main(argc,argv)
int argc;
char **argv;
{
double x[100],y[100],z[100],vx[100],vy[100];
double vz[100],cx,cy,cr,crs,sx,sy,sz,sr,srs,py,temp,px,pz,cz,dx,dy,dz;
int t, num,frame;
double time, dt,framespersec;
int NUMATOMS;
FILE *outfile;
char tempstring[50];
char outfilename[50];
/* Setup */
NUMATOMS=550;
framespersec=30.;
num=0;
frame=0;
dt=.001;
for (t=0;t<NUMATOMS;t++)
{
x[t]=0;
y[t]=0;
z[t]=0;
vx[t]=0;
vy[t]=0;
vz[t]=0;
}
/*prime!*/
time=0.0000000001;
while (time<5.0)
{
if (num<NUMATOMS && time >= num*0.1 ) /*release rate*/
{
x[num]=(rand()%4000)/2000-2.0;
y[num]=(rand()%4000)/2000.;
z[num]=10.5+(rand()%1000)/2000.;
vz[num]=-.5+(rand()%2000)/1000.;
vy[num]=-1.+(rand()%2000)/1000.;
vx[num]=1.5+(rand()%1000)/1000.;
num++;
}
for (t=0;t<num;t++)
{
/*
for (i=t+1;i<num;i++)
{
r=sqrt(
*/
/*too big?*/
if (vx[t]>100.) vx[t]= 50.+(rand()%5000)/100.;
if (vy[t]>100.) vy[t]= 50.+(rand()%5000)/100.;
if (vz[t]>100.) vz[t]= 50.+(rand()%5000)/100.;
if (vx[t]<-100.) vx[t]= -(50.+(rand()%5000)/100.);
if (vy[t]<-100.) vy[t]= -(50.+(rand()%5000)/100.);
if (vz[t]<-100.) vz[t]= -(50.+(rand()%5000)/100.);
/* Moveem!*/
vz[t]-=9.82*dt;
vz[t]+= (-.5+(rand()%1000)/1000.)*dt;
vx[t]+= (-.4+(rand()%1000)/1000.)*dt;
vy[t]+= (-.5+(rand()%1000)/1000.)*dt;
px=x[t]+dt*vx[t];
py=y[t]+dt*vy[t];
pz=z[t]+dt*vz[t];
/* boundries*/
if (px<5.)
{
if (pz<10.)
{
vz[t]= fabs(.90*vz[t]);
if (vz[t]>1.0) {vx[t]*=.98; vy[t]*=.98;}
}
}
else if (pz<0.)
{
vz[t]= fabs(.90*vz[t]);
if (vz[t]>1.0) {vx[t]*=.98; vy[t]*=.98;}
}
z[t]+=dt*vz[t];
x[t]+=dt*vx[t];
y[t]+=dt*vy[t];
if (fabs(vz[t])>10.) vz[t]=vz[t]-.2*vz[t]*dt;
} /* Loop on all particles*/
time+=dt;
if (framespersec*time>frame)
{
temp=sqrt(3.)/7.;
frame++;
strcpy(outfilename,"ram:fall");
stci_d(tempstring,frame);
if (frame<100) strcat(outfilename,"0");
if (frame<10) strcat(outfilename,"0");
strcat(outfilename,tempstring);
strcat(outfilename,".ttddd");
outfile=fopen(outfilename,"wb");
fprintf(outfile,"OBJ Begin\nDESC Begin\nNAME \"WATERFALL\"\n");
fprintf(outfile,"SHAP Shape = 2\nSHAP Lamp = 2\n END DESC\n\n");
for (t=0;t<num;t++)
{
fprintf(outfile,"DESC Begin\nNAME \"Sphere\"\nSHAP Shape = 0\n");
fprintf(outfile,"POSI X=%0.2f Y=%0.2f Z=%0.2f\n",x[t],y[t],z[t]-1.0);
fprintf(outfile,"SIZE X=.1 Y=.1 Z=.1\n COLR R=50 G=130 B=253\n");
fprintf(outfile,"End DESC\n TOBJ\n");
}
fprintf(outfile,"\nTOBJ\nEnd Obj\n");
/* fprintf(outfile,"SHAP Shap 2\nSHAP Lamp 0\n\n");
fprintf(outfile,"PNTS PCount %d\n",num*4);
fprintf(outfile,"EDGE ECount %d\n",num*6);
fprintf(outfile,"FACE TCount %d\n",num*4);
for (t
{
fprintf(outfile,"PNTS Point %d %f %f %f\n",t*4,x[t]-.12,y[t]-temp,z[t]);
fprintf(outfile,"PNTS Point %d %f %f %f\n",t*4+1,x[t]+.12,y[t]-temp,z[t]);
fprintf(outfile,"PNTS Point %d %f %f %f\n",t*4+2,x[t],y[t]+temp,z[t]);
fprintf(outfile,"PNTS Point %d %f %f %f\n",t*4+3,x[t],y[t],z[t]+.5);
fprintf(outfile,"EDGE Edge %d %d %d\n",t*6, t*4, t*4+1);
fprintf(outfile,"EDGE Edge %d %d %d\n",t*6+1,t*4+1,t*4+2);
fprintf(outfile,"EDGE Edge %d %d %d\n",t*6+2,t*4+2,t*4);
fprintf(outfile,"EDGE Edge %d %d %d\n",t*6+3,t*4, t*4+3);
fprintf(outfile,"EDGE Edge %d %d %d\n",t*6+4,t*4+1,t*4+3);
fprintf(outfile,"EDGE Edge %d %d %d\n",t*6+5,t*4+2,t*4+3);
fprintf(outfile,"FACE Connect %d %d %d %d\n",t*4, t*6, t*6+1,t*6+2);
fprintf(outfile,"FACE Connect %d %d %d %d\n",t*4+1,t*6, t*6+3,t*6+4);
fprintf(outfile,"FACE Connect %d %d %d %d\n",t*4+2,t*6+1,t*6+4,t*6+5);
fprintf(outfile,"FACE Connect %d %d %d %d\n",t*4+3,t*6+2,t*6+5,t*6+3);
}
fprintf(outfile,"\n\nEnd DESC\nTOBJ\nEnd Obj\n");
*/
fclose(outfile);
printf("t= %0.2lf x=%0.2lf y=%0.2lf z=%0.2lf vx=%0.2lf vy=%0.2lf vz=%lf\n",
time,x[0],y[0],z[0],vx[0],vy[0],vz[0]);
}
}
}