mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-02-28 06:30:18 +00:00
mode7: more work on starfield
This commit is contained in:
parent
f99a73a2b8
commit
96cd7ac131
@ -4,59 +4,146 @@
|
||||
|
||||
#include "gr-sim.h"
|
||||
|
||||
#define NUMSTARS 64
|
||||
#define NUMSTARS 16
|
||||
|
||||
struct fixed_type {
|
||||
char i;
|
||||
unsigned char f;
|
||||
};
|
||||
|
||||
|
||||
struct star_type {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
struct fixed_type x;
|
||||
struct fixed_type y;
|
||||
struct fixed_type z;
|
||||
int color;
|
||||
};
|
||||
|
||||
static void double_to_fixed(double d, struct fixed_type *f) {
|
||||
|
||||
int temp;
|
||||
|
||||
temp=d*256;
|
||||
|
||||
f->i=(temp>>8)&0xff;
|
||||
|
||||
f->f=temp&0xff;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void print_fixed(struct fixed_type *f) {
|
||||
|
||||
printf("%02X.%02X",f->i,f->f);
|
||||
}
|
||||
|
||||
static void fixed_add(struct fixed_type *x, struct fixed_type *y, struct fixed_type *z) {
|
||||
int carry;
|
||||
short sum;
|
||||
|
||||
sum=(short)(x->f)+(short)(y->f);
|
||||
|
||||
if (sum>=256) carry=1;
|
||||
else carry=0;
|
||||
|
||||
z->f=sum&0xff;
|
||||
|
||||
z->i=x->i+y->i+carry;
|
||||
}
|
||||
|
||||
static double fixed_to_double(struct fixed_type *f) {
|
||||
|
||||
double d;
|
||||
|
||||
d=f->i;
|
||||
d+=((double)(f->f))/256.0;
|
||||
|
||||
// printf("(%02x.%02x)=%lf\n",f->i,f->f,*d);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
static struct star_type stars[NUMSTARS];
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int ch,i;
|
||||
|
||||
int spreadx=40;
|
||||
int spready=40;
|
||||
int spreadz=5;
|
||||
int spreadx=256;
|
||||
int spready=256;
|
||||
int spreadz=16;
|
||||
struct fixed_type speedz;
|
||||
|
||||
double_to_fixed(-0.25,&speedz);
|
||||
|
||||
grsim_init();
|
||||
|
||||
for(i=0;i<NUMSTARS;i++) {
|
||||
stars[i].x=(drand48()-0.5)*spreadx;
|
||||
stars[i].y=(drand48()-0.5)*spready;
|
||||
stars[i].z=((drand48())*spreadz)+0.1;
|
||||
printf("%.2lf,%2lf,%.2lf\n",stars[i].x,stars[i].y,stars[i].z);
|
||||
double_to_fixed( (drand48()-0.5)*spreadx,&stars[i].x);
|
||||
double_to_fixed( (drand48()-0.5)*spready,&stars[i].y);
|
||||
double_to_fixed( ((drand48())*spreadz)+0.1,&stars[i].z);
|
||||
print_fixed(&stars[i].x);
|
||||
printf(",");
|
||||
print_fixed(&stars[i].y);
|
||||
printf(",");
|
||||
print_fixed(&stars[i].z);
|
||||
printf("\n");
|
||||
}
|
||||
gr();
|
||||
|
||||
|
||||
while(1) {
|
||||
gr();
|
||||
|
||||
/* Set color */
|
||||
for(i=0;i<NUMSTARS;i++) {
|
||||
if (stars[i].z<2) color_equals(15);
|
||||
else if (stars[i].z<3) color_equals(7);
|
||||
else color_equals(5);
|
||||
basic_plot(stars[i].x/stars[i].z+20,
|
||||
stars[i].y/stars[i].z+20);
|
||||
if (stars[i].z.i<(spreadz/3)) stars[i].color=15;
|
||||
else if (stars[i].z.i<(spreadz*2/3)) stars[i].color=13;
|
||||
else stars[i].color=5;
|
||||
|
||||
}
|
||||
|
||||
/* draw stars */
|
||||
for(i=0;i<NUMSTARS;i++) {
|
||||
stars[i].z+=-0.125;
|
||||
if (stars[i].z<0) {
|
||||
stars[i].x=(drand48()-0.5)*spreadx;
|
||||
stars[i].y=(drand48()-0.5)*spready;
|
||||
stars[i].z=((drand48())*spreadz)+0.1;
|
||||
int tempx,tempy;
|
||||
double dx,dy;
|
||||
|
||||
dx=fixed_to_double(&stars[i].x)/
|
||||
fixed_to_double(&stars[i].z);
|
||||
|
||||
tempx=dx+20;
|
||||
|
||||
dy=fixed_to_double(&stars[i].y)/
|
||||
fixed_to_double(&stars[i].z);
|
||||
|
||||
tempy=dy+20;
|
||||
|
||||
if ((tempx<0) || (tempy<0) || (tempx>=40) ||
|
||||
(tempy>=40)) {
|
||||
|
||||
double_to_fixed((drand48()-0.5)*spreadx,
|
||||
&stars[i].x);
|
||||
double_to_fixed((drand48()-0.5)*spready,
|
||||
&stars[i].y);
|
||||
stars[i].z.i=spreadz;
|
||||
|
||||
}
|
||||
else {
|
||||
color_equals(stars[i].color);
|
||||
basic_plot(tempx,tempy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Move stars */
|
||||
for(i=0;i<NUMSTARS;i++) {
|
||||
fixed_add(&stars[i].z,&speedz,&stars[i].z);
|
||||
}
|
||||
|
||||
grsim_update();
|
||||
ch=grsim_input();
|
||||
if (ch=='q') exit(0);
|
||||
usleep(30000);
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user