i have the following code but i can not make the color work.
where is the problem?
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <dos.h>
#include <bios.h>
#include <ctype.h>
float xw[8],yw[8],zw[8];
float xe[8],ye[8],ze[8];
int MR[12][2]={{0,1},{1,2},{2,3},{3,0}, {4,5},{5,6},{6,7},{7,4}, {0,4},{3,5},{2,6},{1,7} }; // ¬ ббЁў ॡҐа
int pg[6],pr[12];
int x[8], y[8]; // ¬ ббЁўл ¤«п нЄа ле Є®®а¤Ё в ЄгЎ
int MGrV[4][3]={{0,1,3},{1,2,3},{0,3,2}, // ¬ ббЁў Ја Ґ© Ї® ўҐаиЁ ¬
{0,2,1}};
int MGrR[4][3]={{0,1,2},{2,3,4},{0,5,4}, // ¬ ббЁў Ја Ґ© Ї® аҐЎа ¬
{1,3,5}};
double Xw1,Yw1,Zw1,Xw2,Yw2,Zw2;
double X1e,Y1e,Z1e,X2e,Y2e,Z2e;
double X1,Y1,X2,Y2;
int x1, y1, color, color2;
float fi, teta, tet, phi, tet2, phi2, dl, alpha;
double k;
float f=0, t=90;
int d=300, ro=550, a=100;
int gr=1, page=1;
char str[20];
int i;
float AL,temp,tempx,tempy,v1,v2,xc,yc,tev,fiv,l,L;
void drawCUBE(int color,int color1);
double input(int x1, int y1);
void povorotres();
void perenos(int a1, int a2,int a3);
void init()
{int x0[8]={-a/2, -a/2, a/2, a/2, -a/2 , a/2, a/2,-a/2},
y0[8]={-a/2, a/2, a/2, -a/2, -a/2 ,-a/2, a/2, a/2},
z0[8]={-a/2, -a/2, -a/2,-a/2, a/2 , a/2, a/2, a/2};
for(i=0;i<8;i++)
{
xw[i]=x0[i];
yw[i]=y0[i];
zw[i]=z0[i];
}
}
//---------------”гЄжЁп ¤«п ®ЇаҐ¤Ґ«ҐЁп ўЁ¤®ўле Є®®а¤Ё в ЄгЎ --------------
void vidpr(int i)
{
xe[i]=-xw[i]*sin(teta)+yw[i]*cos(teta);
ye[i]=-xw[i]*cos(fi)*cos(teta)-yw[i]*cos(fi)*sin(teta)+zw[i]*sin(fi);
ze[i]=-xw[i]*sin(fi)*cos(teta)-yw[i]*sin(fi)*sin(teta)-zw[i]*cos(fi)+ro;
}
//---------------”гЄжЁп ¤«п а бзҐв нЄа ле Є®®а¤Ё в ЄгЎ -----------------
void proectetr(int i)
{
x[i]=xe[i]/ze[i]*d+xc;
y[i]=ye[i]/ze[i]*d+yc;
}
/*
void zapolnenie(int color)
{
int i1,j2,j1,rab,rab2,n,a,b,c,rt;
struct { int ygr;
int dy;
float x;
float dx;
} SR[4], SAR[4],tmp;
for (n=0;n<4;n++)
{
if (pg [n]!=0)
{
for (int i=0;i<3;i++)
{
SR[i].ygr=0;
SR[i].dy=0;
SR[i].x=0;
SR[i].dx=0;
SAR[i]=SR[i];
}
for (int j=0,rab=0;j<3;j++)
{
a=MGrR[n][j];
b=MR[a][0];
c=MR[a][1];
if(y[b]!=y[c])
{
if (y[b]<y[c])
{a = c; c=b; b=a;}
SR[rab].ygr=y[b];
SR[rab].dy=y[b]-y[c];
SR[rab].x=float(x[b]);
SR[rab].dx=float(x[b]-x[c])/float(y[c]-y[b]);
rab++;
}
SAR[j].dy=0;
}
a=SR[0].ygr;
for(i1=1;i1<rab;i1++)
if (SR[i1].ygr>a)
a=SR[i1].ygr;
for (j2=0,rab2=0;j2<rab;j2++)
if (SR[j2].ygr==a)
SAR[rab2++]=SR[j2];
setcolor(color);
while (rab2!=0)
{
for (i=0;i<rab2;i++)
for (j=0;j<rab2-i;j++)
if (((SAR[j].x>SAR[j+1].x)&&(SAR[j+1].dy!=0))||(SAR[j].dy==0))
{
tmp=SAR[j];
SAR[j]=SAR[j+1];
SAR[j+1]=tmp;
}
for(j=0;j<rab2;j+=2)
{
for(int x=SAR[j].x;x<SAR[j+1].x;x++)
putpixel(x,a,color);
}
rt=rab2;
for (j2=0;j2<rt;j2++)
{
SAR[j2].dy--;
SAR[j2].ygr--;
SAR[j2].x+=SAR[j2].dx;
if (SAR[j2].dy==0)
rab2--;
}
a--;
for(j2=0;j2<rab;j2++)
if (SR[j2].ygr==a)
for (j=0;j<4;j++)
if (SAR[j].dy==0)
{
SAR[j]=SR[j2];
rab2++;
break;
}
}
}
}}
*/
//----------------------поворот вокруг прямой, параллельной оси Z--------------
void povorotZ()
{
for (i=0;i<8;i++)
{
temp=xw[i];
xw[i]=xw[i]*cos(AL)-yw[i]*sin(AL);
yw[i]=temp*sin(AL)+yw[i]*cos(AL);
}
}
//поворот вокруг прямой, параллельной оси Y
void povorotY()
{
for (i=0;i<8;i++)
{
temp=xw[i];
xw[i]=xw[i]*cos(AL)-zw[i]*sin(AL);
zw[i]=temp*sin(AL)+zw[i]*cos(AL);
}
}
//----------------------поворот вокруг прямой, параллельной оси X-------------------------
void povorotX()
{
for(i=0;i<8;i++)
{
temp=yw[i];
yw[i]=yw[i]*cos(AL)-zw[i]*sin(AL);
zw[i]=temp*sin(AL)+zw[i]*cos(AL);
}
}
void PovorotCentrMass ()
{
povorotZ();
povorotX();
povorotY();
}
void vrashenieCentr()
{
M:
int c=0;
int xx[4],yy[4],zz[4];
setcolor(9);
/*
outtextxy(205,235,"Vvedite koordinati nachalnoi tochki vectora:");
outtextxy(208,250,"x1="); setlinestyle(0,0,3);
Xw1=input(230,250);
outtextxy(293,250,"y1=");
Yw1=input(315,250);
outtextxy(378,250,"z1=");
Zw1=input(400,250);
outtextxy(205,285,"Vvedite koordinati konechnoi tochki vectora:");
outtextxy(208,310,"x2=");
Xw2=input(230,310);
outtextxy(293,310,"y2=");
Yw2=input(315,310);
outtextxy(378,310,"z2=");
Zw2=input(400,310);
*/
char *fistr, *tetastr,*dstr,*rostr;
fi=(atan(1)/45.0)*f;
teta=(atan(1)/45.0)*t;
//dl=sqrt(pow((Xw2-Xw1),2)+pow((Yw2-Yw1),2)+pow((Zw2-Zw1),2));
/*
if(dl==0)
{ setcolor(0);
outtextxy(205,235,"Vvedite koordinati nachalnoi tochki vectora:");
bar(204,244,446,266);
outtextxy(205,285,"Vvedite koordinati konechnoi tochki vectora:");
bar(204,304,446,326);
setcolor(RED);
outtextxy(3,305,"Dlina vectora =0, vvedite koordinati vectora zanovo!");
getch(); setcolor(0);
outtextxy(3,305,"Dlina vectora =0, vvedite koordinati vectora zanovo!");
goto M;
}
tev=acos((Xw2-Xw1)/(sqrt((Xw2-Xw1)*(Xw2-Xw1)+(Yw2-Yw1)*(Yw2-Yw1))));
fiv=acos((Zw2-Zw1)/dl);
*/
xc=435; yc=100;
init();
do
{ settextstyle(0,0,1); setlinestyle(0,0,0);
setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
setcolor(9);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
setlinestyle(0,0,3);
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,fistr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetastr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setlinestyle(0,0,0);
setcolor(7);
//vector(Xw1,Yw1,Zw1,Xw2,Yw2,Zw2);
drawCUBE(0,0);
init();
drawCUBE(9,7);
AL=(atan(1)/45.0)*gr;
perenos(-Xw1,-Yw1,-Zw1);
PovorotCentrMass();
//povorotres();
drawCUBE(9,7);
for (int i=0;i<8;i++)
{ xx[i]=xw[i]; yy[i]=yw[i]; zz[i]=zw[i]; }
if (kbhit())
{ c=getch();
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setcolor(4);
init();
//vector(Xw1,Yw1,Zw1,Xw2,Yw2,Zw2);
for(int i=0;i<8;i++)
{ xw[i]=xx[i]; yw[i]=yy[i]; zw[i]=zz[i]; }
drawCUBE(9,7);
outtextxy(30,235,itoa(fi*180/3.14,fistr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetastr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
gr++;
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
else
{ gr++;
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
}
while(c!=113);
d=300;ro=550;
}
void drawCUBE(int color,int color1)
{
for(int i=0;i<8;i++)
{
vidpr(i);
proectetr(i);
}
int v1,v2,f1,f2,f3,dx1,dx2,dy1,dy2;
for(i=0;i<12;i++)
pr[i]=0;
/*
for(i=0;i<8;i++)
{
pg[i]=0;
f1=MGrV[i][0];
f2=MGrV[i][1];
f3=MGrV[i][2];
dx1=x[f2]-x[f1];
dx2=x[f3]-x[f2];
dy1=y[f2]-y[f1];
dy2=y[f3]-y[f2];
if((dx1*dy2-dx2*dy1)<0)
pg[i]=1;
}
for(i=0;i<5;i++)
if(pg[i]==1)
for(int j=i+1;j<6;j++)
if(pg[j]==1)
for(int i1=0;i1<4;i1++)
for(int j1=0;j1<4;j1++)
if(MGrR[i][i1]==MGrR[j][j1])
{
f1=MGrR[i][i1];
pr[f1]=1;
}
*/
//zapolnenie (color1);
for(i=0;i<12;i++)
{
if(pr[i]==0)
{
v1=MR[i][0];
v2=MR[i][1];
setcolor(color);
line(x[v1],y[v1],x[v2],y[v2]);
}
}
}
void vector(float Xw1,float Yw1,float Zw1, float Xw2,float Yw2,float Zw2)
{ X1e=-Xw1*sin(teta)+Yw1*cos(teta);
Y1e=-Xw1*cos(fi)*cos(teta)-Yw1*cos(fi)*sin(teta)+Zw1*sin(fi);
Z1e=-Xw1*sin(fi)*cos(teta)-Yw1*sin(fi)*sin(teta)-Zw1*cos(fi)+ro;
X2e=-Xw2*sin(teta)+Yw2*cos(teta);
Y2e=-Xw2*cos(fi)*cos(teta)-Yw2*cos(fi)*sin(teta)+Zw2*sin(fi);
Z2e=-Xw2*sin(fi)*cos(teta)-Yw2*sin(fi)*sin(teta)-Zw2*cos(fi)+ro;
X1=(X1e/Z1e)*d+xc; Y1=(Y1e/Z1e)*d+yc;
X2=(X2e/Z2e)*d+xc; Y2=(Y2e/Z2e)*d+yc;
line(X1,Y1,X2,Y2);
}
void perenos(int a1, int a2,int a3)
{ for(int i=0;i<8;i++)
{ xw[i]=xw[i]-a1; yw[i]=yw[i]-a2; zw[i]=zw[i]-a3; }
}
void povorotres()
{
for(i=0;i<8;i++)
{tempx=xw[i];
tempy=yw[i];
xw[i]=xw[i]*(cos(tev)*cos(tev)*cos(fiv)*cos(fiv)*cos(AL)+sin(tev)*sin(AL)*cos(fiv)*cos(tev)+cos(tev)*cos(tev)*sin(fiv)*sin(fiv)-cos(tev)*cos(fiv)*sin(AL)*sin(tev)+sin(tev)*sin(tev)*cos(AL))+yw[i]*(sin(tev)*cos(fiv)*cos(fiv)*cos(AL)*cos(tev)-cos(tev)*cos(tev)*sin(AL)*cos(fiv)+sin(tev)*sin(fiv)*sin(fiv)*cos(tev)-sin(tev)*sin(tev)*cos(fiv)*sin(AL)-cos(tev)*cos(AL)*sin(tev))+zw[i]*(-sin(fiv)*cos(AL)*cos(fiv)*cos(tev)+cos(fiv)*sin(fiv)*cos(tev)+sin(fiv)*sin(AL)*sin(tev))-Xw1*(cos(tev)*cos(tev)*cos(fiv)*cos(fiv)*cos(AL)+sin(tev)*sin(AL)*cos(fiv)*cos(tev)+cos(tev)*cos(tev)*sin(fiv)*sin(fiv)-cos(tev)*cos(fiv)*sin(AL)*sin(tev)+sin(tev)*sin(tev)*cos(AL))-Yw1*(sin(tev)*cos(fiv)*cos(fiv)*cos(AL)*cos(tev)-cos(tev)*cos(tev)*sin(AL)*cos(fiv)+sin(tev)*sin(fiv)*sin(fiv)*cos(tev)-sin(tev)*sin(tev)*cos(fiv)*sin(AL)-cos(tev)*cos(AL)*sin(tev))-Zw1*(-sin(fiv)*cos(AL)*cos(fiv)*cos(tev)+cos(fiv)*sin(fiv)*cos(tev)+sin(fiv)*sin(AL)*sin(tev))+Xw1;
yw[i]=tempx*(cos(tev)*cos(fiv)*cos(fiv)*cos(AL)*sin(tev)+sin(tev)*sin(tev)*sin(AL)*cos(fiv)+cos(tev)*sin(fiv)*sin(fiv)*sin(tev)+cos(tev)*cos(tev)*cos(fiv)*sin(AL)-sin(tev)*cos(AL)*cos(tev))+yw[i]*(sin(tev)*sin(tev)*cos(fiv)*cos(fiv)*cos(AL)-cos(tev)*sin(AL)*cos(fiv)*sin(tev)+sin(tev)*sin(tev)*sin(fiv)*sin(fiv)+sin(tev)*cos(fiv)*sin(AL)*cos(tev)+cos(tev)*cos(AL)*cos(tev))+zw[i]*(-sin(fiv)*cos(AL)*cos(fiv)*sin(tev)+cos(fiv)*sin(fiv)*sin(tev)-sin(fiv)*sin(AL)*cos(tev))-Xw1*(cos(tev)*cos(fiv)*cos(fiv)*cos(AL)*sin(tev)+sin(tev)*sin(tev)*sin(AL)*cos(fiv)+cos(tev)*sin(fiv)*sin(fiv)*sin(tev)+cos(tev)*cos(tev)*cos(fiv)*sin(AL)-sin(tev)*cos(AL)*cos(tev))-Yw1*(sin(tev)*sin(tev)*cos(fiv)*cos(fiv)*cos(AL)-cos(tev)*sin(AL)*cos(fiv)*sin(tev)+sin(tev)*sin(tev)*sin(fiv)*sin(fiv)+sin(tev)*cos(fiv)*sin(AL)*cos(tev)+cos(tev)*cos(AL)*cos(tev))-Zw1*(-sin(fiv)*cos(AL)*cos(fiv)*sin(tev)+cos(fiv)*sin(fiv)*sin(tev)-sin(fiv)*sin(AL)*cos(tev))+Yw1;
zw[i]=tempx*(-cos(tev)*cos(fiv)*cos(AL)*sin(fiv)-sin(tev)*sin(AL)*sin(fiv)+cos(tev)*sin(fiv)*cos(fiv))+tempy*(-sin(tev)*cos(fiv)*cos(AL)*sin(fiv)+cos(tev)*sin(AL)*sin(fiv)+sin(tev)*sin(fiv)*cos(fiv))+zw[i]*(sin(fiv)*sin(fiv)*cos(AL)+cos(fiv)*cos(fiv))-Xw1*(-cos(tev)*cos(fiv)*cos(AL)*sin(fiv)-sin(tev)*sin(AL)*sin(fiv)+cos(tev)*sin(fiv)*cos(fiv))-Yw1*(-sin(tev)*cos(fiv)*cos(AL)*sin(fiv)+cos(tev)*sin(AL)*sin(fiv)+sin(tev)*sin(fiv)*cos(fiv))-Zw1*(sin(fiv)*sin(fiv)*cos(AL)+cos(fiv)*cos(fiv))+Zw1;
}
}
double input(int x1, int y1)
{ union { char hh[2]; int ii; } cc;
setcolor(9);
int i=0;
double var=-1;
char str[5];
int ofs=0;
do
{
do
{
if(i==4) return var;
setfillstyle(1,7);
bar(x1+ofs,y1+9,x1+10+ofs,y1+10); delay(170);
setfillstyle(1,0);
bar(x1+ofs,y1+9,x1+10+ofs,y1+10); delay(170);
}
while(bioskey(1)==0);
cc.ii=bioskey(0);
if (int(cc.hh[0])==13)
{ setfillstyle(1,0);
bar(x1+ofs,y1+9,x1+10+ofs,y1+10);
return var;
}
if(int(cc.hh[0]==45))
{ cc.hh[1]='\0';
bar(x1+ofs,y1+9,x1+10+ofs,y1+10); outtextxy(x1+ofs+1,y1,cc.hh);
str[i]=cc.hh[0]; str[i+1]='\0';
var=atof(str);
i++; ofs+=8;
}
if(int(cc.hh[0]==46))
{ cc.hh[1]='\0';
bar(x1+ofs,y1+9,x1+10+ofs,y1+10); outtextxy(x1+ofs+1,y1,cc.hh);
str[i]=cc.hh[0]; str[i+1]='\0';
var=atof(str);
i++; ofs+=8;
}
if(isdigit(int(cc.hh[0])))
{
cc.hh[1]='\0';
setfillstyle(1,0);
bar(x1+ofs,y1+9,x1+10+ofs,y1+10); outtextxy(x1+ofs+1,y1,cc.hh);
str[i]=cc.hh[0]; str[i+1]='\0';
var=atof(str);
i++; ofs+=8;
}
}
while(1);
}
void vrashenie()
{
M:
int c=0;
int xx[4],yy[4],zz[4];
setcolor(9);
outtextxy(205,235,"Vvedite koordinati nachalnoi tochki vectora:");
outtextxy(208,250,"x1="); setlinestyle(0,0,3);
Xw1=input(230,250);
outtextxy(293,250,"y1=");
Yw1=input(315,250);
outtextxy(378,250,"z1=");
Zw1=input(400,250);
outtextxy(205,285,"Vvedite koordinati konechnoi tochki vectora:");
outtextxy(208,310,"x2=");
Xw2=input(230,310);
outtextxy(293,310,"y2=");
Yw2=input(315,310);
outtextxy(378,310,"z2=");
Zw2=input(400,310);
char *fistr, *tetastr,*dstr,*rostr;
fi=(atan(1)/45.0)*f;
teta=(atan(1)/45.0)*t;
dl=sqrt(pow((Xw2-Xw1),2)+pow((Yw2-Yw1),2)+pow((Zw2-Zw1),2));
if(dl==0)
{ setcolor(0);
outtextxy(205,235,"Vvedite koordinati nachalnoi tochki vectora:");
bar(204,244,446,266);
outtextxy(205,285,"Vvedite koordinati konechnoi tochki vectora:");
bar(204,304,446,326);
setcolor(RED);
outtextxy(3,305,"Dlina vectora =0, vvedite koordinati vectora zanovo!");
getch(); setcolor(0);
outtextxy(3,305,"Dlina vectora =0, vvedite koordinati vectora zanovo!");
goto M;
}
tev=acos((Xw2-Xw1)/(sqrt((Xw2-Xw1)*(Xw2-Xw1)+(Yw2-Yw1)*(Yw2-Yw1))));
fiv=acos((Zw2-Zw1)/dl);
xc=435; yc=100;
init();
do
{ settextstyle(0,0,1); setlinestyle(0,0,0);
setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
setcolor(9);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
setlinestyle(0,0,3);
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,fistr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetastr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setlinestyle(0,0,0);
setcolor(7);
vector(Xw1,Yw1,Zw1,Xw2,Yw2,Zw2);
drawCUBE(0,0);
init();
drawCUBE(9,7);
AL=(atan(1)/45.0)*gr;
perenos(-Xw1,-Yw1,-Zw1);
povorotres();
drawCUBE(9,7);
for (int i=0;i<8;i++)
{ xx[i]=xw[i]; yy[i]=yw[i]; zz[i]=zw[i]; }
if (kbhit())
{ c=getch();
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setcolor(4);
init();
vector(Xw1,Yw1,Zw1,Xw2,Yw2,Zw2);
for(int i=0;i<4;i++)
{ xw[i]=xx[i]; yw[i]=yy[i]; zw[i]=zz[i]; }
drawCUBE(9,7);
outtextxy(30,235,itoa(fi*180/3.14,fistr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetastr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
gr++;
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
else
{ gr++;
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
}
while(c!=113);
d=300;ro=550;
}
void dviwenie()
{
W:
setcolor(9);
outtextxy(205,225,"Vvedite koordinati nachalnoi tochki vectora:");
outtextxy(208,250,"x1=");
setlinestyle(0,0,3);
Xw1=input(230,250);
outtextxy(293,250,"y1=");
Yw1=input(315,250);
outtextxy(378,250,"z1=");
Zw1=input(400,250);
outtextxy(205,285,"Vvedite koordinati konechnoi tochki vectora:");
outtextxy(208,310,"x2=");
Xw2=input(230,310);
outtextxy(293,310,"y2=");
Yw2=input(315,310);
outtextxy(378,310,"z2=");
Zw2=input(400,310);
settextstyle(0,0,1); setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
int c=0;
char *phimstr,*tetamstr,*dstr,*rostr;
fi=(atan(1)/45.0)*f; teta=(atan(1)/45.0)*t;
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
xc=435; yc=100;
float xx[4],yy[4],zz[4];
float dlina=sqrt(pow((Xw2-Xw1),2)+pow((Yw2-Yw1),2)+pow((Zw2-Zw1),2));
if(dlina==0)
{ setcolor(0);
outtextxy(205,225,"Vvedite koordinati nachalnoi tochki vectora:");
bar(203,244,446,266);
outtextxy(205,285,"Vvedite koordinati konechnoi tochki vectora:");
bar(204,304,446,326);
setcolor(RED);
outtextxy(3,305,"Dlina vectora =0, vvedite koordinati vectora zanovo!");
getch(); setcolor(0);
outtextxy(3,305,"Dlina vectora =0, vvedite koordinati vectora zanovo!");
goto W;
}
float dt=0.01;
float t=0;
do
{ init();
setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
setcolor(9);
setlinestyle(0,0,0);
setcolor(6);
vector(Xw1,Yw1,Zw1,Xw2,Yw2,Zw2);
perenos(-Xw1,-Yw1,-Zw1);
drawCUBE(9,7);
for(int i=0; i<8;i++)
{ xw[i]=xw[i]+t*(Xw2-Xw1);
yw[i]=yw[i]+t*(Yw2-Yw1);
zw[i]=zw[i]+t*(Zw2-Zw1);
}
drawCUBE(9,7);
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
t+=dt;
}
while(t<=1);
for (int i=0;i<8;i++)
{ xx[i]=xw[i]; yy[i]=yw[i]; zz[i]=zw[i];}
drawCUBE(9,7);
getch();
while(c!=113)
{ setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
if (kbhit())
c=getch();
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setlinestyle(0,0,0);
setcolor(9);
init();
perenos(-Xw1,-Yw1,-Zw1);
drawCUBE(9,7);
vector(Xw1,Yw1,Zw1,Xw2,Yw2,Zw2);
for(int i=0;i<8;i++)
{ xw[i]=xx[i]; yw[i]=yy[i]; zw[i]=zz[i]; }
drawCUBE(9,7);
settextstyle(0,0,1); setcolor(9);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
d=300;ro=550;
}
void maswtab(double k)
{
for(int i=0; i<8;i++)
{ xw[i]=xw[i]*k;
yw[i]=yw[i]*k;
zw[i]=zw[i]*k; }
}
void maswtabirovanie()
{ setcolor(9);
outtextxy(205,255,"Vvedite koefficient maswtabirovania:");
outtextxy(208,280,"k=");
k=input(230,280);
int c=0;
char *phimstr,*tetamstr,*dstr,*rostr;
fi=(atan(1)/45.0)*f; teta=(atan(1)/45.0)*t;
settextstyle(0,0,1);
setlinestyle(0,0,0);
outtextxy(3,235,"fi="); outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(3,245,"teta="); outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");outtextxy(20,215,itoa(d,dstr,10));
outtextxy(3,225,"ro="); outtextxy(30,225,itoa(ro,rostr,10));
xc=435; yc=100;
init();
drawCUBE(9,7);
setcolor(5);
maswtab(k);
drawCUBE(9,7);
getch();
while(c!=113)
{
setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
if (kbhit())
c=getch();
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setlinestyle(0,0,0);
init();
maswtab(k);
drawCUBE(9,7);
setcolor(9);
settextstyle(0,0,1);
setlinestyle(0,0,0);
outtextxy(3,235,"fi="); outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(3,245,"teta="); outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");outtextxy(20,215,itoa(d,dstr,10));
outtextxy(3,225,"ro="); outtextxy(30,225,itoa(ro,rostr,10));
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
d=300; ro=550;
}
void otrawen_xy()
{
for(int i=0; i<8;i++)
{ xw[i]=xw[i];
yw[i]=yw[i];
zw[i]=-zw[i]; }
}
void otrawen_yz()
{
for(int i=0; i<8;i++)
{ xw[i]=-xw[i];
yw[i]=yw[i];
zw[i]=zw[i]; }
}
void otrawen_xz()
{
for(int i=0; i<8;i++)
{ xw[i]=xw[i];
yw[i]=-yw[i];
zw[i]=zw[i]; }
}
void otraw_xy()
{
fi=(atan(1)/45.0)*f; teta=(atan(1)/45.0)*t;
int c=0;
char *phimstr,*tetamstr,*dstr,*rostr;
setcolor(9);
settextstyle(0,0,1); setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
xc=435; yc=100;
init();
drawCUBE(0,0);
setcolor(2);
drawCUBE(9,7);
vector(-100,0,0,100,0,0);
getch();
setcolor(5);
perenos(0,0,-100);
otrawen_xy();
while(c!=113)
{ setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
if (kbhit())
c=getch();
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setlinestyle(0,0,0);
setcolor(2);
vector(-100,0,0,100,0,0);
init();
perenos(0,0,-100);
drawCUBE(9,7);
otrawen_xy();
drawCUBE(9,7);
setcolor(9);
settextstyle(0,0,1); setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
d=300;ro=550;
}
void otraw_yz()
{
fi=(atan(1)/45.0)*f; teta=(atan(1)/45.0)*t;
int c=0;
char *phimstr,*tetamstr,*dstr,*rostr;
setcolor(9);
settextstyle(0,0,1); setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
xc=435; yc=100;
init();
setcolor(2);
drawCUBE(9,7);
vector(0,-100,0,0,100,0);
getch();
setcolor(5);
perenos(-100,0,0);
otrawen_yz();
while(c!=113)
{ setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
if (kbhit())
c=getch();
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setlinestyle(0,0,0);
setcolor(2);
vector(0,-100,0,0,100,0);
init();
perenos(-100,0,0);
drawCUBE(9,7);
otrawen_yz();
drawCUBE(9,7);
setcolor(9);
settextstyle(0,0,1); setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
d=300;ro=550;
}
void otraw_xz()
{
fi=(atan(1)/45.0)*f; teta=(atan(1)/45.0)*t;
int c=0;
char *phimstr,*tetamstr,*dstr,*rostr;
setcolor(9);
settextstyle(0,0,1); setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
xc=435; yc=100;
init();
setcolor(2);
drawCUBE(9,7);
vector(0,0,-100,0,0,100);
getch();
setcolor(5);
perenos(0,-100,0);
otrawen_xz();
while(c!=113)
{
setvisualpage(1-page);
setactivepage(page);
page=1-page;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
if (kbhit())
c=getch();
if (c==75)
{ teta+=3.14/180;
if ((int)(teta*180/3.14)==360) teta=0; c=0;
}
if (c==77)
{ teta-=3.14/180;
if ((int)(teta*180/3.14)==-360) teta=0; c=0;
}
if (c==72)
{ fi+=3.14/180;
if ((int)(fi*180/3.14)==360) fi=0; c=0;
}
if (c==80)
{ fi-=3.14/180;
if ((int)(fi*180/3.14)==-360) fi=0; c=0;
}
if(c==119) { ro+=1; c=0; }
if(c==115) { ro-=1; c=0; }
if(c==97) { d+=1; c=0; }
if(c==100) { d-=1; c=0; }
setlinestyle(0,0,0);
setcolor(2);
vector(0,0,-100,0,0,100);
init();
perenos(0,-100,0);
drawCUBE(9,7);
otrawen_xz();
drawCUBE(9,7);
setcolor(9);
settextstyle(0,0,1);
setlinestyle(0,0,0);
outtextxy(3,235,"fi=");
outtextxy(3,245,"teta=");
outtextxy(3,265,"q - Exit");
outtextxy(3,215,"d=");
outtextxy(3,225,"ro=");
outtextxy(1,335,"Left-(teta+1) Right-(teta-1) Up-(fi+1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
outtextxy(30,235,itoa(fi*180/3.14,phimstr,10));
outtextxy(45,245,itoa(teta*180/3.14,tetamstr,10));
outtextxy(20,215,itoa(d,dstr,10));
outtextxy(30,225,itoa(ro,rostr,10));
setvisualpage(1-page);
setactivepage(page);
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,640,350);
}
d=300;ro=550;
}
void izmenenie()
{
char *aa,*dd,*rro,*ffi,*ttet;
int d2,aa2,ro2;
float f2,t2;
aa2=a; f2=f; d2=d; t2=t; ro2=ro;
setcolor(9);
outtextxy(205,225,"Vvedite novie nachalnie parametri:");
outtextxy(208,250,"a=");
a=input(225,250);
outtextxy(293,250,"d=");
d=input(310,250);
outtextxy(378,250,"ro=");
ro=input(400,250);
outtextxy(208,300,"fi=");
f=input(230,300);
outtextxy(293,300,"teta=");
t=input(335,300);
setcolor(0);
outtextxy(20,185,itoa(aa2,aa,10)); outtextxy(75,185,itoa(d2,dd,10));
outtextxy(75,195,itoa(ro2,rro,10)); outtextxy(145,185,itoa(f2,ffi,10));
outtextxy(145,195,itoa(t2,ttet,10));
setcolor(9);
outtextxy(20,185,itoa(a,aa,10)); outtextxy(75,185,itoa(d,dd,10));
outtextxy(75,195,itoa(ro,rro,10)); outtextxy(145,185,itoa(f,ffi,10));
outtextxy(145,195,itoa(t,ttet,10));
}
void main()
{ int c=0;
A: clrscr();
int driver=EGA;
int mode=EGAHI;
int error_code;
initgraph(&driver,&mode,"C:\\borlandc\\bgi");
error_code=graphresult();
if (error_code!=grOk)
{
cout<<"Graphics error "<<grapherrormsg(error_code);
exit(0);
}
clearviewport();
setfillstyle(0,1); settextstyle(0,0,1);
bar(0,0,170,20);
setcolor(9);
outtextxy(3,7,"1 - Vrawenie Cent Mass");
bar(0,20,170,40); outtextxy(3,27,"2 - Vrawenie po vectoru");
bar(0,40,170,60); outtextxy(3,47,"3 - Izmenenie Parametrov");
/* bar(0,60,170,80); outtextxy(3,67,"4 - Otragenie XY");
bar(0,80,170,100); outtextxy(3,87,"5 - Otragenie YZ");
bar(0,100,170,120); outtextxy(3,107,"6 - Otragenie XZ");
bar(0,120,170,140); outtextxy(3,127,"7 - Izmenenie parametrov");
*/
bar(0,140,170,160); outtextxy(3,147,"Esc - Exit");
setlinestyle(0,0,3);
char *aa,*rro,*ffi,*dd,*ttet;
outtextxy(3,185,"Nachalnie parametri:");
outtextxy(3,205,"a="); outtextxy(20,205,itoa(a,aa,10));
outtextxy(3,215,"d="); outtextxy(20,215,itoa(d,dd,10));
outtextxy(3,225,"ro="); outtextxy(30,225,itoa(ro,rro,10));
outtextxy(3,235,"fi="); outtextxy(30,235,itoa(f,ffi,10));
outtextxy(3,245,"teta="); outtextxy(45,245,itoa(t,ttet,10));
outtextxy(1,325,"Left-(teta+1) Up-(fi+1)");
outtextxy(1,335,"Right-(teta-1) Down-(fi-1)");
outtextxy(1,342,"w-(ro+1) s-(ro-1) a-(d+1) d-(d-1)");
setlinestyle(0,0,0);
fi=(atan(1)/45.0)*f; teta=(atan(1)/45.0)*t;
xc=435; yc=100;
init();
drawCUBE(9,7);
int key=0;
if(bioskey(1)==0)
{
key=getch();
//if(key==49){dviwenie();closegraph();goto A;}
if(key==50){vrashenie();closegraph(); goto A;}
//if(key==51){maswtabirovanie();closegraph();goto A;}
//if(key==52){otraw_xy();closegraph();goto A;}
//if(key==53){otraw_yz();closegraph();goto A;}
//if(key==54){otraw_xz();closegraph();goto A;}
if(key==49){vrashenieCentr();closegraph();goto A;}
if(key==51){izmenenie();closegraph();goto A;}
if(key==27) closegraph(); exit(1);
}
}