Sign in to follow this  
dagmare

OpenGL texture help

Recommended Posts

I wrote an OpenGL program with swiching scenes. I have a problem with one of the scenes- it shows the objects, but the texture put on quad doesnt work. (I have used this textures in previous scenes and everything was ok). I am curious if anybody could check up on my code? this is function switching between the scenes: void __fastcall TFormMain::DrawObjects() { UpDate(); double hour, min, sec; hour=floor(T/60/60); min=floor((T-hour*60*60)/60); sec=floor(T-hour*60*60-min*60); String time, timeh, timem, times; String dates, yrs,mos,ds,hs,mins,ss, timest; timeh=FloatToStr(hour); timem=FloatToStr(min); times=FloatToStr(sec); yrs=IntToStr(int(yr)); mos=IntToStr(int(mo)); ds=IntToStr(int(d)); hs=IntToStr(int(h)); mins=IntToStr(int(m)); ss=IntToStr(int(s)); dates=yrs+'.'+mos+'.'+ds; timest=hs+':'+mins+':'+ss; time=timeh+'h'+timem+'m'+times+'s'; FormMain->Label2->Caption=time; FormMain->Label3->Caption=dates; FormMain->Label4->Caption=timest; switch(object) { case 0: SceneOne(); break; case 1: SceneTwo(); break; case 2: SceneThree(); break; case 3: SceneFour(); break; case 4: SceneFive(); break; case 5: SceneSix(); break; } } this is scene five - the problematic one: void __fastcall TFormMain::SceneFive() { glLoadIdentity(); GroundTrackMap(); if(Child->CheckBox5->Checked) { glLoadIdentity(); DrawGroundTrack(); } glLoadIdentity(); AnimTrack(); } and this the function with texture which is not working: void __fastcall TFormMain::GroundTrackMap() { glLoadIdentity(); glColor3f(1.0,1.0,1.0); glBindTexture(GL_TEXTURE_2D, texture1); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f(8400,-6400,-15000); glTexCoord2f(0.0f, 0.0f); glVertex3f(-8400,-6400,-15000); glTexCoord2f(0.0f, 1.0f); glVertex3f(-8400,6400,-15000); glTexCoord2f(1.0f, 1.0f); glVertex3f(8400,6400,-15000); glEnd(); } the rest of the functions in scene five is working ok. Could anybody help me with that? actually if there is anybody who can check all my code, than i can pay for that- i am desperate to finish this thing quick :)

Share this post


Link to post
Share on other sites
Have you glEnable(GL_TEXTURE_2D)'d the other scenes but not scene five? It might not hurt to toss it into the beginning of the drawing, just to make sure. Also, you seem to have LOTS of glLoadIdentity( )s, which are unnecessary and a performance hit (though not the cause of your problem, just something to note). If that doesn't help, post some more code inside of [source] and [/source] tags (it'll be formatted and pretty, much easier to read).

-jouley

Share this post


Link to post
Share on other sites
yes i did, and even i add this line to scene five, it doesnt help. Is it possible that it is something with my lighting settings? I can send some more code via e-mail if you be so kind to have a look, because it is quite long. Is that ok?

and for now:

//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <fstream>
#include <iostream.h>
#include <condefs.h>
#include <conio.h>
#pragma hdrstop

#include "GlSkel.h"
#include "child1.h"
#include "nSym.h"
#include "incomplete.h"
#include "perturbation.h"

//---------------------------------------------------------------------------
//#pragma hdrstop
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;

//FILE *test;

//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{ //Child->nowa=FALSE;

//test=fopen("ground.txt","w");
Application->OnIdle = IdleLoop;
//size = 0.50f;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::IdleLoop(TObject*, bool& done)
{
done = false;
RenderGLScene();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{ StartValue();

hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
if(hrc == NULL)
ShowMessage(":-)~ hrc == NULL");
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage("Could not MakeCurrent");
w = ClientWidth;
h = ClientHeight;

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);

glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
SetupLighting();
SetupTextures();

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, PixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormResize(TObject *Sender)
{
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

w = ClientWidth;
h = ClientHeight;

if(h == 0)
h = 1;
glViewport(0, 0, w, h);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,10000.1f,200000.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::RenderGLScene()
{
T0=T;T=T+60;
JD=julian(yr, mo, d, h, m, s);
//cieniuj(JD,T);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawObjects();
glFlush();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawObjects()
{ UpDate();

double hour, min, sec;

hour=floor(T/60/60);
min=floor((T-hour*60*60)/60);
sec=floor(T-hour*60*60-min*60);

String time, timeh, timem, times;
String dates, yrs,mos,ds,hs,mins,ss, timest;

timeh=FloatToStr(hour);
timem=FloatToStr(min);
times=FloatToStr(sec);

yrs=IntToStr(int(yr));
mos=IntToStr(int(mo));
ds=IntToStr(int(d));
hs=IntToStr(int(h));
mins=IntToStr(int(m));
ss=IntToStr(int(s));

dates=yrs+'.'+mos+'.'+ds;
timest=hs+':'+mins+':'+ss;

time=timeh+'h'+timem+'m'+times+'s';
FormMain->Label2->Caption=time;
FormMain->Label3->Caption=dates;
FormMain->Label4->Caption=timest;
switch(object)
{
case 0:
SceneOne();
break;
case 1:
SceneTwo();
break;
case 2:
SceneThree();
break;
case 3:
SceneFour();
break;
case 4:
SceneFive();
break;
case 5:
SceneSix();
break;
}
}

//---------------------------------------------------------------------------
void __fastcall TFormMain::SceneOne()
{
glLoadIdentity();
glColor3f(0.9f, 0.5f, 0.5f);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawAxis();

glLoadIdentity();
glColor3f(0.9f, 0.5f, 0.5f);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
AnimGLSat();

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawEarth();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SceneTwo()
{

glLoadIdentity();
glColor3f(0.9f, 0.5f, 0.5f);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawAxis();

glLoadIdentity();
DrawOrbits();

glLoadIdentity();
glColor3f(0.9f, 0.5f, 0.5f);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
AnimGLSat();

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawEarth();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SceneThree()
{
glLoadIdentity();
glColor3f(0.9f, 0.5f, 0.5f);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawAxis();

glLoadIdentity();
AnimGLEcf();

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawEarthECF();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SceneFour()
{
glLoadIdentity();
glColor3f(0.9f, 0.5f, 0.5f);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawAxis();

glLoadIdentity();
AnimGLEcf();

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawGLEcf();

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
DrawEarthECF();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SceneFive()
{
glLoadIdentity();
GroundTrackMap();
if(Child->CheckBox5->Checked)
{
glLoadIdentity();
DrawGroundTrack();
}
glLoadIdentity();
AnimTrack();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SceneSix()
{
glLoadIdentity();
FormMain->Label2->Caption=' ';

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormPaint(TObject *Sender)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
DrawObjects();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
gluDeleteQuadric(Satqua);
gluDeleteQuadric(Earth);
gluDeleteQuadric(Earth1);
delete bitmap;
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hrc);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::StartValue()
{ for(loop=0;loop<num;loop++)
{ double w[3];
sat[loop].r=rand()%4;
sat[loop].g=rand()%3;
sat[loop].b=rand()%2;
/* while(sat[loop].r<0.3 && sat[loop].g<0.3 && sat[loop].b<0.3)
{
sat[loop].r=rand()%4;
sat[loop].g=rand()%4;
sat[loop].b=rand()%3;
} */

sat[loop].rs=sat[loop].r;
sat[loop].gs=sat[loop].g;
sat[loop].bs=sat[loop].b;
sat[loop].el[5]=loop*10*PI/180.0;//mean anomaly
sat[loop].el[2]=60*PI/180.0;//ink
sat[loop].el[4]=loop*15*PI/180.0;//node
sat[loop].el[0]=20000.0;//semimajor axis
sat[loop].el[1]=0.6; //eccentricity
sat[loop].el[3]=15*PI/180.0; // argument of perigee

secular(sat[loop].el,w);
sat[loop].Ms=(*(w+2));
sat[loop].Nodes=(*(w+1));
sat[loop].oms=(*w);

}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawAxis()
{
glBegin(GL_LINES);
{
glVertex3f(-100000,0,0);
glVertex3f(100000,0,0);
glVertex3f(0,-100000,0);
glVertex3f(0,100000,0);
glVertex3f(0,0,-100000);
glVertex3f(-0,0,100000);
}
glEnd();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawEarth()
{

double ziemia;
ziemia=(green+7.29211585530*pow(10,-5)*T)*180/PI;

Earth = gluNewQuadric();
gluQuadricTexture(Earth, GL_TRUE);
gluQuadricDrawStyle(Earth, GLU_FILL);
gluQuadricNormals(Earth, GLU_SMOOTH);
glBindTexture(GL_TEXTURE_2D, texture1);
glColor3f(1.0f,1.0f,1.0f);
glRotatef(-90,0.0f,0.0f,1.0f);
glRotatef(ziemia,0.0f,0.0f,1.0f);
gluSphere(Earth, 6378.137f,320000,320000);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawEarthECF()
{
Earth1 = gluNewQuadric();
gluQuadricTexture(Earth1, GL_TRUE);
gluQuadricDrawStyle(Earth, GLU_FILL);
gluQuadricNormals(Earth1, GLU_SMOOTH);
glBindTexture(GL_TEXTURE_2D, texture1);
glColor3f(1.0f,1.0f,1.0f);
glRotatef(-90,0.0f,0.0f,1.0f);
gluSphere(Earth1, 6378.137f,320000,320000);

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawSatellite()
{
Satqua = gluNewQuadric();
gluQuadricDrawStyle(Satqua, GLU_FILL);
gluQuadricNormals(Satqua, GLU_SMOOTH);
//glColor3f(sat[i].r,sat[i].g,sat[i].b);
gluSphere(Satqua,200.0f,32,32);

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::AnimGLSat()
{ int i;
double wiekowe[3];

for(i=0;i<num;i++)
{
el[5]=sat[i].el[5];
el[2]=sat[i].el[2];
el[4]=sat[i].el[4];
el[0]=sat[i].el[0];
el[1]=sat[i].el[1];
el[3]=sat[i].el[3];

posvel(T,T0,el,pos,vel); //calculates position and velocity of the satellite

sat[i].x=pos[0];
sat[i].y=pos[1];
sat[i].z=pos[2];

elements(vel,pos,el,T0,T); //calculates orbital elements of the satellite

secular(el,wiekowe);
sat[i].Ms=(*(wiekowe+2));
sat[i].Nodes=(*(wiekowe+1));
sat[i].oms=(*wiekowe);
sat[i].el[5]=el[5]+(*(wiekowe+2))*(T-T0);
sat[i].el[2]=el[2];
sat[i].el[4]=el[4]+(*(wiekowe+1))*(T-T0);
sat[i].el[0]=el[0];
sat[i].el[1]=el[1];
sat[i].el[3]=el[3]+(*wiekowe)*(T-T0);
//fprintf(test,"%.10f %.10f %.10f\n", vel[3], T, sat[0].el[5]);
glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
glTranslatef(sat[i].x,sat[i].y,sat[i].z);
glColor3f(sat[i].r,sat[i].g,sat[i].b);
DrawSatellite();
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::AnimGLEcf()
{ int i;
double wiek[3],rff[4],elf[9],posf[4],velf[4];

for(i=0;i<num;i++)
{
elf[5]=sat[i].el[5];
elf[2]=sat[i].el[2];
elf[4]=sat[i].el[4];
elf[0]=sat[i].el[0];
elf[1]=sat[i].el[1];
elf[3]=sat[i].el[3];

posvel(T,T0,elf,posf,velf); //calculates position and velocity of the satellite
earthfix(posf,rff,T);

elements(velf,posf,elf,T0,T); //calculates orbital elements of the satellite

secular(elf,wiek);
sat[i].Ms=(*(wiek+2));
sat[i].Nodes=(*(wiek+1));
sat[i].oms=(*wiek);
sat[i].el[5]=elf[5]+(*(wiek+2))*(T-T0);
sat[i].el[2]=elf[2];
sat[i].el[4]=elf[4]+(*(wiek+1))*(T-T0);
sat[i].el[0]=elf[0];
sat[i].el[1]=elf[1];
sat[i].el[3]=elf[3]+(*wiek)*(T-T0);

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
glTranslatef(rff[0],rff[1],rff[2]);
glColor3f(sat[i].r,sat[i].g,sat[i].b);
DrawSatellite();
}

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawGLEcf()
{ int i,k;
double rf[4],ele[9],polo[4],pre[4];
double Te=0,T0e=0;
double sece[3];
double rep;
int x;

glLoadIdentity();
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);
glColor3f(1.0,0.4,0.4);

if(Child->CheckBox5->Checked)
{
x=1;
rep=Child->repeat;
}
else
{
x=num;
rep=1000;
}

for(i=0;i<x;i++)
{ T0e=T0;Te=T;

ele[5]=sat[i].el[5];;
ele[2]=sat[i].el[2];
ele[4]=sat[i].el[4];
ele[0]=sat[i].el[0];
ele[1]=sat[i].el[1];
ele[3]=sat[i].el[3];
k=0;
glBegin(GL_LINE_STRIP);
while(k<rep)
{
k++;

posvel(Te,T0e,ele,polo,pre); //calculates position and velocity of the satellite
earthfix(polo,rf,Te);

elements(pre,polo,ele,T0e,Te); //calculates orbital elements of the satellite

secular(ele,sece);
ele[5]=ele[5]+(*(sece+2))*(Te-T0e);
ele[4]=ele[4]+(*(sece+1))*(Te-T0e);
ele[3]=ele[3]+(*sece)*(Te-T0e);

glLoadIdentity();
glVertex3f(rf[0],rf[1],rf[2]);
T0e=Te;
Te=Te+60;
} glEnd();
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawOrbits()
{
int l;
double ele[9],pre[4],polo[4];
double To=0,T0o=0;
double P,nn;
double GM=398600.64;
double sec[3];

To=T; T0o=T0;

for(l=0;l<num;l++)
{
To=0,T0o=0;

ele[0]=sat[l].el[0];
ele[1]=sat[l].el[1];
ele[2]=sat[l].el[2];
ele[3]=sat[l].el[3];
ele[4]=sat[l].el[4];
ele[5]=sat[l].el[5];

nn=sqrt(GM/pow(ele[0],3));
P=2*PI/nn;

glLoadIdentity();
glColor3f(1.0,0.4,0.4);
glTranslatef(0.0,0.0,z);
glRotatef(xspeed,1.0f,0.0f,0.0f);
glRotatef(yspeed,0.0f,0.0f,1.0f);

glBegin(GL_LINE_STRIP);
{
while(T0o<P+100)
{ T0o=To;
To=To+60;
posvel(To,T0o,ele,polo,pre);
elements(pre,polo,ele,T0o,To);
secular(ele,sec);
ele[5]=ele[5]+(*(sec+2))*(To-T0o);
ele[4]=ele[4]+(*(sec+1))*(To-T0o);
ele[3]=ele[3]+(*sec)*(To-T0o);
glVertex3f(polo[0],polo[1],polo[2]);

}
}glEnd();

}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::GroundTrackMap()
{
glLoadIdentity();
glColor3f(1.0,1.0,1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1);

glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(8400,-6400,-15000);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-8400,-6400,-15000);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-8400,6400,-15000);
glTexCoord2f(1.0f, 1.0f); glVertex3f(8400,6400,-15000);
glEnd();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::AnimTrack()
{
int l,k;
double elt[9],velt[4],post[4];
//double Tt=0,T0t=0;
double ratio1, ratio2;
double sect[3],r[4];
double earthrot=7.29211585530*pow(10,-5);
double teta, latitude, longitude,teta0=0;
teta0=green;
ratio1=2*8400/(2*PI);
ratio2=2*6400/PI;
glColor3f(0.5,0.5,0.5);

glLoadIdentity();
glPointSize(5);
glBegin(GL_POINTS);
for(l=0;l<num;l++)
{ //double T0t=T0, Tt=T;
elt[0]=sat[l].el[0];
elt[1]=sat[l].el[1];
elt[2]=sat[l].el[2];
elt[3]=sat[l].el[3];
elt[4]=sat[l].el[4];
elt[5]=sat[l].el[5];
// glPointSize(0.5);
// glBegin(GL_POINTS);
// for(k=0;k<2000;k++)
// { T0t=Tt;
// Tt=Tt+30;
posvel(T,T0,elt,post,velt);
earthfix(post,r,T);
// sat[l].x=polo[0];
// sat[l].y=polo[1];
// sat[l].z=polo[2];

teta=teta0+earthrot*T;
// groundtrack(post,teta,latitude, longitude);
// fprintf(test,"%f %f\n",latitude,longitude);
latitude=asin(post[2]/post[3]);

L99: if(latitude<-PI/2)
latitude=latitude+PI;
if(latitude<-PI/2) goto L99;
// glColor3f(1,0,0);

longitude=atan2(post[1],post[0]);
longitude=longitude-teta;
L100: if(longitude<0)
{
longitude=longitude+2*PI;
}
if(longitude<0) goto L100;

elements(velt,post,elt,T0,T);
secular(elt,sect);
elt[5]=elt[5]+(*(sect+2))*(T-T0);
elt[4]=elt[4]+(*(sect+1))*(T-T0);
elt[3]=elt[3]+(*sect)*(T-T0);

sat[l].oms=(*sect);
sat[l].Nodes=(*(sect+1));
sat[l].Ms=(*(sect+2));

sat[l].el[0]=elt[0];
sat[l].el[1]=elt[1];
sat[l].el[2]=elt[2];
sat[l].el[3]=elt[3];
sat[l].el[4]=elt[4];
sat[l].el[5]=elt[5];
glLoadIdentity();
glColor3f(sat[l].r,sat[l].g,sat[l].b);
glVertex3f(ratio1*longitude-8400,ratio2*latitude,-15000);
}
glEnd(); //Sleep(40);
// } glEnd();
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawGroundTrack()
{
int l,k;
double elt[9],velt[4],post[4];
double Tt=0,T0t=0;
double ratio1, ratio2;
double sect[3],r[4];
double earthrot=7.29211585530*pow(10,-5);
double teta, latitude, longitude,teta0=0;


ratio1=2*8400/(2*PI);
ratio2=2*6400/PI;
glColor3f(1.0,1.0,1.0);
teta0=green;
glLoadIdentity();
glPointSize(1);
// elt[5]=sat[l].el[5];
//glBegin(GL_POINTS);
for(l=0;l<1;l++)
{ T0t=T0, Tt=T;
elt[0]=sat[l].el[0];
elt[1]=sat[l].el[1];
elt[2]=sat[l].el[2];
elt[3]=sat[l].el[3];
elt[4]=sat[l].el[4];
elt[5]=sat[l].el[5];


glPointSize(1.0);
glBegin(GL_POINTS);
for(k=0;k<2000;k++)
{ T0t=Tt;
Tt=Tt+600;
posvel(Tt,T0t,elt,post,velt);
earthfix(post,r,Tt);
// sat[l].x=polo[0];
// sat[l].y=polo[1];
// sat[l].z=polo[2];

teta=teta0+earthrot*Tt;
// groundtrack(post,teta,latitude, longitude);
// fprintf(test,"%f %f\n",latitude,longitude);
latitude=asin(post[2]/post[3]);

L99: if(latitude<-PI/2)
latitude=latitude+PI;
if(latitude<-PI/2) goto L99;
// glColor3f(1,0,0);

longitude=atan2(post[1],post[0]);
longitude=longitude-teta;
L100: if(longitude<0)
{
longitude=longitude+2*PI;
}
if(longitude<0) goto L100;

elements(velt,post,elt,T0t,Tt);
secular(elt,sect);
elt[5]=elt[5]+(*(sect+2))*(Tt-T0t);
elt[4]=elt[4]+(*(sect+1))*(Tt-T0t);
elt[3]=elt[3]+(*sect)*(Tt-T0t);
/*
sat[l].oms=(*sect);
sat[l].Nodes=(*(sect+1));
sat[l].Ms=(*(sect+2));
*/
/*
sat[l].el[0]=elt[0];
sat[l].el[1]=elt[1];
sat[l].el[2]=elt[2];
sat[l].el[3]=elt[3];
sat[l].el[4]=elt[4];
sat[l].el[5]=elt[5];*/

glLoadIdentity();
glColor3f(1.0,1.0,1.0);
//glColor3f(0,0,0);
glVertex3f(ratio1*longitude-8400,ratio2*latitude,-15000);
}
glEnd();// Sleep(40);
} //glEnd();
}

//----------------------------------------------------------------------------
void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key == VK_UP)
xspeed-=0.5f;
if(Key == VK_DOWN)
xspeed+=0.5f;
if(Key == VK_LEFT)
yspeed-=0.5f;
if(Key == VK_RIGHT)
yspeed+=0.5f;
if(Key == VK_PRIOR)
z-=200.5f;
if(Key == VK_NEXT)
z+=200.5f;
if (Key==' ')
{
object++;
if(object>4)
object=0;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetupLighting()
{
GLfloat MaterialAmbient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat MaterialDiffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialSpecular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialShininess[] = {50.0};
GLfloat AmbientLightPosition[] = {1.0, 1.0, 1.0, 0.0};
GLfloat LightAmbient[] = {0.5, 0.5, 0.5, 1.0};

glMaterialfv(GL_FRONT, GL_AMBIENT, MaterialAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, MaterialDiffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, MaterialSpecular);
glMaterialfv(GL_FRONT, GL_SHININESS, MaterialShininess);
glLightfv(GL_LIGHT0,GL_POSITION, AmbientLightPosition);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightAmbient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glShadeModel(GL_SMOOTH);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetupTextures()
{
bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("Data/earth.bmp");
GLubyte bits[256][256][4];
for(int i = 0; i < 256; i++)
{
for(int j = 0; j < 256; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
/*
bitmap->LoadFromFile("Data/earth.bmp");
for(int i = 0; i < 64; i++)
{
for(int j = 0; j < 64; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, bits);

bitmap->LoadFromFile("Data/earth.bmp");
for(int i = 0; i < 64; i++)
{
for(int j = 0; j < 64; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}



glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture3);
glBindTexture(GL_TEXTURE_2D, texture3);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, bits);

glEnable(GL_TEXTURE_2D);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); */

}
//--------------------------------------------------------------------------
// ASTRODYNAMICS
//--------------------------------------------------------------------------

void __fastcall TFormMain:: posvel(double T, double T0, double EL[9], double R[4], double PR[4])
{
double GM=398600.64; //km^3*s^-2
double AR,VR,VN,P,EA;
double AKE,A,EC,AI,AM,V,U,SOM,COM,SI,CI,SU,CU; //ED;
AKE=sqrt(GM);
A=EL[0];
EC=EL[1];
AI=EL[2];
// A=20000,0;
EL[8]=AKE/(pow(A,1.5));//mean motion
AM=EL[8]*(T-T0)+EL[5];
// printf("AM %.15f \n",AM);
//ED=AM;
EA=KEPL(AM,EC);

EL[6]=EA;
V=2.0*atan((sqrt((1.0+EC)/(1.0-EC)))*tan(EA/2.0));
if(V<0) V=V+2*PI;
EL[7]=V;
U=V+EL[3];
AR=A*(1.0-EC*EC)/(1.0+EC*cos(V));
SOM=sin(EL[4]);
COM=cos(EL[4]);
SU=sin(U);
CU=cos(U);
SI=sin(AI);
CI=cos(AI);

R[0]=AR*(CU*COM-SU*SOM*CI);
R[1]=AR*(CU*SOM+SU*COM*CI);
R[2]=AR*SU*SI;
R[3]=AR;
P=A*(1.0-EC*EC);
VR=AKE*EC*sin(V)/sqrt(P);
VN=AKE*(1.0+EC*cos(V))/(sqrt(P));

PR[0]=R[0]*VR/AR+(-SU*COM-CU*SOM*CI)*VN;
PR[1]=R[1]*VR/AR+(-SU*SOM+CU*COM*CI)*VN;
PR[2]=R[2]*VR/AR+CU*SI*VN;
PR[3]=sqrt(PR[0]*PR[0]+PR[1]*PR[1]+PR[2]*PR[2]);
// fprintf(test, "%.10f %f.10\n",V*180/M_PI, PR[3]);
}
//--------------------------------------------------------------------------
double KEPL(double AM, double EC)
{
double E1,ED;
E1=AM;

L4: ED=AM+EC*sin(E1);
if(sqrt(pow(ED-E1,2))>0.00000000000001)
{
E1=ED;
goto L4;
}

return ED;
}
//---------------------------------------------------------------------------
double cross(double vec1[3],double vec2[3], double vec4[3])
{
vec4[0]=vec1[1]*vec2[2]-vec1[2]*vec2[1];
vec4[1]=vec1[2]*vec2[0]-vec1[0]*vec2[2];
vec4[2]=vec1[0]*vec2[1]-vec1[1]*vec2[0];
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain:: elements(double vel[4], double pos[4], double el[9], double T0, double T)
{
double h[3],dlh,dlv,dlr,en, node, omega,EA,M;
double PI=atan(1.0)*4.0;
double GM=398600.64; //km^3*s^-2
double a,ec,ink,b,c,u,p,v;
cross(pos,vel,h);
dlh=lenght(h);
dlv=lenght(vel);
dlr=lenght(pos);
en=pow(dlv,2)/2.0-GM/dlr;
a=-GM/(2.0*en);
el[0]=a;

if(dlh*dlh/(GM*a)>=1.0) ec=el[1];
else ec=sqrt(1.0-dlh*dlh/(GM*a));

// ec=sqrt(1.0-dlh*dlh/(GM*a));
el[1]=ec;
ink=acos(h[2]/dlh);
if (ink<0.0) ink=ink+PI;
el[2]=ink;
if(ink==0.0000) node=el[4];
else
node=atan2(h[0],-h[1]);
if(node<0.0) node=node+2*PI;
el[4]=node;
//if (ink==0.0) ink=0.0001;
//else
b=pos[2]/(sin(ink));
c=pos[0]*cos(node)+pos[1]*sin(node);
u=atan2(b,c);
if(ink==0.0000) u=0.0;
if(u<0.0) u=u+2.0*PI;
p=a*(1.0-pow(ec,2));
b=sqrt(p/GM)*scalar(vel,pos);
c=p-dlr;
v=atan2(b,c);
if(v<0.0) v=v+2*PI;
omega=u-v;
if(ink==0.0000) omega=el[3];
if(omega<0.0) omega=omega+2*PI;
el[3]=omega;
el[8]=sqrt(GM)/(pow(a,1.5));//mean motion
EA=2.0*atan(sqrt((1-ec)/(1+ec))*tan(v/2.0));
M=EA-ec*sin(EA);
//M=el[5]+el[8]*(T-T0);
if(M<0.0) M=M+2*PI;
el[5]=M;
}
//---------------------------------------------------------------------------
double lenght(double vec[3])
{
double lenght;
lenght=sqrt(pow(vec[0],2)+pow(vec[1],2)+pow(vec[2],2));
return lenght;
}
//---------------------------------------------------------------------------
double scalar(double vec1[3],double vec2[3])
{
double scalar;
scalar=vec1[0]*vec2[0]+vec1[1]*vec2[1]+vec1[2]*vec2[2];
return scalar;
}
//---------------------------------------------------------------------------
double *secular(double el[9], double wiek[3])
{
double Re=6378.137,GM=398600.64;//km
double J2=-0.00108262668355;
double nm, ink, p, ec,aa, ksi;
double omegas,Ms,nodes;

ink=el[2];
ec=el[1];
aa=el[0];
p=aa*(1.0-pow(ec,2));
nm=sqrt(GM/(pow(aa,3)));

ksi=3*Re*Re*J2/(4*p*p);
//printf("ksi %.15f\n",ksi);
omegas=ksi*nm*(4-5*sin(ink)*sin(ink));
nodes=-2*ksi*nm*cos(ink);
Ms=ksi*nm*sqrt(1-ec*ec)*(2-3*sin(ink)*sin(ink));
wiek[0]=omegas;
wiek[1]=nodes;
wiek[2]=Ms;

return wiek;
// printf("secular %.15f %.15f %.15f\n",omegas, nodes, Ms);
}
//---------------------------------------------------------------------------
double earthfix(double r[4], double rf[4], double t)
{
//double PI=atan(1.0)*4.0;
double teta0ecf=0,tetaecf=0;
teta0ecf=green;
//double teta=1.00273790926493*2.0*PI;
tetaecf=teta0ecf+7.29211585530*pow(10,-5)*t;
rf[0]=cos(tetaecf)*r[0]+sin(tetaecf)*r[1];
rf[1]=-sin(tetaecf)*r[0]+cos(tetaecf)*r[1];
rf[2]=r[2];
return 0;
}
//----------------------------------------------------------------------------
void __fastcall TFormMain::ECIframe1Click(TObject *Sender)
{
object=0;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ECIorbits1Click(TObject *Sender)
{
object=1;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ECFFrame1Click(TObject *Sender)
{
object=2;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ECFandTrajectory1Click(TObject *Sender)
{
object=3;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::GroundTrack1Click(TObject *Sender)
{
object=4;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::CreateNewConstelatio1Click(TObject *Sender)
{

Child->Width=350;
Child->Height=600;
Child->Visible=true;

Child->Edit7->Text=IntToStr(num);
Child->Edit1->Text=FloatToStr(sat[0].el[0]);
Child->Edit2->Text=FloatToStr(sat[0].el[1]);
Child->Edit3->Text=FloatToStr(sat[0].el[2]);
Child->Edit4->Text=FloatToStr(sat[0].el[3]);
Child->Edit5->Text=FloatToStr(sat[0].el[4]);
Child->Edit6->Text=FloatToStr(sat[0].el[5]);


}
//---------------------------------------------------------------------------
void __fastcall TFormMain::UpDate()
{

int i;
// double deltaOMEGA,
double deltaM;
int max;

if(Child->CheckBox5->Checked)
{
Child->CheckBox6->Enabled=FALSE;
}
else if(Child->CheckBox6->Checked)
{
Child->CheckBox5->Enabled=FALSE;
}
else if(!(Child->CheckBox5->Checked) && !(Child->CheckBox6->Checked))
{
Child->CheckBox6->Enabled=TRUE;
Child->CheckBox5->Enabled=TRUE;
}

if(Child->CheckBox1->Checked)
{
Child->CheckBox2->Enabled=FALSE;
Child->CheckBox3->Enabled=FALSE;
Child->CheckBox4->Enabled=FALSE;
Child->Edit12->Enabled=FALSE;
}

else if(Child->CheckBox2->Checked)
{
Child->Edit12->Enabled=TRUE;
Child->CheckBox1->Enabled=FALSE;
Child->CheckBox3->Enabled=FALSE;
Child->CheckBox4->Enabled=FALSE;
}

else if(Child->CheckBox3->Checked)
{
Child->CheckBox2->Enabled=FALSE;
Child->CheckBox1->Enabled=FALSE;
Child->CheckBox4->Enabled=FALSE;
Child->Edit12->Enabled=FALSE;
}

else if(Child->CheckBox4->Checked)
{
Child->CheckBox2->Enabled=FALSE;
Child->CheckBox3->Enabled=FALSE;
Child->CheckBox1->Enabled=FALSE;
Child->Edit12->Enabled=FALSE;
}
else if(
!(Child->CheckBox4->Checked) &&
!(Child->CheckBox3->Checked) &&
!(Child->CheckBox2->Checked) &&
!(Child->CheckBox1->Checked))
{
Child->CheckBox2->Enabled=TRUE;
Child->CheckBox3->Enabled=TRUE;
Child->CheckBox1->Enabled=TRUE;
Child->CheckBox4->Enabled=TRUE;
Child->Edit12->Enabled=TRUE;
}


if(Child->nowa)
{ T=0.0; T0=0.0;
yr=Child->Edit13->Text.ToDouble();
mo=Child->Edit14->Text.ToDouble();
d=Child->Edit15->Text.ToDouble();
h=Child->Edit16->Text.ToDouble();
m=Child->Edit17->Text.ToDouble();
s=Child->Edit18->Text.ToDouble();
JD=julian(yr, mo, d, h, m, s);
green=sidereal(JD,h);

if(Child->CheckBox5->Checked)
{
FormMain->semi();
}

num=Child->Edit7->Text.ToInt();
sat[0].el[0]=Child->Edit1->Text.ToDouble();
sat[0].el[1]=Child->Edit2->Text.ToDouble();
if(sat[0].el[1]<=0) sat[0].el[1]=0,0001;
sat[0].el[2]=Child->Edit3->Text.ToDouble();
sat[0].el[3]=Child->Edit4->Text.ToDouble();
sat[0].el[4]=Child->Edit5->Text.ToDouble();
sat[0].el[5]=Child->Edit6->Text.ToDouble();

for(i=0;i<num;i++)
{
sat[i].r=rand()%4;
sat[i].g=rand()%2;
sat[i].b=rand()%3;
}



for(i=1;i<num;i++)
{
sat[i].el[5]=i*20*PI/180+sat[0].el[5];//loop*10*PI/180.0;//mean anomaly
sat[i].el[2]=sat[0].el[2];//60*PI/180.0;//ink
sat[i].el[4]=sat[0].el[4]+i*25*PI/180.0;//loop*15*PI/180.0;//node
sat[i].el[0]=sat[0].el[0];//20000.0;//semimajor axis
sat[i].el[1]=sat[0].el[1];//0.6; //eccentricity
sat[i].el[3]=sat[0].el[3];//15*PI/180.0; // argument of perigee
}

if(Child->CheckBox1->Checked && Child->CheckBox1->Enabled)
{
Fn=Child->Edit8->Text.ToInt();
Fd=Child->Edit9->Text.ToInt();
Np=Child->Edit10->Text.ToInt();
Nd=Child->Edit11->Text.ToInt();
num=Child->Edit7->Text.ToInt();
sat[0].el[0]=Child->Edit1->Text.ToDouble();
sat[0].el[1]=Child->Edit2->Text.ToDouble();


if(sat[0].el[1]<=0) sat[0].el[1]=0,0001;
sat[0].el[2]=Child->Edit3->Text.ToDouble();
//deltaOMEGA=-2.0*PI*Fn/Fd;
max=Fd*Nd;
//if(max>1000) max=1000;
if(num>max) num=max;
Child->Edit7->Text=IntToStr(num);

for(i=1;i<num;i++)
{ sat[i].el[0]=Child->Edit1->Text.ToDouble();
sat[i].el[1]=Child->Edit2->Text.ToDouble();
sat[i].el[2]=Child->Edit3->Text.ToDouble();
sat[i].el[4]= sat[i-1].el[4]-2*PI*Fn/Fd;
sat[i].el[5]= sat[i-1].el[5]+2*PI*Fn/Fd*Np/Nd;
}
Child->nowa=FALSE;
}
else if(Child->CheckBox2->Checked && Child->CheckBox2->Enabled)
{

dOMEGA=Child->Edit12->Text.ToDouble();

Fn=Child->Edit8->Text.ToInt();
Fd=Child->Edit9->Text.ToInt();
Np=Child->Edit10->Text.ToInt();
Nd=Child->Edit11->Text.ToInt();
num=Fd+1;
if(num>1000) num=1000;
Child->Edit7->Text=IntToStr(num);
for(i=1;i<num;i++)
{
sat[i].el[0]=Child->Edit1->Text.ToDouble();
sat[i].el[1]=Child->Edit2->Text.ToDouble();
sat[i].el[2]=Child->Edit3->Text.ToDouble();
sat[i].el[4]= sat[i-1].el[4]-dOMEGA*Fn/Fd;
//if(sat[i].el[4]>sat[0].el[4]+dOMEGA || sat[i].el[4]<-dOMEGA+sat[0].el[4])
// sat[i].el[4]=sat[0].el[4];
sat[i].el[5]= sat[i-1].el[5]+dOMEGA*Fn/Fd*Np/Nd;
}
Child->nowa=FALSE;
}
else if(Child->CheckBox3->Checked && Child->CheckBox3->Enabled)
{
NonSym->Visible=TRUE;

}
if(Child->CheckBox4->Checked && Child->CheckBox4->Enabled)
{
incom->Visible=TRUE;
}
Child->nowa=FALSE;
}

if(NonSym->zrobione)
{
double startOM;
double deltaOM[10];
Fn=Child->Edit8->Text.ToInt();
Fd=Child->Edit9->Text.ToInt();
Np=Child->Edit10->Text.ToInt();
Nd=Child->Edit11->Text.ToInt();
startOM=NonSym->Edit1->Text.ToDouble();
deltaOM[0]=NonSym->Edit2->Text.ToDouble();
deltaOM[1]=NonSym->Edit3->Text.ToDouble();
deltaOM[2]=NonSym->Edit4->Text.ToDouble();
deltaOM[3]=NonSym->Edit5->Text.ToDouble();
deltaOM[4]=NonSym->Edit6->Text.ToDouble();
deltaOM[5]=NonSym->Edit7->Text.ToDouble();
deltaOM[6]=NonSym->Edit8->Text.ToDouble();
deltaOM[7]=NonSym->Edit9->Text.ToDouble();
deltaOM[8]=NonSym->Edit10->Text.ToDouble();

if(num>10) num=10;
Child->Edit7->Text=IntToStr(num);

sat[0].el[5]==-1.0*startOM*Nd/Np;
sat[0].el[4]=startOM;

for(loop=1;loop<num;loop++)
{
sat[loop].el[4]=sat[loop-1].el[4]-deltaOM[loop-1];
deltaM=-1.0*deltaOM[loop-1]*Nd/Np;
sat[loop].el[5]= sat[loop-1].el[5]+deltaM;
}
T=0.0; T0=0.0;
NonSym->Visible=FALSE;
}

if(incom->yes)
{
int j,i,k=0,x=0;
int rem=0;
int which=0;
rem=0;
rem=incom->Edit1->Text.ToInt();

for(j=0;j<100;j++)
incom->remove[j]=0;

for(j=0;j<rem;j++)
incom->remove[j]=incom->Memo1->Lines->Strings[j].ToInt();

while(k<rem)
{
for(j=0;j<rem;j++)
{
if(incom->remove[j]>x)
{
x=incom->remove[j];
which=j;
}

}

if(x>-1)
{
sat[x].x=sat[num-1].x;
sat[x].y=sat[num-1].y;
sat[x].z=sat[num-1].z;

for(i=0;i<9;i++)
sat[x].el[i]=sat[num-1].el[i];
x=0;
}
k++;
incom->remove[which]=-1;
num--;


}
Child->Edit7->Text=IntToStr(num);
incom->Memo1->Clear();
incom->yes=FALSE;
}





Child->nowa=FALSE;
NonSym->zrobione=FALSE;
}
void __fastcall TFormMain::Exit1Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------


void __fastcall TFormMain::SaveConstellationas1Click(TObject *Sender)
{ int one, two, three, flower;
if(Child->CheckBox5->Checked) flower=1; else flower=0;
if(Child->CheckBox1->Checked) one=1; else one=0;
if(Child->CheckBox2->Checked) two=1; else two=0;
if(Child->CheckBox3->Checked) three=1; else three=0;

if(!SaveDialog1->Execute()) return;
String Name=SaveDialog1->FileName;

if(SaveDialog1->FileName!="")
{
ofstream Students(SaveDialog1->FileName.c_str(), ios::out);
Students <<flower<<"\n"<<num<<"\n"<<(FloatToStr(sat[0].el[0])).c_str()<<"\n"
<<(FloatToStr(sat[0].el[1])).c_str()<<"\n"
<<(FloatToStr(sat[0].el[2])).c_str()<<"\n"
<<(FloatToStr(sat[0].el[3])).c_str()<<"\n"
<<(FloatToStr(sat[0].el[4])).c_str()<<"\n"
<<(FloatToStr(sat[0].el[5])).c_str()<<"\n"
<<one<<"\n"<<two<<"\n"<<three<<"\n"
<<Fn<<"\n"<<Fd<<"\n"<<Np<<"\n"<<Nd<<"\n"
<<(FloatToStr(dOMEGA)).c_str();
}
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::OpenConstellation1Click(TObject *Sender)
{
int k=0;
if(!OpenDialog1->Execute()) return;
String Name=OpenDialog1->FileName;

std::ifstream is(Name.c_str()); if(!is.is_open()) return;
std::string s;

while(!is.eof())
{

std::getline(is,s);
String S=s.c_str(); // convert back to Borland AnsiString
if(k==0) //check if it is flower constellation
{
if(S.ToInt()==1) //flower constellation?//yes
{
Child->CheckBox5->Checked=true;
Child->CheckBox6->Checked=false;
}
else //no
{
Child->CheckBox6->Checked=true;
Child->CheckBox5->Checked=false;

}
}

if(k==1) //load number of satellites
{
num=S.ToInt();
Child->Edit7->Text=S;
}
if(Child->CheckBox5->Checked)
{
if(k==2) //load semi-major axis
{
sat[0].el[0]=S.ToDouble();
Child->Edit1->Text=S;
}

if(k==3) //load eccentricity
{
sat[0].el[1]=S.ToDouble();
Child->Edit2->Text=S;
}

if(k==4) //load inclination
{
sat[0].el[2]=S.ToDouble();
Child->Edit3->Text=S;
}

if(k==5)
{
sat[0].el[3]=S.ToDouble();
Child->Edit4->Text=S;
}

if(k==6)
{
sat[0].el[4]=S.ToDouble();
Child->Edit5->Text=S;
}

if(k==7)
{
sat[0].el[5]=S.ToDouble();
Child->Edit6->Text=S;
}

if(k==8)
{
if(S.ToInt()==1)
{
Child->CheckBox1->Checked=true;
Child->CheckBox1->Enabled=true;
Child->CheckBox2->Checked=false;
Child->CheckBox3->Checked=false;
Child->CheckBox4->Checked=false;
}
}

if(k==9)
{
if(S.ToInt()==1)
{
Child->CheckBox2->Checked=true;
Child->CheckBox2->Enabled=true;
Child->CheckBox1->Checked=false;
Child->CheckBox3->Checked=false;
Child->CheckBox4->Checked=false;
}
}

if(k==10)
{
if(S.ToInt()==1)
{
Child->CheckBox3->Checked=true;
Child->CheckBox3->Enabled=true;
Child->CheckBox1->Checked=false;
Child->CheckBox2->Checked=false;
Child->CheckBox4->Checked=false;
}
}

if(k==11)
{
Fn=S.ToInt();
Child->Edit8->Text=S;
}

if(k==12)
{
Fd=S.ToInt();
Child->Edit9->Text=S;
}

if(k==13)
{
Np=S.ToInt();
Child->Edit10->Text=S;
}

if(k==14)
{
Nd=S.ToInt();
Child->Edit11->Text=S;
}

if(k==15)
{
dOMEGA=S.ToDouble();
Child->Edit12->Text=S;
}
}
if(Child->CheckBox6->Checked)
{
//int l=0;
if(k>15 && k<=15+num)
{
sat[k-15].el[0]=S.ToDouble();
Child->Edit1->Text=S;
}

if(k>15+num && k<=15+2*num)
{
sat[k-num-15].el[1]=S.ToDouble();
Child->Edit2->Text=S;
}

if(k>15+2*num && k<=15+3*num)
{
sat[k-2*num-15].el[2]=S.ToDouble();
Child->Edit3->Text=S;
}

if(k>15+3*num && k<=15+4*num)
{
sat[k-3*num-15].el[3]=S.ToDouble();
Child->Edit4->Text=S;
}

if(k>15+4*num && k<=15+5*num)
{
sat[k-4*num-15].el[4]=S.ToDouble();
Child->Edit5->Text=S;
}

if(k>15+5*num && k<=15+6*num)
{
sat[k-5*num-15].el[5]=S.ToDouble();
Child->Edit6->Text=S;
}
Child->nowa=false;
}
k++;

object=0;
}

if(Child->CheckBox5->Checked)
Child->nowa=true;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::semi(void)
{

double rotz; // earth rotation
double ksi; //
double J2; // J2
double Rz; // eart radius
double GM; // gravitational constant
double Nd;
int Np, i;
double a, a0 ,p, hp, ink, n, ec, roznica;
a0=Child->Edit1->Text.ToDouble();
ec=Child->Edit2->Text.ToDouble();
ink=Child->Edit3->Text.ToDouble();
Np=Child->Edit10->Text.ToInt();
Nd=Child->Edit11->Text.ToInt();
//constants
rotz=7.29211585530*pow(10.0,-5.0);
J2=-1.08262668355*pow(10.0,-3.0);
Rz=6378.137;
GM=398600.0;

hp=a0-Rz;
roznica=1.0;

while(sqrt(pow(roznica,2))>0.0000000000000001)
{
hp=a0*(1-ec);
ec=-1*hp/a0+1;
p=a0*(1.0-ec*ec);
n=sqrt(GM/pow(a0,3.0));
ksi=3.0*Rz*Rz*J2/(4.0*p*p);
a=pow(GM,1.0/3.0)*pow((pow((1.0/rotz*Nd/Np*pow((1.0+2.0*ksi*n/rotz*cos(ink)),-1.0)*(1.0+ksi*(4.0+2.0*sqrt(1.0-ec*ec)-(5.0+3.0*sqrt(1.0-ec*ec))*sin(ink)*sin(ink)))),2.0)),1.0/3.0);
roznica=a-a0;
a0=a;
}

Child->Edit1->Text=FloatToStr(a);
sat[0].el[0]=a;
Child->repeat=2*PI/rotz*Nd/Np*pow((1.0+2.0*ksi*n/rotz*cos(ink)),-1.0)*(1.0+ksi*(4.0+2.0*sqrt(1.0-ec*ec)-(5.0+3.0*sqrt(1.0-ec*ec))*sin(ink)*sin(ink)));

}

void groundtrack(double r[4], double tetaGMST, double phi, double lambda)
{
double rsat,a,b;
double Re=6378.137;
double EE,alpha,F,P,Q,D,ni,G,t;
double ec=0.081819221456;
rsat=sqrt(r[0]*r[0]+r[1]*r[1]);

a=Re;
if(r[2]<0)
b=-6356.75160056;
else if(r[2]>0)
b=6356.75160056;
else b=0;

EE=(b*r[2]-(a*a-b*b))/(a*rsat);
alpha=atan2(r[1]/rsat,r[0]/rsat);
lambda=alpha-tetaGMST;

while(lambda<0.0)
lambda=lambda+2.0*PI;
// if(lambda<0.0) goto G1;

while(lambda>2.0*PI)
lambda=lambda-2.0*PI;
//if(lambda>2.0*PI)
//goto G2;


F=(b*r[2]+(a*a-b*b))/(a*rsat);
P=4.0*(EE*F+1)/3.0;
Q=2.0*(EE*EE-F*F);
D=pow(P,3.0)+Q*Q;

if(D>0)
ni=pow((sqrt(D)-Q),(1.0/3.0))-pow((sqrt(D)+Q),(1.0/3.0));
if(D<0)
ni=2*sqrt(-P)*cos(1.0/3.0*pow(cos(Q/(P*sqrt(-P))),-1.0));
else ni=0;
G=0.5*(sqrt(EE*EE+ni)+EE);
t=sqrt(G*G+(F-ni*G)/(2.0*G-EE))-G;
phi=atan(a*(1.0-t*t)/(2.0*b*t));
phi=atan((1-ec*ec)*tan(phi)); /*
G3: if(phi<-PI/2.0)
phi=phi+PI;
if(phi<-PI/2.0) goto G3;

G4: if(phi>PI/2.0)
phi=phi-PI;
if(phi>PI/2.0) goto G4;
*/

//fprintf(test,"phi=%f lambda=%f\n",phi*180.0/PI,lambda*180.0/PI);
}
//----------------------------------------------------------------------------
double __fastcall TFormMain:: julian(double yr, double mo, double d, double h, double min, double s)
{
double juliand;
double one;

one=7.0*(yr+int((mo+9.0)/12.0))/4.0;
juliand=367.0*yr-int(one)+int(275*mo/9.0)+d+1721013.5+((s/60.0+min)/(60.0)+h)/(24.0);
return juliand;

}

//-----------------------------------------------------------------------------
bool __fastcall TFormMain:: shadow(double rsat[3], double JD)
{
double TUT1=0;

TUT1=(JD-2451545.0)/(36525.0);
double TTDB, Lsun, Msun, Lecl;
double rs, epsilon, rsun[3];

Lsun=280.460+36000.770*TUT1;
while(Lsun<360.0)
Lsun=Lsun+360.0;

while(Lsun>360)
Lsun=Lsun-360;

TTDB=TUT1;
Msun=357.5277233+35999.05034*TTDB;

while(Msun<360.0)
Msun=Msun+360.0;

while(Msun>360)
Msun=Msun-360;

Lecl=Lsun+1.914666471*sin(Msun*M_PI/180.0)+0.019994643*sin(2.0*Msun*M_PI/180.0);
rs=1.000140612-0.016708617*cos(Msun*M_PI/180.0)-0.000139589*cos(2.0*Msun*M_PI/180.0);
epsilon=23.439291-0.0130042*TTDB;

double AU=149597870.691;
rsun[0]=rs*cos(Lecl*M_PI/180)*AU;
rsun[1]=rs*cos(epsilon*M_PI/180)*sin(Lecl*M_PI/180)*AU;
rsun[2]=rs*sin(epsilon*M_PI/180)*sin(Lecl*M_PI/180)*AU;

double deltas, alphas, a1,a2;

deltas=asin(sin(epsilon*M_PI/180.0)*sin(Lecl*M_PI/180.0));

a1=cos(epsilon*M_PI/180.0)*sin(Lecl*M_PI/180.0)/(cos(deltas));
a2=cos(Lecl*M_PI/180.0)/(cos(deltas));

alphas=atan2(a1,a2);

double z;

double Rz=6378.137;
double ksi;
double horiz, vert;
double pen, alphapen, umb;
bool umbra=false, preumbra=false;
alphapen=0.26900424*M_PI/180.0;
double alphaumb=0.26411888*M_PI/180.0;
z=scalar(rsun,rsat);

if(z<0.0)
{
ksi=acos(z/(lenght(rsun)*lenght(rsat)));
horiz=lenght(rsat)*cos(ksi);
vert=lenght(rsat)*sin(ksi);
pen=Rz+tan(alphapen)*horiz;
if(vert<=pen)
{
preumbra=true;
umb=Rz-tan(alphaumb)*horiz;
if(vert<=umb)
{
umbra=true;
}

}
}
if(preumbra || umbra)
return true;
else
return false;
}
//----------------------------------------------------------------------------
double sidereal(double JD, double HG)
{
double JD0,D,D0,GST,TG;
//julian date of previous midnight
if((JD-int(JD))>0.5)
JD0=int(JD)+0.5;
else
JD0=int(JD)-0.5;

//number of days and fraction from 2000 January
D=JD-2451545.0;
D0=JD0-2451545.0;

TG = D/36525;

//greenwich sidereal time in hours:
GST = 6.697374558+0.06570982441908*D0+1.00273790935*HG+0.000026*TG*TG;
while(GST>2*M_PI)
GST=GST-2*M_PI;
while(GST<2*M_PI)
GST=GST+2*M_PI;

return GST;
}


//------------------------------------------------------------------------
bool checkshadow(double rsat[3], double JD, double T)
{ bool cien,JDn;
double dsh,hsh,minsh,ssh;
double dni, godz, minuty, sekundy;

dni=floor(T/(24.0*3600.0));
godz=floor((T-dni*(24.0*3600.0))/3600.0);
minuty=floor(((T-dni*(24.0*3600.0))-godz*3600.0)/60.0);
sekundy=floor((((T-dni*(24.0*3600.0))-godz*3600.0)-minuty*60.0));

dsh=d+dni;
hsh=h+godz;
minsh=m+minuty;
ssh=s+sekundy;

JDn=FormMain->julian(yr,mo,dsh,hsh,minsh,ssh);
cien=FormMain->shadow(rsat,JDn);
return cien;

}

//----------------------------------------------------------------------

void cieniuj(double JD, double T)
{
double polsat[3];
int p;
for(p=0;p<num;p++)
{
polsat[0]=sat[p].x;
polsat[1]=sat[p].y;
polsat[2]=sat[p].z;

if(checkshadow(polsat,JD,T))
{ /*
sat[p].r=0.2;
sat[p].g=0.2;
sat[p].b=0.2;*/

}
else
{
sat[p].r=sat[p].rs;
sat[p].g=sat[p].gs;
sat[p].b=sat[p].bs;
}
}
}
void __fastcall TFormMain::Perturbation1Click(TObject *Sender)
{
pert->Visible=true;
}
//---------------------------------------------------------------------------



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627757
    • Total Posts
      2978950
  • Similar Content

    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
  • Popular Now