sujan.dasmahapa 0 Light Poster

Dear Friends
I have a dataset like below. 1 means Straight line with startPointX,startPointY,endPointX,endPointY.

//////////////////////////////////////////////////////////////
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -178.200000 52.000000 -138.200000 52.000000
1 0.000000 24.600000 0.000000 19.000000
1 -125.421613 36.515000 -138.200000 52.000000
1 -123.421613 36.515000 -107.873000 36.515000
1 -100.000000 19.000000 0.000000 19.000000
1 -105.873000 36.515000 -94.557821 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -100.000000 19.000000 0.000000 19.000000
1 0.000000 19.000000 0.000000 24.600000
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -94.557821 36.515000 -105.873000 36.515000
1 -107.873000 36.515000 -123.421613 36.515000
1 -125.421613 36.515000 -138.200000 52.000000
1 -138.200000 52.000000 -178.200000 52.000000
1 -115.000000 0.000000 -115.000000 15.000000
1 -115.000000 15.000000 -100.000000 15.000000
1 -100.000000 15.000000 -100.000000 19.000000
1 -100.000000 19.000000 0.200000 19.000000
1 0.200000 19.000000 0.000000 19.000000
1 0.000000 19.000000 0.000000 24.574923
1 0.000000 24.574923 -0.000000 24.600000
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -59.920000 36.515000 -66.103821 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -88.374000 36.515000 -94.557821 36.515000
1 -94.557821 36.515000 -105.873000 36.515000
1 -105.873000 36.515000 -107.873000 36.515000
1 -107.873000 36.515000 -123.421613 36.515000
1 -123.421613 36.515000 -125.421613 36.515000
1 -125.421613 36.515000 -138.200000 52.000000
1 -138.200000 52.000000 -178.200000 52.000000
1 -178.200000 52.000000 -178.200000 52.500000
1 -178.200000 52.500000 -178.200000 55.000000
1 -178.200000 55.000000 -190.000000 55.000000
1 5.000000 0.000000 5.000000 55.000000
1 5.000000 55.000000 -190.000000 55.000000
//////////////////////////////////////////////////////////////

I have to construct a profile which I can easily do by making a GL_LINES.

After that I need rotate the profile by x-axis and construct a surface of revolution. Please giveme some idea how can I achieve this. I have done something but I am not getting the surface.


Like I am storing the original startPoints and endPoints in an array with assuming z=0.
Then rotating each point by x-axis. so x-values will be same and y and z values I am calculating using this formula.
y = y cosq - z sinq;
z = ysinq + zcosq;

Is this correct...?? Then I am defining a number of loops and in loop I am creating GL_QUADS for each startPoint and endPoint...
1st loop 1ststartPoint, 1stLoop 1stendPoint
2nd loop 1stStartPoint, 2nd loop 1stEndPoint...


But I am not getting any 3D surface. Please help me.........Check the code below.


//////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct point3D{
float x;
float y;
float z;
}POINT3D;

int count1;
POINT3D *startPoints, *endPoints;

void CRevolutionProjView::drawProfile(CString filename)
{
pFrame->m_wndStatusBar.SetPaneText(0,L"DrawProfile !!");

// profile to be drawn

GLfloat PI = 4 * atan(1.0);

//file needs be open
double startPX, startPY, endPX, endPY;
double cenX, cenY, cenZ, rad, startA, endA;
ifstream indata; // indata is like cin
int id; // variable for input value
indata.open(filename); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
count1=0;
while ( !indata.eof() ) { // keep reading until end-of-file
indata >> id;
cout << "The id is " << id << endl;
if(id==1)
{
indata >> startPX >> startPY >> endPX >> endPY;
glBegin(GL_LINES);
glVertex2f(startPX, startPY); // origin of the line
glVertex2f(endPX, endPY); // ending point of the line
glEnd();

if(count1==0)
{
startPoints = (POINT3D *)malloc(sizeof(POINT3D));
endPoints = (POINT3D *)malloc(sizeof(POINT3D));
}
else
{
startPoints = (POINT3D *)realloc(startPoints,sizeof(POINT3D)*(count1+1));
endPoints = (POINT3D *)realloc(endPoints,sizeof(POINT3D) * (count1+1));

}
startPoints[count1].x = startPX;
startPoints[count1].y = startPY;
startPoints[count1].z = 0.0f;
endPoints[count1].x = endPX;
endPoints[count1].y = endPY;
endPoints[count1].z = 0.0f;
count1++;
}
}
indata.close();
cout << "End-of-file reached.." << endl;

}

void CRevolutionProjView::drawSurface()
{

double PI = 4.0 * atan(1.0);

//I have x and y points;

//count1 = numberof points

//theta = 0 to 360 degs.

//nsweep = number of sweeps. 360/nsweep = each angle;
int nsweep=4;

//no of profiles = nsweep + 1...

//each profile will have count1 no of lines...so count1 startpoints and count1 endPoints...

//so...total startPoints and endPoints for (nsweep+1) profiles = (nsweep+1) * count1...

POINT3D *totalStartPoints, *totalEndPoints;
totalStartPoints = new POINT3D[(nsweep+1)*count1];
totalEndPoints = new POINT3D[(nsweep+1)*count1];
int cnt1=0;
double theta, inter;
inter = (360/nsweep) * (PI/180);
theta = 0;
for(int i=0; i<(nsweep+1); i++)
{
for(int j=0; j<count1; j++)
{
totalStartPoints[cnt1].x = startPoints[j].x;
totalStartPoints[cnt1].y = startPoints[j].y * cos(theta) - startPoints[j].z * sin(theta);
totalStartPoints[cnt1].z = startPoints[j].y * sin(theta) + startPoints[j].z * cos(theta);

totalEndPoints[cnt1].x = endPoints[j].x;
totalEndPoints[cnt1].y = endPoints[j].y * cos(theta) - endPoints[j].z * sin(theta);
totalEndPoints[cnt1].z = endPoints[j].y * sin(theta) + endPoints[j].z * cos(theta);
cnt1++;
}

theta = theta + inter;
}

cnt1=0;
glColor3f(1.0f,0.0f,0.0f);
for(int i=0; i<nsweep; i++)
{
for(int j=0; j<count1; j++) {

GLfloat *v0, *v1, *v2, *v3;

v0 = new GLfloat[3];
v1 = new GLfloat[3];
v2 = new GLfloat[3];
v3 = new GLfloat[3];

v0[0] = totalStartPoints[cnt1].x;
v0[1] = totalStartPoints[cnt1].y;
v0[2] = totalStartPoints[cnt1].z;

v1[0] = totalEndPoints[cnt1].x;
v1[1] = totalEndPoints[cnt1].y;
v1[2] = totalEndPoints[cnt1].z;

v2[0] = totalEndPoints[cnt1+count1].x;
v2[1] = totalEndPoints[cnt1+count1].y;
v2[2] = totalEndPoints[cnt1+count1].z;

v3[0] = totalStartPoints[cnt1+count1].x;
v3[1] = totalStartPoints[cnt1+count1].y;
v3[2] = totalStartPoints[cnt1+count1].z;


glBegin(GL_QUADS); // draw a cube with 6 quads
glVertex3fv(v0); // front face
glVertex3fv(v1);
glVertex3fv(v2);
glVertex3fv(v3);
glEnd();
delete v0;
delete v1;
delete v2;
delete v3;
cnt1++;
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////