woshka

05-22-2013, 01:24 PM

Hello

I want to create a torus

I have found the points and it is easy to write to a file

the code works fine when we have 4 faces around for the polygon

But I don't know how to write the code so that it could be accomplished with any polygon with any number of faces

the write mesh code is as follows

void Mesh::writemesh(char *out_path){

fstream outfile;

double p=3.14;double r=3.0;

outfile.open(out_path,ios::out);

outfile<<96<<" "<<20<<" "<<134<<"\n\n";

double N=4.0;

GLfloat theta = ( 2.0f * 3.1415926536 ) / N;

for(double i=0;i<=10;i+=(p/6))

{

r+=(p/6);

for(double c=0;c<N;c++){

outfile<<r*cos(theta * c)<<" "<<r*sin(theta * c)<<" "<<i<<"\n";

}

/*outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+1.0<<" "<<(r*p/6)*sin(i)+2.0<<"\n";

outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+2.0<<" "<<(r*p/6)*sin(i)+2.0<<"\n";

outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+2.0<<" "<<(r*p/6)*sin(i)+1.0<<"\n";

outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+1.0<<" "<<(r*p/6)*sin(i)+1.0<<"\n";*/

}

outfile<<"\n";

outfile<<"0 0 0"<<"\n";

outfile<<"\n";

for(double i=0;i<48;i=i+4.0)

{

outfile<<N;

for(double j=0;j<N;j++)

{

outfile<<" "<<i+j<<" 0";

}

outfile<<"\n";

outfile<<"4 "<<i+1<<" 0 "<<i+5.0<<" 0 "<<i+6.0<<" 0 "<<i+2.0<<" 0"<<"\n";

outfile<<"4 "<<i<<" 0 "<<i+4.0<<" 0 "<<i+5.0<<" 0 "<<i+1.0<<" 0"<<"\n";

outfile<<"4 "<<i+2.0<<" 0 "<<i+6.0<<" 0 "<<i+7.0<<" 0 "<<i+3.0<<" 0"<<"\n";

outfile<<"4 "<<i<<" 0 "<<i+3.0<<" 0 "<<i+7<<" 0 "<<i+4.0<<" 0"<<"\n";

}

outfile.close();

}

I want to create a torus

I have found the points and it is easy to write to a file

the code works fine when we have 4 faces around for the polygon

But I don't know how to write the code so that it could be accomplished with any polygon with any number of faces

the write mesh code is as follows

void Mesh::writemesh(char *out_path){

fstream outfile;

double p=3.14;double r=3.0;

outfile.open(out_path,ios::out);

outfile<<96<<" "<<20<<" "<<134<<"\n\n";

double N=4.0;

GLfloat theta = ( 2.0f * 3.1415926536 ) / N;

for(double i=0;i<=10;i+=(p/6))

{

r+=(p/6);

for(double c=0;c<N;c++){

outfile<<r*cos(theta * c)<<" "<<r*sin(theta * c)<<" "<<i<<"\n";

}

/*outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+1.0<<" "<<(r*p/6)*sin(i)+2.0<<"\n";

outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+2.0<<" "<<(r*p/6)*sin(i)+2.0<<"\n";

outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+2.0<<" "<<(r*p/6)*sin(i)+1.0<<"\n";

outfile<<(4+cos(r*p/6))*cos(i)<<" "<<(4+cos(r*p/6))*cos(i)+1.0<<" "<<(r*p/6)*sin(i)+1.0<<"\n";*/

}

outfile<<"\n";

outfile<<"0 0 0"<<"\n";

outfile<<"\n";

for(double i=0;i<48;i=i+4.0)

{

outfile<<N;

for(double j=0;j<N;j++)

{

outfile<<" "<<i+j<<" 0";

}

outfile<<"\n";

outfile<<"4 "<<i+1<<" 0 "<<i+5.0<<" 0 "<<i+6.0<<" 0 "<<i+2.0<<" 0"<<"\n";

outfile<<"4 "<<i<<" 0 "<<i+4.0<<" 0 "<<i+5.0<<" 0 "<<i+1.0<<" 0"<<"\n";

outfile<<"4 "<<i+2.0<<" 0 "<<i+6.0<<" 0 "<<i+7.0<<" 0 "<<i+3.0<<" 0"<<"\n";

outfile<<"4 "<<i<<" 0 "<<i+3.0<<" 0 "<<i+7<<" 0 "<<i+4.0<<" 0"<<"\n";

}

outfile.close();

}