PDA

View Full Version : Sweeping profile create surface



AeroSujan
09-18-2011, 07:51 PM
Dear Friends
I have to create a surface by sweeping a profile. I am not able to get it. Please help me someone. I am trying like this.

GLvoid CRevolutionProjView::drawOutline( GLvoid )
{
int loop;
glBegin(GL_LINE_STRIP);
for( loop=0; loop<30; ++loop)
{
glVertex3f( v[loop].x, v[loop].y, v[loop].z );
}
glEnd();
}
/* Sweep the outline around the y axis */
GLvoid CRevolutionProjView::sweepOutline( GLvoid )
{
GLint loop;
for( loop = 0; loop < 2 ; ++loop )
{
float frac = (float)loop / 2; //MAXOUTLINES; /* frac will run from 0 to a bit less than 1 */
glRotatef( frac * 360, 1.0, 0.0, 0.0 );
glColor3f(1.0 - frac, 0.0, frac); /* change the colour to show up the separate outlines */
drawOutline();
}
}


I am getting some more profiles but not a shaded model of the surface. How can I get a shaded model of surface out of the profile. Please help me friends. Thanks Sujan

ZbuffeR
09-19-2011, 01:30 AM
You will not be able to use glRotate, you have to calculate yourself the matrix multiplication needed to rotate your outlines.
Then instead of drawing within the loop, store vertex values, then draw using something like GL_QUADS or GL_TRIANGLES (instead of GL_LINE_STRIP).

AeroSujan
09-19-2011, 06:51 AM
I have the vertex values in the form of startpoint and endpoint for a line and I have many lines that construct a profile........Now how can I get the values of the rotated points please tell me........In the original data there's no value of z...I know the formula for rotating a point about x-axis...That is
newPx = xcos(theta) - y sin(theta)
newPy = ysin(theta) + x cos(theta)

But how can I get the values for z...Is this formula correct please tell me... Thanks a lot for your help...

ZbuffeR
09-19-2011, 09:28 AM
Looks good, and if you rotate around z, you don't need the change it :)
Otherwise you have the full formula here :
http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml

AeroSujan
09-20-2011, 02:34 AM
Thats a really nice help ZbuffeR....Please keep in touch as I am going to apply this formula now. If I find difficulty I'll come back to you. Thanks Sujan

AeroSujan
09-21-2011, 07:10 AM
Friend Please give me some suggestions about drawing a profile and create a surface out of that.... Check my input data file.

//////////////////////////////////////////////////////////////
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
//////////////////////////////////////////////////////////////

This is how my input file for profile will look like.
1 means its a traight line. Then startPoint X, startPoint Y and endPoint X, endPoint Y......

With this I have to create a profile first. Then rotate that profile with respect to X-axis by 360 degrees...to generate a surface.

Please give me some suggestion how can I achieve this. Please help me. Thanks a lot Sujan
Please

AeroSujan
09-21-2011, 07:36 AM
/*Please check my two API for processing data...Tell me if this is correct. I am not getting the geometry with this. Thanks a lot for your help.. */


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++;
}
}
}

AeroSujan
09-22-2011, 12:30 AM
Please give me some suggestions friends. I am stuck.