//--------------------------------------------------------------------------- #include #include #include #include #pragma hdrstop #include "hlavni.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; long double prevedx(long double x,long double y,long double z ) { return cos(uhelc)*(sin(uhelb)*(x)-cos(uhelb)*(z))+(sin(uhelc)*(sin(uhela)*cos(uhelb)*(x)-cos(uhela)*(y)+sin(uhelb)*sin(uhela)*(z))); } //--------------------------------------------------------------------------- long double prevedy(long double x,long double y,long double z) { return -sin(uhelc)*(sin(uhelb)*(x)-cos(uhelb)*(z))+cos(uhelc)*(sin(uhela)*cos(uhelb)*(x)-cos(uhela)*(y)+sin(uhelb)*sin(uhela)*(z)); } //--------------------------------------------------------------------------- void __fastcall DrawAxes(TCanvas* canvas, int Width, int Height) { canvas->Pen->Color=(TColor)RGB(255,255,255); canvas->Pen->Width=1; canvas->MoveTo(Width/2, Height/2); canvas->LineTo(Width/2+prevedx(60,0,0), Height/2+prevedy(60,0,0)); canvas->MoveTo(Width/2, Height/2); canvas->LineTo(Width/2+prevedx(0,60,0), Height/2+prevedy(0,60,0)); canvas->MoveTo(Width/2, Height/2); canvas->LineTo(Width/2+prevedx(0,0,60), Height/2+prevedy(0,0,60)); } //--------------------------------------------------------------------------- void smaz(TCanvas* canvas, int width, int height) { canvas->Brush->Color=(TColor)RGB(0,0,0); canvas->Rectangle(0,0,width, height); DrawAxes(canvas, width, height); } //--------------------------------------------------------------------------- void __fastcall DrawPlanets() { int i=0; int newx, newy; int height = Form1->Image1->Height; int width = Form1->Image1->Width; if (Zobr == TECKY || Zobr == OBRAZKY) { smaz(FBuffer->Canvas, width, height); } FBuffer->Canvas->Pen->Width=3; for(i = 0; i <= MAX; i++) { FBuffer->Canvas->Pen->Color = (TColor)RGB(((i+3))*31,((i+4))*87,((i+4))*53); if (sel == -1) { newx = prevedx(tela[i].x,tela[i].y,tela[i].z)/zoom+width/2; newy = prevedy(tela[i].x,tela[i].y,tela[i].z)/zoom+height/2; } else //Relativne vzhledem k sel { newx = prevedx(tela[i].x-tela[sel].x,tela[i].y-tela[sel].y,tela[i].z-tela[sel].z)/zoom+width/2; newy = prevedy(tela[i].x-tela[sel].x,tela[i].y-tela[sel].y,tela[i].z-tela[sel].z)/zoom+height/2; } switch (Zobr) { case CARY: case TECKY: FBuffer->Canvas->MoveTo(prevedx(tela[i].px,tela[i].py,tela[i].pz)/zoom+width/2,prevedy(tela[i].px,tela[i].py,tela[i].pz)/zoom+height/2); FBuffer->Canvas->LineTo(newx, newy); break; case OBRAZKY: Form1->ilPlanety->Draw(FBuffer->Canvas, newx - 15, newy - 15, i, true); break; } } } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void nastav(int i) { tela[i].x=0; tela[i].y=0; tela[i].z=0; tela[i].vx=0; tela[i].vy=0; tela[i].vz=0; tela[i].m=0; } //--------------------------------------------------------------------------- void __fastcall TForm1::init() { sel=-1; zoom=500000000; // Tady narvu planety daty // To je Slunce tela[0].px=tela[0].x=0; tela[0].py=tela[0].y=0; tela[0].pz=tela[0].z=0; tela[0].vx=0; tela[0].vy=0; tela[0].vz=0; tela[0].m=1.971E+30; // A to Merkur, tela[1].px=tela[1].x=56927699999; // Vzdalenost od Slunce tela[1].py=tela[1].y=0; tela[1].pz=tela[1].z=tela[1].x*sin(M_PI*7/180); // Nakloneni obezne drahy k ekliptice (7 stupnu u Merkuru) tela[1].vx=0; tela[1].vy=47063; // Obezna rychlost tela[1].vz=0; tela[1].m=3.285E+23; // Hmotnost // toto Venuse, tela[2].px=tela[2].x=106353299999; tela[2].py=tela[2].y=0; tela[2].pz=tela[2].z=tela[2].x*sin(M_PI*3.3/180); tela[2].vx=0; tela[2].vy=34454; tela[2].vz=0; tela[2].m=4.868E+24; // a dal to znate sami... tela[3].px=tela[3].x=147099999999; tela[3].py=tela[3].y=0; tela[3].pz=tela[3].z=0; tela[3].vx=0; tela[3].vy=29307; tela[3].vz=0; tela[3].m=5.974E+24; tela[4].px=tela[4].x=224033299999; tela[4].py=tela[4].y=0; tela[4].pz=tela[4].z=tela[4].x*sin(M_PI*1.8/180); tela[4].vx=0; tela[4].vy=23742; tela[4].vz=0; tela[4].m=6.392E+23; tela[5].px=tela[5].x=765214199999; tela[5].py=tela[5].y=0; tela[5].pz=tela[5].z=tela[5].x*sin(M_PI*1.3/180); tela[5].vx=0; tela[5].vy=12852; tela[5].vz=0; tela[5].m=1.899E+27; tela[6].px=tela[6].x=1404510799999; tela[6].py=tela[6].y=0; tela[6].pz=tela[6].z=tela[6].x*sin(M_PI*2.48/180); tela[6].vx=0; tela[6].vy=9499; tela[6].vz=0; tela[6].m=5.686E+26; tela[7].px=tela[7].x=2794899999999; tela[7].py=tela[7].y=0; tela[7].pz=tela[7].z=tela[7].x*sin(M_PI*0.7/180); tela[7].vx=0; tela[7].vy=6621; tela[7].vz=0; tela[7].m=8.684E+25; tela[8].px=tela[8].x=4449039499999; tela[8].py=tela[8].y=0; tela[8].pz=tela[8].z=tela[8].x*sin(M_PI*1.7/180); tela[8].vx=0; tela[8].vy=5379; tela[8].vz=0; tela[8].m=1.023E+26; tela[9].px=tela[9].x=5857816200000; tela[9].py=tela[9].y=0; tela[9].pz=tela[9].z=tela[9].x*sin(M_PI*17/180); tela[9].vx=0; tela[9].vy=4120; tela[9].vz=0; tela[9].m=1.553E+22; long double px=0,py=0,pz=0; // "Vyvazeni" cele soustavy Sluncem, aby to neletelo pryc // Hmmm... Je to zakon zachovani hybnosti, pro fyziky znale :) for(int i=1;i<=MAX;i++) { px+=tela[i].vx*tela[i].m; py+=tela[i].vy*tela[i].m; pz+=tela[i].vz*tela[i].m; } tela[0].vx=-px/tela[0].m; tela[0].vy=-py/tela[0].m; tela[0].vz=-pz/tela[0].m; d=60*60*24; Zobr = CARY; smaz(Image1->Canvas, Image1->Width, Image1->Height); smaz(FBuffer->Canvas, Image1->Width, Image1->Height); DrawPlanets(); } void __fastcall TForm1::FormCreate(TObject *Sender) { MAX=9; FBuffer = new Graphics::TBitmap; FBuffer->Height = Screen->DesktopHeight; FBuffer->Width = Screen->DesktopWidth; init(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key) { switch(Key) { case 'q': uhela+=M_PI/8; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'w': uhela-=M_PI/8; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'a': uhelb+=M_PI/8; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 's': uhelb-=M_PI/8; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'z': uhelc+=M_PI/8; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'x': uhelc-=M_PI/8; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'g': if(zoom>10000000)zoom/=1.5; else Beep(1000,15); smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'h': if(zoomCanvas, Image1->Width, Image1->Height); break; case 'e': if(d>5) d/=2; else Beep(1000,15); break; case 'r': if(dCanvas, Image1->Width, Image1->Height); } /*else if(sel==-1) { sel=0; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); }*/ lZobrPlaneta->Caption = JmPlanet[sel + 1]; break; case '[': if((sel>-1)) { sel--; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); } /*else if(sel==-1) { sel=0; smaz(FBuffer->Canvas, Image1->Width, Image1->Height); } */ lZobrPlaneta->Caption = JmPlanet[sel + 1]; break; case ';': init(); rbCary->Checked = true; break; case 'p': Timer1->Enabled=!Timer1->Enabled; if (Timer1->Enabled == true) Button13->Caption = "Stop"; else Button13->Caption = "Start"; break; case 'c': exit(0); smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; case 'd': smaz(FBuffer->Canvas, Image1->Width, Image1->Height); break; } Image1Paint(this); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { FormKeyPress(this,Key); } void __fastcall TForm1::Timer1Timer(TObject *Sender) { char buf[100]; spocti(tela); DrawPlanets(); TRect rect(0, 0, Image1->Width, Image1->Height); Image1->Canvas->CopyRect(rect, FBuffer->Canvas, rect); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { FormKeyPress(Sender, 'q'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { FormKeyPress(Sender, 'w'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button6Click(TObject *Sender) { FormKeyPress(Sender, 'a'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button5Click(TObject *Sender) { FormKeyPress(Sender, 's'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button8Click(TObject *Sender) { FormKeyPress(Sender, 'z'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button7Click(TObject *Sender) { FormKeyPress(Sender, 'x'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button10Click(TObject *Sender) { FormKeyPress(Sender, 'g'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button9Click(TObject *Sender) { FormKeyPress(Sender, 'h'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button12Click(TObject *Sender) { FormKeyPress(Sender, 'r'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button11Click(TObject *Sender) { FormKeyPress(Sender, 'e'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button15Click(TObject *Sender) { FormKeyPress(Sender, ']'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button14Click(TObject *Sender) { FormKeyPress(Sender, '['); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button13Click(TObject *Sender) { FormKeyPress(Sender, 'p'); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button16Click(TObject *Sender) { FormKeyPress(Sender, ';'); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormResize(TObject *Sender) { smaz(FBuffer->Canvas, Image1->Width, Image1->Height); } //--------------------------------------------------------------------------- void __fastcall TForm1::Image1Paint(TObject *Sender) { TRect rect(0, 0, Image1->Width, Image1->Height); Image1->Canvas->CopyRect(rect, FBuffer->Canvas, rect); } //--------------------------------------------------------------------------- void __fastcall TForm1::rbCaryClick(TObject *Sender) { smaz(FBuffer->Canvas, Image1->Width, Image1->Height); Zobr = CARY; } //--------------------------------------------------------------------------- void __fastcall TForm1::rbTeckyClick(TObject *Sender) { Zobr = TECKY; } //--------------------------------------------------------------------------- void __fastcall TForm1::rbObrazkyClick(TObject *Sender) { Zobr = OBRAZKY; } //---------------------------------------------------------------------------