summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2011-06-06 07:59:19 +0000
committerIan C <ianc@noddybox.co.uk>2011-06-06 07:59:19 +0000
commita63d34a43ae15cc5e579dfafd6c64a1fe4880f80 (patch)
tree0e4def74f85eb73c31b323735fc4d268d5df61d7
parent45d55fd925d307e3ad249e77acbf658db24239aa (diff)
Readability reformatting.
-rw-r--r--xd.c1252
1 files changed, 721 insertions, 531 deletions
diff --git a/xd.c b/xd.c
index cc2502f..52a694a 100644
--- a/xd.c
+++ b/xd.c
@@ -29,6 +29,7 @@ static const char id[]="$Id$";
#include <string.h>
#include <ctype.h>
#include <math.h>
+#include <errno.h>
#include <X11/X.h>
#include <X11/Xlib.h>
@@ -66,83 +67,84 @@ typedef enum {UsesImage, UsesPixmap} DType;
typedef enum {MousePress, MouseRelease, MouseMove} Mouse;
typedef struct
- {
- const char *name;
- void (*draw)(void);
- DType type;
- } DemoInfo;
+{
+ const char *name;
+ void (*draw)(void);
+ DType type;
+} DemoInfo;
typedef struct
- {
- double x,y,z;
- } Point3D;
+{
+ double x,y,z;
+} Point3D;
#define MAX_POLY_POINTS 32
typedef struct
- {
- int p[MAX_POLY_POINTS];
- int no;
- int col;
- } Poly3D;
+{
+ int p[MAX_POLY_POINTS];
+ int no;
+ int col;
+} Poly3D;
typedef struct
- {
- int no_points;
- int no_poly;
+{
+ int no_points;
+ int no_poly;
- Point3D origin;
+ Point3D origin;
- Point3D *ps;
- Poly3D *poly;
+ Point3D *ps;
+ Poly3D *poly;
- Point3D *workp3;
- XPoint *workxp;
+ Point3D *workp3;
+ XPoint *workxp;
- int x_rot;
- int y_rot;
- int z_rot;
+ int x_rot;
+ int y_rot;
+ int z_rot;
- int mode;
+ int mode;
- int col;
+ int col;
- int cull;
- } Obj3D;
+ int cull;
+} Obj3D;
#define MODE_SOLID 0
#define MODE_WIRE 1
#define MODE_EDGE 2
typedef struct
- {
- Point3D origin;
- int radius;
- int mode;
- unsigned long col;
- } Sphere3D;
+{
+ Point3D origin;
+ int radius;
+ int mode;
+ unsigned long col;
+} Sphere3D;
typedef struct
- {
- Point3D origin;
- int w,h;
- int mode;
- unsigned long col;
- } Rect3D;
+{
+ Point3D origin;
+ int w;
+ int h;
+ int mode;
+ unsigned long col;
+} Rect3D;
typedef struct
- {
- Point3D origin;
- unsigned long col;
- } Particle3D;
+{
+ Point3D origin;
+ unsigned long col;
+} Particle3D;
typedef enum {eObj, eSphere, eRect, eParticle} ObjType;
typedef struct
- {
- ObjType type;
- void *p;
- } WorldObj;
+{
+ ObjType type;
+ void *p;
+} WorldObj;
/* ---------------------------------------- DEMO PROTOS
*/
@@ -346,17 +348,21 @@ int main(int argc, char *argv[])
int f;
for(f=1;f<argc;f++)
- {
+ {
if (!strcmp(argv[f],"-r"))
+ {
use_root=TRUE;
+ }
else if (!strcmp(argv[f],"-c"))
+ {
cycle=TRUE;
+ }
else
- {
+ {
demo=atoi(argv[f]);
demo=MAX(0,MIN(demo,NO_DEMOS-1));
- }
}
+ }
OpenX();
XMapWindow(disp,win);
@@ -368,23 +374,25 @@ int main(int argc, char *argv[])
blue=GetCol(0,0,255);
for(f=0;f<3600;f++)
- {
+ {
sintab[f]=sin(RAD(f*0.10));
costab[f]=cos(RAD(f*0.10));
- }
+ }
srand(getpid());
while(TRUE)
- {
+ {
int update;
+ Window w1,w2;
+ int i1,i2;
if (XPending(disp))
- {
+ {
XNextEvent(disp,&ev);
switch(ev.type)
- {
+ {
case KeyPress:
HandleKey(&ev.xkey);
break;
@@ -414,19 +422,14 @@ int main(int argc, char *argv[])
default:
break;
- }
}
-
- {
- Window w1,w2;
- int i1,i2;
+ }
XQueryPointer(disp,win,&w1,&w2,&i1,&i2,&mouse_x,&mouse_y,&mouse_b);
- }
demotbl[demo].draw();
Redraw();
- }
+ }
return EXIT_SUCCESS;
}
@@ -440,12 +443,20 @@ static void Error(char *p)
exit(EXIT_FAILURE);
}
+static void SysError(char *p)
+{
+ perror(p);
+ exit(EXIT_FAILURE);
+}
+
static void *Grab(size_t s)
{
void *p;
if (!(p=malloc(s)))
- Error("malloc()");
+ {
+ SysError("malloc()");
+ }
return p;
}
@@ -463,16 +474,16 @@ static void Bounce(int *x, int *y, int *ix, int *iy)
*y+=*iy;
if (*x<0 || *x>=width)
- {
+ {
*ix=-(*ix);
*x+=*ix;
- }
+ }
if (*y<0 || *y>=height)
- {
+ {
*iy=-(*iy);
*y+=*iy;
- }
+ }
}
@@ -487,35 +498,43 @@ static void OpenX(void)
/* Open display and find an appropriate visual
*/
if (!(disp=XOpenDisplay(NULL)))
+ {
Error("Couldn't open X display");
+ }
if (!XMatchVisualInfo(disp,DefaultScreen(disp),32,TrueColor,&visual) &&
!XMatchVisualInfo(disp,DefaultScreen(disp),24,TrueColor,&visual) &&
!XMatchVisualInfo(disp,DefaultScreen(disp),16,TrueColor,&visual) &&
!XMatchVisualInfo(disp,DefaultScreen(disp),15,TrueColor,&visual))
- Error("Couldn't find a visual\n");
+ {
+ Error("Couldn't find a visual");
+ }
font=XLoadQueryFont(disp,"fixed");
if (!font)
+ {
Error("Couldn't load font fixed");
+ }
width=640;
height=480;
if (!use_root)
+ {
win=XCreateWindow(disp,DefaultRootWindow(disp),
0,0,width,height,0,
visual.depth,
InputOutput,
visual.visual,
0,NULL);
+ }
else
- {
- win=DefaultRootWindow(disp);
+ {
+ win=DefaultRootWindow(disp);
width=DisplayWidth(disp,DefaultScreen(disp));
height=DisplayHeight(disp,DefaultScreen(disp));
- }
+ }
centre_x=width/2;
centre_y=height/2;
@@ -553,12 +572,12 @@ static void OpenX(void)
&gc_val);
if (use_root)
- {
+ {
/*
XSetCloseDownMode(disp,RetainTemporary);
XSetWindowBackgroundPixmap(disp,win,pix);
*/
- }
+ }
/* TODO: XImage creation */
@@ -585,11 +604,13 @@ static void ClsCol(unsigned long col)
static void Redraw(void)
{
if (demotbl[demo].type==UsesPixmap)
+ {
XCopyArea(disp,pix,win,gc,0,0,width,height,0,0);
+ }
else
- {
+ {
/* TODO: XImage copy */
- }
+ }
/* XFlush(disp); */
XSync(disp,FALSE);
}
@@ -619,10 +640,10 @@ static void Plot(int x,int y,int col)
static void Circle(int x,int y,int r,int col)
{
if (r<1)
- {
+ {
Plot(x,y,col);
return;
- }
+ }
SetCol(col);
XDrawArc(disp,pix,gc,x-r,y-r,r*2,r*2,0,64*360);
@@ -632,10 +653,10 @@ static void Circle(int x,int y,int r,int col)
static void FCircle(int x,int y,int r,int col)
{
if (r<1)
- {
+ {
Plot(x,y,col);
return;
- }
+ }
SetCol(col);
XFillArc(disp,pix,gc,x-r,y-r,r*2,r*2,0,64*360);
@@ -664,10 +685,10 @@ static void Print(int x,int y,int col,char *fmt,...)
static void Rect(int x,int y,int w,int h,int col)
{
if (w==0 && h==0)
- {
+ {
Plot(x,y,col);
return;
- }
+ }
SetCol(col);
XDrawRectangle(disp,pix,gc,x,y,w,h);
@@ -677,10 +698,10 @@ static void Rect(int x,int y,int w,int h,int col)
static void FRect(int x,int y,int w,int h,int col)
{
if (w==0 && h==0)
- {
+ {
Plot(x,y,col);
return;
- }
+ }
SetCol(col);
XFillRectangle(disp,pix,gc,x,y,w,h);
@@ -692,7 +713,9 @@ static void Polygon(XPoint p[], int no, int col)
int f;
for(f=0;f<no;f++)
+ {
LineP(p+f,p+(f+1)%no,col);
+ }
}
@@ -723,7 +746,9 @@ static void SetCol(unsigned long col)
static unsigned long last_col=123;
if (col==last_col)
+ {
return;
+ }
last_col=col;
@@ -734,12 +759,14 @@ static void SetCol(unsigned long col)
static void HandleKey(XKeyEvent *key)
{
switch(XLookupKeysym(key,0))
- {
+ {
case XK_Prior:
demo--;
if (demo<0)
+ {
demo=NO_DEMOS-1;
+ }
XStoreName(disp,win,demotbl[demo].name);
Cls();
@@ -754,14 +781,14 @@ static void HandleKey(XKeyEvent *key)
default:
break;
- }
+ }
}
static void HandleMouse(int x, int y, int b, Mouse mode)
{
switch(mode)
- {
+ {
case MousePress:
mouse_b|=(1<<(b-1));
break;
@@ -772,7 +799,7 @@ static void HandleMouse(int x, int y, int b, Mouse mode)
default:
break;
- }
+ }
mouse_x=x;
mouse_y=y;
@@ -784,7 +811,9 @@ static int AngToCol(int ang, int no_col)
int d;
if (ang>1800)
+ {
ang=1800-(ang-1800);
+ }
d=(int)((no_col/1800.0)*(double)ang);
@@ -826,17 +855,19 @@ static void RotateX(double cx, double cy, double cz,
double dy,dz,si,co;
while(a<0)
+ {
a+=3600;
+ }
a%=3600;
if (a==0)
- {
+ {
*x=ix;
*y=iy;
*z=iz;
return;
- }
+ }
dy=iy-cy;
dz=iz-cz;
@@ -858,17 +889,19 @@ static void RotateY(double cx, double cy, double cz,
double dx,dz,si,co;
while(a<0)
+ {
a+=3600;
+ }
a%=3600;
if (a==0)
- {
+ {
*x=ix;
*y=iy;
*z=iz;
return;
- }
+ }
dx=ix-cx;
dz=iz-cz;
@@ -890,17 +923,19 @@ static void RotateZ(double cx, double cy, double cz,
double dy,dx,si,co;
while(a<0)
+ {
a+=3600;
+ }
a%=3600;
if (a==0)
- {
+ {
*x=ix;
*y=iy;
*z=iz;
return;
- }
+ }
dy=iy-cy;
dx=ix-cx;
@@ -919,7 +954,7 @@ static void DrawObj(Obj3D *o, unsigned long cmap[])
int f;
for(f=0;f<o->no_points;f++)
- {
+ {
RotateX(0,0,0,
o->ps[f].x,o->ps[f].y,o->ps[f].z,
&o->workp3[f].x,&o->workp3[f].y,&o->workp3[f].z,
@@ -939,29 +974,38 @@ static void DrawObj(Obj3D *o, unsigned long cmap[])
o->origin.y+o->workp3[f].y,
o->origin.z+o->workp3[f].z,
o->workxp+f);
- }
+ }
for(f=0;f<o->no_poly;f++)
- {
+ {
static XPoint p[MAX_POLY_POINTS];
int r;
int c=-1;
int col;
for(r=0;r<o->poly[f].no;r++)
+ {
p[r]=o->workxp[o->poly[f].p[r]];
+ }
if (o->cull)
+ {
c=(p[0].x-p[1].x)*(p[2].y-p[1].y)-(p[0].y-p[1].y)*(p[2].x-p[1].x);
+ }
if (o->col!=-1)
+ {
col=cmap[o->col];
+ }
else
+ {
col=cmap[o->poly[f].col];
+ }
if (c<0)
+ {
switch(o->mode)
- {
+ {
case MODE_SOLID:
FPolygon(p,o->poly[f].no,col);
break;
@@ -973,8 +1017,9 @@ static void DrawObj(Obj3D *o, unsigned long cmap[])
default:
Polygon(p,o->poly[f].no,col);
break;
- }
+ }
}
+ }
}
@@ -987,7 +1032,7 @@ static int ZSort(const void *p1, const void *p2)
o2=p2;
switch(o1->type)
- {
+ {
case eObj:
z1=((const Obj3D *)o1->p)->origin.z;
break;
@@ -1003,10 +1048,10 @@ static int ZSort(const void *p1, const void *p2)
default:
z1=-1;
break;
- }
+ }
switch(o2->type)
- {
+ {
case eObj:
z2=((const Obj3D *)o2->p)->origin.z;
break;
@@ -1022,7 +1067,7 @@ static int ZSort(const void *p1, const void *p2)
default:
z2=-1;
break;
- }
+ }
return (int)(z2-z1);
}
@@ -1037,7 +1082,7 @@ static int InvZSort(const void *p1, const void *p2)
o2=p2;
switch(o1->type)
- {
+ {
case eObj:
z1=((const Obj3D *)o1->p)->origin.z;
break;
@@ -1053,10 +1098,10 @@ static int InvZSort(const void *p1, const void *p2)
default:
z1=-1;
break;
- }
+ }
switch(o2->type)
- {
+ {
case eObj:
z2=((const Obj3D *)o2->p)->origin.z;
break;
@@ -1072,7 +1117,7 @@ static int InvZSort(const void *p1, const void *p2)
default:
z2=-1;
break;
- }
+ }
return (int)(z1-z2);
}
@@ -1088,17 +1133,21 @@ static void DrawList(WorldObj *w, int no, unsigned long cmap[],
Rect3D *r;
if (do_sort)
- {
+ {
if (inv_z_order)
+ {
qsort(w,no,sizeof(WorldObj),InvZSort);
+ }
else
+ {
qsort(w,no,sizeof(WorldObj),ZSort);
}
+ }
for(f=0;f<no;f++)
- {
+ {
switch(w[f].type)
- {
+ {
case eObj:
DrawObj(w[f].p,cmap);
break;
@@ -1107,10 +1156,12 @@ static void DrawList(WorldObj *w, int no, unsigned long cmap[],
s=w[f].p;
if (Project(s->origin.x,s->origin.y,s->origin.z,&xp))
+ {
if (Project(s->origin.x+s->radius,s->origin.y,
s->origin.z,&xp2))
+ {
switch(s->mode)
- {
+ {
case MODE_SOLID:
FCircle(xp.x,xp.y,xp2.x-xp.x,cmap[s->col]);
break;
@@ -1121,23 +1172,26 @@ static void DrawList(WorldObj *w, int no, unsigned long cmap[],
FCircle(xp.x,xp.y,xp2.x-xp.x,black);
Circle(xp.x,xp.y,xp2.x-xp.x,cmap[s->col]);
break;
- }
+ }
+ }
+ }
break;
case eRect:
r=w[f].p;
if (Project(r->origin.x,r->origin.y,r->origin.z,&xp))
+ {
if (Project(r->origin.x+r->w,r->origin.y+r->h,
r->origin.z,&xp2))
- {
+ {
int w,h;
w=xp2.x-xp.x;
h=xp2.y-xp.y;
switch(r->mode)
- {
+ {
case MODE_SOLID:
FRect(xp.x,xp.y,w,h,cmap[r->col]);
break;
@@ -1148,22 +1202,25 @@ static void DrawList(WorldObj *w, int no, unsigned long cmap[],
FRect(xp.x,xp.y,w,h,black);
Rect(xp.x,xp.y,w,h,cmap[r->col]);
break;
- }
}
+ }
+ }
break;
case eParticle:
p=w[f].p;
if (Project(p->origin.x,p->origin.y,p->origin.z,&xp))
+ {
Plot(xp.x,xp.y,cmap[p->col]);
+ }
break;
default:
break;
- }
}
+ }
}
@@ -1185,28 +1242,28 @@ static void DrawSubList(Obj3D *o, int obj_no,
i=0;
for(f=0;f<obj_no;f++,i++)
- {
+ {
w[i].type=eObj;
w[i].p=o+f;
- }
+ }
for(f=0;f<sphere_no;f++,i++)
- {
+ {
w[i].type=eSphere;
w[i].p=s+f;
- }
+ }
for(f=0;f<rect_no;f++,i++)
- {
+ {
w[i].type=eRect;
w[i].p=r+f;
- }
+ }
for(f=0;f<particle_no;f++,i++)
- {
+ {
w[i].type=eParticle;
w[i].p=p+f;
- }
+ }
DrawList(w,no,cmap,inv_z_order,do_sort);
@@ -1224,7 +1281,9 @@ static void ExampleDemo(void)
Print(0,20,GetCol(255,255,255),"X: %d Y:%d B:%d",mouse_x,mouse_y,mouse_b);
if (mouse_b&Button1Mask)
+ {
Line(0,0,mouse_x,mouse_y,GetCol(RND(0xff),RND(0xff),RND(0xff)));
+ }
}
@@ -1240,10 +1299,10 @@ static void DropDemo(void)
static time_t last=0;
typedef struct Drop
- {
+ {
int x,y,r,c;
struct Drop *next;
- } Drop;
+ } Drop;
static Drop *head=NULL;
static Drop *tail=NULL;
@@ -1251,28 +1310,30 @@ static void DropDemo(void)
Drop *d;
if (!init)
- {
+ {
int f;
for(f=0;f<256;f++)
+ {
col[f]=GetCol(255-f,255-f,255-f);
+ }
init=TRUE;
- }
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
clr=!clr;
bounce=time(NULL);
- }
}
+ }
if (mouse_b&Button1Mask /*&& (last!=time(NULL))*/)
- {
+ {
Drop *new;
new=Grab(sizeof *new);
@@ -1284,45 +1345,53 @@ static void DropDemo(void)
new->next=NULL;
if (!head)
+ {
head=tail=new;
+ }
else
- {
+ {
tail->next=new;
tail=new;
- }
+ }
last=time(NULL);
- }
+ }
if (clr)
+ {
Cls();
+ }
d=head;
while(d)
- {
+ {
if (d->c>=256)
- {
+ {
Drop *t;
if (d->next)
+ {
head=d->next;
+ }
else
+ {
head=tail=NULL;
+ }
t=d;
d=d->next;
Release(t);
- }
+ }
else
- {
+ {
Circle(d->x,d->y,d->r,col[d->c]);
d->r+=scale;
d->c+=speed;
d=d->next;
- }
}
+ }
}
@@ -1338,12 +1407,12 @@ static void AutoDropDemo(void)
static time_t last=0;
typedef struct Drop
- {
+ {
int x,y,r,c;
int speed;
int scale;
struct Drop *next;
- } Drop;
+ } Drop;
static Drop *head=NULL;
static Drop *tail=NULL;
@@ -1352,17 +1421,19 @@ static void AutoDropDemo(void)
int f;
if (!init)
- {
+ {
int f;
for(f=0;f<256;f++)
+ {
col[f]=GetCol(MAX(255-f*2,0),MAX(255-f*2,0),255-f);
+ }
init=TRUE;
- }
+ }
if (last!=time(NULL) && !head)
- {
+ {
int x,y,sc;
x=RND(width);
@@ -1370,7 +1441,7 @@ static void AutoDropDemo(void)
sc=scale;
for(f=0;f<num;f++)
- {
+ {
Drop *new;
new=Grab(sizeof *new);
@@ -1384,49 +1455,55 @@ static void AutoDropDemo(void)
new->next=NULL;
if (!head)
+ {
head=tail=new;
+ }
else
- {
+ {
tail->next=new;
tail=new;
- }
}
+ }
last=time(NULL);
- }
+ }
/* Cls(); */
d=head;
while(d)
- {
+ {
if (d->c>=256)
- {
+ {
Drop *t;
if (d->next)
- head=d->next;
+ {
+ head=d->next;
+ }
else
- head=tail=NULL;
+ {
+ head=tail=NULL;
+ }
t=d;
d=d->next;
Release(t);
- }
+ }
else
- {
+ {
Circle(d->x,d->y,d->r,col[d->c]);
d->r+=d->scale;
d->c+=d->speed;
d=d->next;
- }
}
+ }
}
/* ---------------------------------------- FAST DROP DEMO
-*/
+ */
static void FastDropDemo(void)
{
static const int speed=30;
@@ -1437,10 +1514,10 @@ static void FastDropDemo(void)
static time_t last=0;
typedef struct Drop
- {
+ {
int x,y,r,c;
struct Drop *next;
- } Drop;
+ } Drop;
static Drop *head=NULL;
static Drop *tail=NULL;
@@ -1448,28 +1525,30 @@ static void FastDropDemo(void)
Drop *d;
if (!init)
- {
+ {
int f;
for(f=0;f<256;f++)
+ {
col[f]=GetCol(255-f,255-f,255-f);
+ }
init=TRUE;
- }
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
clr=!clr;
bounce=time(NULL);
- }
}
+ }
if (mouse_b&Button1Mask /*&& (last!=time(NULL))*/)
- {
+ {
Drop *new;
new=Grab(sizeof *new);
@@ -1481,50 +1560,58 @@ static void FastDropDemo(void)
new->next=NULL;
if (!head)
+ {
head=tail=new;
+ }
else
- {
+ {
tail->next=new;
tail=new;
- }
+ }
last=time(NULL);
- }
+ }
if (clr)
+ {
Cls();
+ }
d=head;
while(d)
- {
+ {
if (d->c>=256)
- {
+ {
Drop *t;
if (d->next)
- head=d->next;
+ {
+ head=d->next;
+ }
else
- head=tail=NULL;
+ {
+ head=tail=NULL;
+ }
t=d;
d=d->next;
Release(t);
- }
+ }
else
- {
+ {
Rect(d->x-d->r/2,d->y-d->r/2,d->r,d->r,col[d->c]);
d->r+=scale;
d->c+=speed;
d=d->next;
- }
}
+ }
}
/* ---------------------------------------- TRAIL DEMO
-*/
+ */
static void TrailDemo(void)
{
static const int NO=20;
@@ -1534,15 +1621,15 @@ static void TrailDemo(void)
static unsigned long col[256];
static struct
- {
+ {
int x,y,xi,yi;
- } *p;
+ } *p;
typedef struct Drop
- {
+ {
int x,y,r,c;
struct Drop *next;
- } Drop;
+ } Drop;
static Drop *head=NULL;
static Drop *tail=NULL;
@@ -1551,28 +1638,31 @@ static void TrailDemo(void)
int f;
if (!init)
- {
+ {
for(f=0;f<256;f++)
+ {
col[f]=GetCol(255-f,255-f,255-f);
+ }
p=Grab(sizeof(*p)*NO);
for(f=0;f<NO;f++)
- {
+ {
p[f].x=RND(width);
p[f].y=RND(height);
- do {
+ do
+ {
p[f].xi=RND(5)-2;
p[f].yi=RND(5)-2;
- } while (p[f].xi==0 || p[f].yi==0);
- }
+ } while (p[f].xi==0 || p[f].yi==0);
+ }
init=TRUE;
- }
+ }
for(f=0;f<NO;f++)
- {
+ {
int r;
new=Grab(sizeof *new);
@@ -1584,48 +1674,54 @@ static void TrailDemo(void)
new->next=NULL;
if (!head)
+ {
head=tail=new;
+ }
else
- {
+ {
tail->next=new;
tail=new;
- }
+ }
Bounce(&p[f].x,&p[f].y,&p[f].xi,&p[f].yi);
- }
+ }
/* Cls(); */
d=head;
while(d)
- {
+ {
if (d->c>=256)
- {
+ {
Drop *t;
if (d->next)
- head=d->next;
+ {
+ head=d->next;
+ }
else
- head=tail=NULL;
+ {
+ head=tail=NULL;
+ }
t=d;
d=d->next;
Release(t);
- }
+ }
else
- {
+ {
FRect(d->x-d->r/2,d->y-d->r/2,d->r,d->r,col[d->c]);
d->r+=scale;
d->c+=speed;
d=d->next;
- }
}
+ }
}
/* ---------------------------------------- TUNNEL DEMO
-*/
+ */
static void TunnelDemo(void)
{
static const int speed=100;
@@ -1644,14 +1740,14 @@ static void TunnelDemo(void)
static int create=0;
typedef struct Drop
- {
+ {
double x[points];
double y[points];
double z;
int r,c;
int ang;
struct Drop *next;
- } Drop;
+ } Drop;
static Drop *head=NULL;
static Drop *tail=NULL;
@@ -1660,44 +1756,46 @@ static void TunnelDemo(void)
int f;
if (!init)
- {
+ {
for(f=0;f<256;f++)
+ {
col[f]=GetCol(255-f,255-f,255-f);
+ }
si=Grab(sizeof(double)*points);
co=Grab(sizeof(double)*points);
for(f=0;f<points;f++)
- {
+ {
si[f]=sin(RAD(360.0/points*f));
co[f]=cos(RAD(360.0/points*f));
- }
+ }
init=TRUE;
- }
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
clr=!clr;
bounce=time(NULL);
- }
}
+ }
if (create==0)
- {
+ {
Drop *new;
new=Grab(sizeof *new);
for(f=0;f<points;f++)
- {
+ {
new->x[f]=(RND(radius>>1)+radius>>1)*si[f];
new->y[f]=(RND(radius>>1)+radius>>1)*co[f];
- }
+ }
new->r=radius;
new->z=max_z;
@@ -1706,73 +1804,89 @@ static void TunnelDemo(void)
new->ang=RND(20)-10;
if (new->ang<0)
+ {
new->ang+=3600;
+ }
new->next=NULL;
if (!head)
+ {
head=tail=new;
+ }
else
- {
+ {
tail->next=new;
tail=new;
- }
+ }
create=delay;
- }
+ }
else
- create--;
+ {
+ create--;
+ }
if (clr)
+ {
Cls();
+ }
d=head;
while(d)
- {
+ {
if (d->z<10)
- {
+ {
Drop *t;
if (d->next)
- head=d->next;
+ {
+ head=d->next;
+ }
else
- head=tail=NULL;
+ {
+ head=tail=NULL;
+ }
t=d;
d=d->next;
Release(t);
- }
+ }
else
- {
+ {
XPoint p[points];
if (d->c)
+ {
d->c=MAX(0,d->c-10);
+ }
for(f=0;f<points;f++)
- {
+ {
RotateZ(0,0,d->z,
d->x[f],d->y[f],d->z,
&d->x[f],&d->y[f],&d->z,
d->ang);
Project(d->x[f],d->y[f],d->z,p+f);
- }
+ }
for(f=0;f<points;f++)
+ {
LineP(p+f,p+((f+1)%points),col[d->c]);
+ }
d->z-=speed;
d=d->next;
- }
}
+ }
}
/* ---------------------------------------- STAR DEMO
-*/
+ */
static void StarDemo(void)
{
# define TYPE Particle3D
@@ -1782,36 +1896,36 @@ static void StarDemo(void)
static const int no_poly=4;
static Point3D pset[4]=
- {
- {-100,50,100},
- {100,50,100},
- {0,-50,100},
- {0,0,-300},
- };
+ {
+ {-100,50,100},
+ {100,50,100},
+ {0,-50,100},
+ {0,0,-300},
+ };
static Poly3D plist[4]=
- {
- {
- {0,3,1},
- 3,
- 0
- },
- {
- {0,1,2},
- 3,
- 0
- },
- {
- {0,2,3},
- 3,
- 0
- },
- {
- {1,3,2},
- 3,
- 0
- },
- };
+ {
+ {
+ {0,3,1},
+ 3,
+ 0
+ },
+ {
+ {0,1,2},
+ 3,
+ 0
+ },
+ {
+ {0,2,3},
+ 3,
+ 0
+ },
+ {
+ {1,3,2},
+ 3,
+ 0
+ },
+ };
static Obj3D *obj;
@@ -1839,14 +1953,16 @@ static void StarDemo(void)
int f;
if (!init)
- {
+ {
for(f=0;f<256;f++)
+ {
col[f]=GetCol(255-f,255-f,255-f);
+ }
star=Grab(sizeof(TYPE)*no);
for(f=0;f<no;f++)
- {
+ {
star[f].origin.x=RND(radius)-radius/2;
star[f].origin.y=RND(radius)-radius/2;
star[f].origin.z=RND(max_z);
@@ -1856,12 +1972,12 @@ static void StarDemo(void)
star[f].mode=MODE_EDGE;
# endif
star[f].col=255;
- }
+ }
obj=Grab(sizeof(Obj3D)*no_obj);
for(f=0;f<no_obj;f++)
- {
+ {
obj[f].no_points=no_points;
obj[f].no_poly=no_poly;
obj[f].ps=pset;
@@ -1879,97 +1995,103 @@ static void StarDemo(void)
obj[f].origin.z=RND(radius);
obj[f].col=255;
- }
+ }
init=TRUE;
- }
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
clr=!clr;
bounce=time(NULL);
- }
}
+ }
if (!clr)
- {
+ {
if (speed<max_speed)
+ {
speed+=speed_inc;
}
+ }
else
- {
+ {
if (speed>min_speed)
+ {
speed-=speed_inc;
}
+ }
Cls();
for(f=0;f<no;f++)
- {
+ {
if (star[f].origin.z<1000)
- {
+ {
star[f].origin.x=RND(radius)-radius/2;
star[f].origin.y=RND(radius)-radius/2;
star[f].origin.z=max_z;
star[f].col=255;
- }
+ }
else
- {
+ {
/*
- RotateZ(0,0,0,
- star[f].origin.x,star[f].origin.y,star[f].origin.z,
- &star[f].origin.x,&star[f].origin.y,&star[f].origin.z,
- 1);
- */
+ RotateZ(0,0,0,
+ star[f].origin.x,star[f].origin.y,star[f].origin.z,
+ &star[f].origin.x,&star[f].origin.y,&star[f].origin.z,
+ 1);
+ */
if (speed>min_speed)
- {
+ {
XPoint p;
XPoint p2;
Project(star[f].origin.x,star[f].origin.y,star[f].origin.z,&p);
Project(star[f].origin.x,star[f].origin.y,star[f].origin.z+speed*speed,&p2);
LineP(&p,&p2,col[star[f].col]);
- }
+ }
star[f].origin.z-=20*speed;
if (star[f].col)
- star[f].col--;
- }
+ star[f].col--;
}
+ }
for(f=0;f<no_obj;f++)
- {
+ {
obj[f].origin.z-=100*speed;
obj[f].z_rot+=10;
if (obj[f].col)
+ {
obj[f].col=MAX(0,obj[f].col-speed);
+ }
if (obj[f].origin.z<400)
- {
+ {
obj[f].origin.x=RND(radius/8)-radius/16;
obj[f].origin.y=RND(radius/8)-radius/16;
obj[f].origin.z=radius*2;
obj[f].col=255;
- }
}
+ }
# if defined(ISSPHERE)
- DrawSubList(obj,no_obj,star,no,NULL,0,NULL,0,col,False,True);
+ DrawSubList(obj,no_obj,star,no,NULL,0,NULL,0,col,False,True);
# else
- DrawSubList(obj,no_obj,NULL,0,NULL,0,star,no,col,False,True);
+ DrawSubList(obj,no_obj,NULL,0,NULL,0,star,no,col,False,True);
# endif
}
/* ---------------------------------------- STAR SPHERE DEMO
-*/
+ */
static void StarSphereDemo(void)
{
static const int no=100;
@@ -1993,15 +2115,17 @@ static void StarSphereDemo(void)
int f;
if (!init)
- {
+ {
for(f=0;f<256;f++)
+ {
col[f]=GetCol(255-f,255-f,255-f);
+ }
star=Grab(sizeof(Sphere3D)*no);
wo=Grab(sizeof(WorldObj)*no);
for(f=0;f<no;f++)
- {
+ {
star[f].origin.x=RND(radius)-radius/2;
star[f].origin.y=RND(radius)-radius/2;
star[f].origin.z=RND(max_z);
@@ -2011,59 +2135,65 @@ static void StarSphereDemo(void)
wo[f].type=eSphere;
wo[f].p=star+f;
- }
+ }
init=TRUE;
- }
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
clr=!clr;
bounce=time(NULL);
- }
}
+ }
if (!clr)
- {
+ {
if (speed<max_speed)
+ {
speed+=speed_inc;
}
+ }
else
- {
+ {
if (speed>min_speed)
+ {
speed-=speed_inc;
}
+ }
Cls();
for(f=0;f<no;f++)
- {
+ {
if (star[f].origin.z<1000)
- {
+ {
star[f].origin.x=RND(radius)-radius/2;
star[f].origin.y=RND(radius)-radius/2;
star[f].origin.z=max_z;
star[f].col=255;
- }
+ }
else
- {
+ {
star[f].origin.z-=base_speed*speed;
if (star[f].col)
- star[f].col=MAX(0,star[f].col-speed);
+ {
+ star[f].col=MAX(0,star[f].col-speed);
}
}
+ }
DrawList(wo,no,col,False,True);
}
/* ---------------------------------------- TEST 3D DEMO
-*/
+ */
static void Test3DDemo(void)
{
static const int no_particle=2000;
@@ -2075,66 +2205,66 @@ static void Test3DDemo(void)
static XPoint xpwork[8];
static Point3D pset[8]=
- {
- {-50,-200,50},
- {50,-200,50},
- {50,-200,-50},
- {-50,-200,-50},
-
- {50,200,50},
- {-50,200,50},
- {-50,200,-50},
- {50,200,-50},
- };
+ {
+ {-50,-200,50},
+ {50,-200,50},
+ {50,-200,-50},
+ {-50,-200,-50},
+
+ {50,200,50},
+ {-50,200,50},
+ {-50,200,-50},
+ {50,200,-50},
+ };
static Poly3D plist[6]=
- {
- {
- {0,1,2,3},
- 4,
- 0
- },
- {
- {4,5,6,7},
- 4,
- 0
- },
- {
- {0,5,4,1},
- 4,
- 1
- },
- {
- {2,1,4,7},
- 4,
- 2
- },
- {
- {3,2,7,6},
- 4,
- 3
- },
- {
- {0,3,6,5},
- 4,
- 2
- },
- };
+ {
+ {
+ {0,1,2,3},
+ 4,
+ 0
+ },
+ {
+ {4,5,6,7},
+ 4,
+ 0
+ },
+ {
+ {0,5,4,1},
+ 4,
+ 1
+ },
+ {
+ {2,1,4,7},
+ 4,
+ 2
+ },
+ {
+ {3,2,7,6},
+ 4,
+ 3
+ },
+ {
+ {0,3,6,5},
+ 4,
+ 2
+ },
+ };
static Obj3D obj=
- {
- 8,
- 6,
- {0,0,1000},
- pset,
- plist,
- pwork,
- xpwork,
- 0,0,0,
- MODE_SOLID,
- -1,
- True
- };
+ {
+ 8,
+ 6,
+ {0,0,1000},
+ pset,
+ plist,
+ pwork,
+ xpwork,
+ 0,0,0,
+ MODE_SOLID,
+ -1,
+ True
+ };
static Particle3D *p;
static WorldObj *w;
@@ -2146,7 +2276,7 @@ static void Test3DDemo(void)
int f;
if (!init)
- {
+ {
col[0]=white;
col[1]=red;
col[2]=green;
@@ -2158,74 +2288,84 @@ static void Test3DDemo(void)
w=Grab(sizeof(WorldObj)*(no_particle+1));
for(f=0;f<no_particle;f++)
- {
+ {
p[f].origin.x=RND(radius*2)-radius;
p[f].origin.y=RND(radius*2)-radius;
p[f].origin.z=RND(max_z-min_z)+min_z;
+
if (RND(2)==1)
+ {
p[f].origin.z=max_z;
+ }
else
+ {
p[f].origin.z=min_z;
+ }
+
p[f].col=0;
w[f].p=p+f;
w[f].type=eParticle;
- }
+ }
w[no_particle].type=eObj;
w[no_particle].p=&obj;
DrawList(w,no_particle+1,col,False,True);
- }
+ }
if (mouse_b&Button2Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
rot=(rot+1)%3;
bounce=time(NULL);
- }
}
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
obj.cull=!obj.cull;
bounce=time(NULL);
- }
}
+ }
if (mouse_b&Button1Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
obj.mode++;
if (obj.mode>MODE_EDGE)
- obj.mode=MODE_SOLID;
+ {
+ obj.mode=MODE_SOLID;
+ }
bounce=time(NULL);
- }
}
+ }
Cls();
for(f=0;f<no_particle;f++)
- {
+ {
p[f].origin.y+=1;
if (p[f].origin.y>radius)
+ {
p[f].origin.y=-radius;
}
+ }
switch(rot)
- {
+ {
case 0:
Print(0,20,white,"Y rotation");
obj.y_rot+=10;
@@ -2240,7 +2380,7 @@ static void Test3DDemo(void)
break;
default:
break;
- }
+ }
Print(0,30,white,"Mode : %d Culling: %s",obj.mode,obj.cull ? "on":"off");
@@ -2249,7 +2389,7 @@ static void Test3DDemo(void)
/* ---------------------------------------- COL SCAPE DEMO
-*/
+ */
static void ColScapeDemo(void)
{
static const int gap=200;
@@ -2263,51 +2403,51 @@ static void ColScapeDemo(void)
static const double y_base=100.0;
static Point3D pset[8]=
- {
- {-50,-20,50},
- {50,-20,50},
- {50,-20,-50},
- {-50,-20,-50},
-
- {50,20,50},
- {-50,20,50},
- {-50,20,-50},
- {50,20,-50},
- };
+ {
+ {-50,-20,50},
+ {50,-20,50},
+ {50,-20,-50},
+ {-50,-20,-50},
+
+ {50,20,50},
+ {-50,20,50},
+ {-50,20,-50},
+ {50,20,-50},
+ };
static Poly3D plist[6]=
- {
- {
- {0,1,2,3},
- 4,
- 0
- },
- {
- {4,5,6,7},
- 4,
- 0
- },
- {
- {0,5,4,1},
- 4,
- 0
- },
- {
- {2,1,4,7},
- 4,
- 0
- },
- {
- {3,2,7,6},
- 4,
- 0
- },
- {
- {0,3,6,5},
- 4,
- 0
- },
- };
+ {
+ {
+ {0,1,2,3},
+ 4,
+ 0
+ },
+ {
+ {4,5,6,7},
+ 4,
+ 0
+ },
+ {
+ {0,5,4,1},
+ 4,
+ 0
+ },
+ {
+ {2,1,4,7},
+ 4,
+ 0
+ },
+ {
+ {3,2,7,6},
+ 4,
+ 0
+ },
+ {
+ {0,3,6,5},
+ 4,
+ 0
+ },
+ };
static Obj3D *obj;
@@ -2321,7 +2461,7 @@ static void ColScapeDemo(void)
int f,a;
if (!init)
- {
+ {
int x,z;
col[0]=white;
@@ -2339,7 +2479,7 @@ static void ColScapeDemo(void)
a=0;
for(f=0;f<no;f++)
- {
+ {
w[f].p=obj+f;
w[f].type=eObj;
@@ -2365,26 +2505,26 @@ static void ColScapeDemo(void)
a+=20;
if (((f+1)%no_x)==0)
- {
+ {
x=-(no_x/2)*gap;
z-=gap;
- }
}
+ }
DrawList(w,no,col,False,True);
- }
+ }
Cls();
a=ang;
for(f=0;f<no;f++)
- {
+ {
obj[f].origin.y=y_base+sintab[a]*y_range;
obj[f].y_rot+=10;
obj[f].x_rot+=10;
a=(a+5)%3600;
- }
+ }
ang=(ang+10)%3600;
@@ -2393,7 +2533,7 @@ static void ColScapeDemo(void)
/* ---------------------------------------- FLUID DEMO
-*/
+ */
static void FluidDemo(void)
{
static const int gap=20;
@@ -2415,13 +2555,15 @@ static void FluidDemo(void)
int f,a,a2;
if (!init)
- {
+ {
int x,z,c;
col=Grab(sizeof(*col)*no_z);
for(f=0;f<no_z;f++)
+ {
col[f]=GetCol(64,64,255-((no_z-f-1)*2));
+ }
p=Grab(sizeof(Sphere3D)*no);
w=Grab(sizeof(WorldObj)*no);
@@ -2432,7 +2574,7 @@ static void FluidDemo(void)
c=0;
for(f=0;f<no;f++)
- {
+ {
w[f].p=p+f;
w[f].type=eSphere;
@@ -2448,17 +2590,17 @@ static void FluidDemo(void)
a+=20;
if (((f+1)%no_x)==0)
- {
+ {
x=-(no_x/2)*gap;
z-=gap;
c++;
- }
}
+ }
DrawList(w,no,col,False,True);
init=TRUE;
- }
+ }
Cls();
@@ -2466,16 +2608,16 @@ static void FluidDemo(void)
a2=ang;
for(f=0;f<no;f++)
- {
+ {
p[f].origin.y=y_base+(sintab[a]+costab[a])*y_range;
a=(a+60)%3600;
if (((f+1)%no_x)==0)
- {
+ {
a2=(a2+60)%3600;
a=a2;
- }
}
+ }
ang=(ang+60)%3600;
@@ -2484,7 +2626,7 @@ static void FluidDemo(void)
/* ---------------------------------------- PARTICLE DROP DEMO
-*/
+ */
static void ParticleDropDemo(void)
{
static const int gap=30;
@@ -2521,13 +2663,15 @@ static void ParticleDropDemo(void)
int f,a,a2;
if (!init)
- {
+ {
int x,z,c;
col=Grab(sizeof(*col)*no_z);
for(f=0;f<no_z;f++)
+ {
col[f]=GetCol(64,64,255-((no_z-f-1)*4));
+ }
p=Grab(sizeof(Sphere3D)*no);
w=Grab(sizeof(WorldObj)*(no+1));
@@ -2538,7 +2682,7 @@ static void ParticleDropDemo(void)
c=0;
for(f=0;f<no;f++)
- {
+ {
w[f].p=p+f;
w[f].type=eSphere;
@@ -2554,13 +2698,13 @@ static void ParticleDropDemo(void)
a+=20;
if (((f+1)%no_x)==0)
- {
+ {
max_x=x;
x=-(no_x/2)*gap;
z-=gap;
c++;
- }
}
+ }
min_z=z;
@@ -2580,14 +2724,14 @@ static void ParticleDropDemo(void)
drop.mode=MODE_SOLID;
init=TRUE;
- }
+ }
Cls();
drop.origin.y+=drop_speed;
if (drop.origin.y>y_base)
- {
+ {
amp=init_amp;
ang=0;
dist=1;
@@ -2596,50 +2740,56 @@ static void ParticleDropDemo(void)
drop.origin.x=RND2(max_x,min_x);
drop.origin.z=RND2(max_z,min_z);
drop.origin.y=drop_y;
- }
+ }
if (amp>0.0)
- {
+ {
int a;
if (ang<0)
+ {
ang+=3600;
+ }
a=ang;
for(f=0;f<no;f++)
- {
+ {
double d;
double y;
d=Distance(&ctr,&p[f].origin)/gap;
if (d<3.0)
- d=3.0;
+ d=3.0;
if (d<dist)
- {
+ {
y=amp/(d/amp_dropoff);
a=(int)(ang+(d/ang_dropoff))%3600;
-
+
p[f].origin.y=y_base+y*sintab[a];
- }
}
+ }
amp-=amp_decay;
ang-=200;
dist++;
- }
+ }
else
+ {
for(f=0;f<no;f++)
+ {
p[f].origin.y=y_base;
+ }
+ }
DrawList(w,no+1,col,False,True);
}
/* ---------------------------------------- POLY DROP DEMO
-*/
+ */
static void PolyDropDemo(void)
{
static const int gap=30;
@@ -2671,7 +2821,7 @@ static void PolyDropDemo(void)
static Sphere3D drop;
static Obj3D obj=
- {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_EDGE,-1,True};
+ {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_EDGE,-1,True};
static WorldObj w[2];
@@ -2686,13 +2836,15 @@ static void PolyDropDemo(void)
int f,r;
if (!init)
- {
+ {
int x,z,c;
col=Grab(sizeof(*col)*no_z);
for(f=0;f<no_z;f++)
+ {
col[f]=GetCol(64,64,255-((no_z-f-1)*4));
+ }
no_poly=(no_z-1)*(no_x-1);
@@ -2718,7 +2870,7 @@ static void PolyDropDemo(void)
max_z=z=(no_z)*gap+z_off;
for(f=0;f<no;f++)
- {
+ {
pt[f].x=x;
pt[f].y=y_base;
pt[f].z=z;
@@ -2726,13 +2878,13 @@ static void PolyDropDemo(void)
x+=gap;
if (((f+1)%no_x)==0)
- {
+ {
max_x=x;
x=-(no_x/2)*gap;
z-=gap;
c++;
- }
}
+ }
min_z=z;
@@ -2752,7 +2904,7 @@ static void PolyDropDemo(void)
r=0;
for(f=0,r=0;f<no_poly;f++,r++)
- {
+ {
poly[f].col=c;
poly[f].no=4;
@@ -2762,21 +2914,21 @@ static void PolyDropDemo(void)
poly[f].p[3]=r+no_x;
if (((f+1)%(no_x-1))==0)
- {
+ {
c++;
r++;
- }
}
+ }
init=TRUE;
- }
+ }
Cls();
drop.origin.y+=drop_speed;
if (drop.origin.y>y_base)
- {
+ {
amp=init_amp;
ang=0;
dist=1;
@@ -2785,50 +2937,58 @@ static void PolyDropDemo(void)
drop.origin.x=RND2(max_x,min_x);
drop.origin.z=RND2(max_z,min_z);
drop.origin.y=drop_y;
- }
+ }
if (amp>0.0)
- {
+ {
int a;
if (ang<0)
+ {
ang+=3600;
+ }
a=ang;
for(f=0;f<no;f++)
- {
+ {
double d;
double y;
d=Distance(&ctr,&pt[f])/gap;
if (d<2.0)
- d=2.0;
+ {
+ d=2.0;
+ }
if (d<dist)
- {
+ {
y=amp/(d/amp_dropoff);
a=(int)(ang+(d/ang_dropoff))%3600;
-
+
pt[f].y=y_base+y*sintab[a];
- }
}
+ }
amp-=amp_decay;
ang-=200;
dist++;
- }
+ }
else
+ {
for(f=0;f<no;f++)
+ {
pt[f].y=y_base;
+ }
+ }
DrawList(w,2,col,False,False);
}
/* ---------------------------------------- CRATER DEMO
-*/
+ */
static void CraterDemo(void)
{
static const int gap=30;
@@ -2862,7 +3022,7 @@ static void CraterDemo(void)
static Sphere3D drop;
static Obj3D obj=
- {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_SOLID,-1,True};
+ {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_SOLID,-1,True};
static WorldObj w[2];
@@ -2876,7 +3036,7 @@ static void CraterDemo(void)
int f,r;
if (!init)
- {
+ {
int x,z,c;
col=Grab(sizeof(*col)*no_z);
@@ -2886,7 +3046,9 @@ static void CraterDemo(void)
initp.z=z_off+(no_z*gap)/2;
for(f=0;f<no_z;f++)
+ {
col[f]=GetCol(64,64,255-((no_z-f-1)*3));
+ }
no_poly=(no_z-1)*(no_x-1)*2;
@@ -2900,7 +3062,7 @@ static void CraterDemo(void)
max_z=z=(no_z/2)*gap;
for(f=0;f<no;f++)
- {
+ {
pt[f].x=x;
pt[f].y=0;
pt[f].z=z;
@@ -2908,13 +3070,13 @@ static void CraterDemo(void)
x+=gap;
if (((f+1)%no_x)==0)
- {
+ {
max_x=x;
x=-(no_x/2)*gap;
z-=gap;
c++;
- }
}
+ }
min_z=z;
@@ -2935,7 +3097,7 @@ static void CraterDemo(void)
r=0;
for(f=0,r=0;f<no_poly;f+=2,r++)
- {
+ {
poly[f].col=c;
poly[f].no=3;
@@ -2951,11 +3113,11 @@ static void CraterDemo(void)
poly[f+1].p[2]=r+no_x;
if (((f+2)%(no_x-1))==0)
- {
+ {
r++;
c=(c+1)%no_z;
- }
}
+ }
obj.origin=initp;
obj.no_points=no;
@@ -2972,61 +3134,65 @@ static void CraterDemo(void)
w[1].type=eSphere;
init=TRUE;
- }
+ }
if (mouse_b&Button1Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
view=!view;
if (!view)
- {
+ {
obj.origin=initp;
obj.x_rot=0;
obj.y_rot=0;
obj.z_rot=0;
- }
+ }
else
- obj.origin.z+=800;
+ {
+ obj.origin.z+=800;
+ }
bounce=time(NULL);
- }
}
+ }
if (mouse_b&Button3Mask)
- {
+ {
static time_t bounce=0;
if (bounce!=time(NULL))
- {
+ {
obj.mode++;
if (obj.mode>MODE_EDGE)
- obj.mode=MODE_SOLID;
+ {
+ obj.mode=MODE_SOLID;
+ }
bounce=time(NULL);
- }
}
+ }
Cls();
if (view)
- {
+ {
obj.x_rot=MAX(2700,MIN(3599,2700+mouse_y*3));
obj.y_rot=(centre_x-mouse_x)*3;
obj.y_rot=MAX(-900,MIN(obj.y_rot,900));
- }
+ }
else
- {
+ {
drop.origin.y+=drop_speed*speed;
speed+=0.1;
if (drop.origin.y>y_base)
- {
+ {
int a;
speed=1.0;
@@ -3038,7 +3204,7 @@ static void CraterDemo(void)
drop.origin.y=drop_y;
for(f=0;f<no;f++)
- {
+ {
Point3D p;
double d;
double y;
@@ -3051,34 +3217,36 @@ static void CraterDemo(void)
d=Distance(&ctr,&p)/gap;
if (d<1.0)
+ {
d=1.0;
+ }
if (d<max_dist)
- {
+ {
y=y_range;
a=(int)(900+(d/ang_dropoff))%3600;
-
+
pt[f].y+=y*sintab[a];
- }
}
}
}
+ }
if (view)
- {
+ {
DrawObj(&obj,col);
Print(0,0,white,"Viewing mode (LMB to end)");
- }
+ }
else
- {
+ {
DrawList(w,2,col,False,False);
DrawSubList(NULL,0,&drop,1,NULL,0,NULL,0,col,FALSE,FALSE);
- }
+ }
}
/* ---------------------------------------- TRIANGLE DEMO
-*/
+ */
static void TriangleDemo(void)
{
static const int gap=100;
@@ -3107,7 +3275,7 @@ static void TriangleDemo(void)
static Point3D initp;
static Obj3D obj=
- {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_EDGE,-1,True};
+ {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_EDGE,-1,True};
static Point3D ctr;
@@ -3120,7 +3288,7 @@ static void TriangleDemo(void)
int f,r;
if (!init)
- {
+ {
int x,z,c;
col=Grab(sizeof *col * no_col);
@@ -3130,10 +3298,12 @@ static void TriangleDemo(void)
initp.z=z_off+(no_z*gap)/2;
for(f=0;f<no_col;f++)
- {
- int i=255-f;
+ {
+ int i;
+
+ i=255-f;
col[f]=GetCol(i,i,i);
- }
+ }
no_poly=(no_z-1)*(no_x-1)*2;
@@ -3147,27 +3317,31 @@ static void TriangleDemo(void)
max_z=z=(no_z/2)*gap;
for(f=0;f<no;f++)
- {
+ {
int m=f%no_x;
pt[f].x=x;
pt[f].z=z;
if (m==0 || m==no_x-1)
+ {
pt[f].y=y_wall;
+ }
else
+ {
pt[f].y=sintab[RND(3600)]*y_range;
+ }
x+=gap;
if (((f+1)%no_x)==0)
- {
+ {
max_x=x;
x=min_x;
z-=gap;
c++;
- }
}
+ }
min_z=z;
@@ -3179,7 +3353,7 @@ static void TriangleDemo(void)
r=0;
for(f=0,r=0;f<no_poly;f+=2,r++)
- {
+ {
poly[f].col=0;
poly[f].no=3;
@@ -3195,11 +3369,11 @@ static void TriangleDemo(void)
poly[f+1].p[2]=r+no_x;
if (((f+2)%(no_x-1))==0)
- {
+ {
r++;
c++;
- }
}
+ }
obj.origin=initp;
obj.no_points=no;
@@ -3210,7 +3384,7 @@ static void TriangleDemo(void)
obj.workxp=Grab(sizeof(XPoint)*no);
init=TRUE;
- }
+ }
Cls();
DrawObj(&obj,col);
@@ -3220,25 +3394,33 @@ static void TriangleDemo(void)
move+=speed;
while (move>=gap)
- {
+ {
for(f=no-1;f>=no_x;f--)
+ {
pt[f].y=pt[f-no_x].y;
+ }
for(f=0;f<no_x;f++)
+ {
if (f==0 || f==no_x-1)
+ {
pt[f].y=y_wall;
+ }
else
+ {
pt[f].y=sintab[RND(3600)]*y_range;
+ }
+ }
move-=gap;
- }
+ }
obj.origin.z=initp.z-move;
}
/* ---------------------------------------- TRIANGLE DEMO
-*/
+ */
static void TriangleDemo2(void)
{
static const int gap=100;
@@ -3267,7 +3449,7 @@ static void TriangleDemo2(void)
static Point3D initp;
static Obj3D obj=
- {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_EDGE,-1,True};
+ {0,0,{0,0,0},NULL,NULL,NULL,NULL,0,0,0,MODE_EDGE,-1,True};
static Point3D ctr;
@@ -3282,7 +3464,7 @@ static void TriangleDemo2(void)
int newa;
if (!init)
- {
+ {
int x,z,c;
col=Grab(sizeof *col * no_col);
@@ -3292,10 +3474,12 @@ static void TriangleDemo2(void)
initp.z=z_off+(no_z*gap)/2;
for(f=0;f<no_col;f++)
- {
- int i=255-f*200;
+ {
+ int i;
+
+ i=255-f*200;
col[f]=GetCol(i/2,i,i/2);
- }
+ }
no_poly=(no_z-1)*(no_x-1)*2;
@@ -3309,7 +3493,7 @@ static void TriangleDemo2(void)
max_z=z=(no_z/2)*gap;
for(f=0;f<no;f++)
- {
+ {
int m=f%no_x;
pt[f].x=x;
@@ -3318,12 +3502,14 @@ static void TriangleDemo2(void)
pt[f].y=sintab[ang]*y_range;
if (m==0 || m==no_x-1)
+ {
pt[f].y+=y_wall;
+ }
x+=gap;
if (((f+1)%no_x)==0)
- {
+ {
max_x=x;
x=min_x;
z-=gap;
@@ -3332,14 +3518,14 @@ static void TriangleDemo2(void)
newa=(ang+angi)%3600;
if (newa<ang)
- {
+ {
angi=RND2(450,100);
- }
+ }
ang=newa;
- }
}
+ }
min_z=z;
@@ -3352,7 +3538,7 @@ static void TriangleDemo2(void)
c=0;
for(f=0,r=0;f<no_poly;f+=2,r++)
- {
+ {
poly[f].col=c;
poly[f].no=3;
@@ -3372,10 +3558,10 @@ static void TriangleDemo2(void)
c=(c+1)%no_col;
if (((f+2)%(no_x-1))==0)
- {
+ {
r++;
- }
}
+ }
obj.origin=initp;
obj.no_points=no;
@@ -3386,7 +3572,7 @@ static void TriangleDemo2(void)
obj.workxp=Grab(sizeof(XPoint)*no);
init=TRUE;
- }
+ }
Cls();
DrawObj(&obj,col);
@@ -3394,29 +3580,33 @@ static void TriangleDemo2(void)
newa=(ang+angi)%3600;
if (newa<ang)
- {
+ {
angi=RND2(450,100);
- }
+ }
ang=newa;
move+=speed;
while (move>=gap)
- {
+ {
for(f=no-1;f>=no_x;f--)
+ {
pt[f].y=pt[f-no_x].y;
+ }
for(f=0;f<no_x;f++)
- {
+ {
pt[f].y=sintab[ang]*y_range;
if (f==0 || f==no_x-1)
+ {
pt[f].y+=y_wall;
}
+ }
move-=gap;
- }
+ }
obj.origin.z=initp.z-move;
}