home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Assembly 1994 - The 3rd Phase
/
ASMROM94.mdf
/
sources
/
cube216c.txt
< prev
next >
Wrap
Text File
|
1994-11-12
|
4KB
|
128 lines
/* (C) Mikko Tommila 1989 */
/* Written in Turbo C 2.0 (C) Borland, Inc.*/
/* Link this with a VGA256.OBJ file if you haven't included it in your Graphics.Lib */
/*VGA256.BGI (C) Borland, Inc.*/
#include <graphics.h>
#include <math.h>
#include <stdio.h>
void move(float m, float *b, float *c);
void cdecl VGA256_driver(void);
void swap(int *m1,int *m2);
main()
{
int grdrv; /*graphichs driver*/
int grmode; /*& -mode*/
int xr, yr;
int nn, ap, bp, r[216];
float xp, yp;
int n1, n2, n3; /*something*/
float xf;
float xm, ym, zm; /*momentum on x, y & z circles*/
typedef struct {
float z;
float y;
float x;
} coordinate;
coordinate cor[216];
int co[216];
/*some info*/
puts("To acquire rotation on image:\n");
puts("E D around x-axis");
puts("A S around y-axis");
puts("Q W around z-axis\n\n");
puts("ESC exits !\n\n");
puts("Press any key");
do {delay(1);} while(!kbhit());
installuserdriver("VGA256",0);
registerbgidriver(VGA256_driver);
grdrv=11;
grmode=0;
/*set graphics mode*/
initgraph(&grdrv, &grmode, "");
getaspectratio(&xr,&yr);
xf=xr;
xf=xf/10000;
for(n1=0;n1<6;n1++) {
for (n2=0;n2<6;n2++) {
for (n3=0;n3<6;n3++) {
nn=n3+6*n2+36*n1;
cor[nn].x=10*n1-25;
cor[nn].y=10*n2-25;
cor[nn].z=10*n3-25;
co[nn]=nn+16;
r[nn]=nn;
setrgbpalette(nn+16,10*n1+4,10*n2+4,10*n3+4);
}
}
}
nn=216;
/* main turning routine */
xm=0; ym=0; zm=0;
do {
if (kbhit()) {
switch (toupper(getch())){
case 'D':xm-=1;break;
case 'E':xm+=1;break;
case 'A':ym-=1;break;
case 'S':ym+=1;break;
case 'W':zm-=1;break;
case 'Q':zm+=1;break;
case 27:closegraph();exit(0);
}
}
for(ap=0; ap<nn; ap++)
{
move(xm,&cor[ap].y,&cor[ap].z);
move(ym,&cor[ap].z,&cor[ap].x);
move(zm,&cor[ap].y,&cor[ap].x);
}
for(ap=0; ap<nn; ap++)
{
for(bp=ap+1; bp<nn; bp++) { if(cor[r[bp]].z < cor[r[ap]].z) swap(&r[ap],&r[bp]); }
}
cleardevice();
for(ap=0; ap<nn; ap++)
{
bp=r[ap];
setcolor(co[bp]);
setfillstyle(1,co[bp]);
xp=cor[bp].x;
yp=cor[bp].y;
xp=xp+(xp*cor[bp].z/200);
yp=yp+(yp*cor[bp].z/200);
xp=xp+160;
yp=yp*xf+100;
fillellipse(xp,yp,3,3);
}
} while (1==1);
}
/*routine that changes the x, y & z coordinates*/
void move(float m, float *b, float *c)
{
float d=hypot(*b,*c);
float l=0;
if (*b !=0) l=atan(*c/ *b);
if (*b<0) l+=3.14159265;
l+=6.283185+m/100;
if(l>6.283185) l-=6.283185;
*c=sin(l)* d;
*b=cos(l)* d;
}
void swap(int *m1,int *m2)
{
int tmp;
tmp=*m1;
*m1=*m2;
*m2=tmp;
}