home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
306.lha
/
Gravity-Well
/
GW-Main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1980-12-03
|
5KB
|
144 lines
/*
GW-Main.c
Root module for Gravity-Well
Gary Teachout
Copyright July 1989
lc -cs GW-Main To compile with Lattice 5.0
*/
#include "GW-Include.h"
void main()
{
startup() ;
for ( ; ; )
{
takestep( g.timestep ) ;
g.elapsedtime += g.timestep ;
updatedisplay() ;
interface() ;
}
}
void takestep( time )
double time ;
{
struct dv av , rv , tv , uv ;
double r , v ;
long i , j , flag , s , sn = 1 ;
for ( i = 0 ; i < 20 ; i ++ )
g.objects[ i ].oldpos = g.objects[ i ].position ;
for ( flag = 1 ; flag ; )
{
for ( flag = i = 0 ; ( i < 20 ) && ( ! flag ) ; i ++ )
{
if ( g.objects[ i ].flags && ( ! g.objects[ i ].collision ) )
{
for ( j = 0 ; ( j < 20 ) && ( ! flag ) ; j ++ )
{
if ( ( g.objects[ j ].flags )
&& ( ! g.objects[ j ].collision )
&& ( g.objects[ j ].mass )
&& ( i != j ) )
{
subdv( &g.objects[ j ].velocity ,
&g.objects[ i ].velocity ,
&rv ) ;
magdv( &rv , &v ) ;
subdv( &g.objects[ j ].position ,
&g.objects[ i ].position ,
&rv ) ;
magdv( &rv , &r ) ;
if ( ( r < ( v * time * g.magic ) ) && ( sn < 256 ) )
{
flag = 1 ;
time = time * 0.5 ;
sn = sn * 2 ;
}
}
}
}
}
}
for ( s = 0 ; s < sn ; s ++ )
{
for ( i = 0 ; i < 20 ; i ++ )
{
if ( g.objects[ i ].flags && ( ! g.objects[ i ].collision ) )
{
av = zerodv ;
for ( j = 0 ; j < 20 ; j ++ )
{
if ( ( g.objects[ j ].flags )
&& ( ! g.objects[ j ].collision )
&& ( g.objects[ j ].mass )
&& ( i != j ) )
{
subdv( &g.objects[ j ].position ,
&g.objects[ i ].position ,
&rv ) ;
magdv( &rv , &r ) ;
if ( r < ( g.objects[ i ].radius
+ g.objects[ j ].radius ) )
{
endtrail( i , j ) ;
g.objects[ i ].collision = 1 ;
v = g.objects[ i ].mass
/ ( g.objects[ i ].mass
+ g.objects[ j ].mass ) ;
scaledv( &rv , &v , &tv ) ;
subdv( &g.objects[ j ].position ,
&tv ,
&g.objects[ j ].position ) ;
g.objects[ j ].oldpos = g.objects[ j ].position ;
scaledv( &g.objects[ i ].velocity ,
&g.objects[ i ].mass ,
&tv ) ;
scaledv( &g.objects[ j ].velocity ,
&g.objects[ j ].mass ,
&uv ) ;
adddv( &tv , &uv , &g.objects[ j ].velocity ) ;
g.objects[ j ].mass += g.objects[ i ].mass ;
v = 1 / g.objects[ j ].mass ;
scaledv( &g.objects[ j ].velocity ,
&v ,
&g.objects[ j ].velocity ) ;
j = 30 ;
}
else
{
r = ( g.objects[ j ].mass * time ) / ( r * r * r ) ;
scaledv( &rv , &r , &tv ) ;
adddv( &av , &tv , &av ) ;
}
}
}
adddv( &g.objects[ i ].velocity ,
&av ,
&g.objects[ i ].velocity ) ;
}
}
for ( i = 0 ; i < 20 ; i ++ )
{
if ( g.objects[ i ].flags && ( ! g.objects[ i ].collision ) )
{
scaledv( &g.objects[ i ].velocity ,
&time ,
&tv ) ;
adddv( &g.objects[ i ].position ,
&tv ,
&g.objects[ i ].position ) ;
}
}
}
}