PDA

View Full Version : Object displayed in all three directions..!!!



saurabhsb
02-10-2014, 04:36 AM
Hi guys, I am new to OpenGL and trying to read point data and display it in the openGL window. I am able to read the point cloud data from .stl file but the I am facing a problem. The point cloud data is being displayed in all three directions. I am attaching the image here.. If it is not displayed right click and say 'open image in new tab'
https://www.dropbox.com/s/jh4t6ew8bgfodvz/Capture.JPG

I have used ZPR module for zoom pan and rotate developed by Nigel Stewart which is available on the net.
I changed some code in their zprdemo.cpp file in order to satisfy my requirements. In the drawAxes function, they have used glPushMatrix and glPullMatrix along with glRotatef to rotate the direction of cone. (which forms the representation of 3 axes)



void drawAxes()
{
GLERROR;
glPushMatrix();
/* No name for grey sphere */

glColor3f(0.3,0.3,0.3);
glutSolidSphere(0.7, 20, 20);

glPushMatrix();
glPushName(1); /* Red cone is 1 */
glColor3f(1,0,0);
glRotatef(90,0,1,0);
glutSolidCone(0.6, 4.0, 50, 20);
glPopName();
glPopMatrix();

glPushMatrix ();
glPushName(2); /* Green cone is 2 */
glColor3f(0,1,0);
glRotatef(-90,1,0,0);
glutSolidCone(0.6, 4.0, 50, 20);
glPopName();
glPopMatrix();

glColor3f(0,0,1); /* Blue cone is 3 */
glPushName(3);
glutSolidCone(0.6, 4.0, 50, 20);
glPopName();

glPopMatrix();
drawGeometry(); //MY FUNCTION TO PLOT POINT CLOUD DATA
GLERROR;
}

void drawGeometry()
{
GLERROR;
glColor3f(1,1,1);

/* Plotting points*/
glBegin(GL_POINTS);
for(int j=0;j<=(objVector.PointCoordinates.size()-3);j++)
{
GLfloat Xcoord= objVector.PointCoordinates[j];
GLfloat Ycoord= objVector.PointCoordinates[j+1];
GLfloat Zcoord= objVector.PointCoordinates[j+2];
glVertex3f(Xcoord,Ycoord,Zcoord);
}
glEnd();

glFlush();
GLERROR;
}

(The actual order of placing the functions in main code is obviously reversed)
At the end I have called my function to plot the points. The result which I am getting is as per the image I have attached..The bottle is plotted in all three directions. I think glRotatef matrix is making some trouble but I am not able to find it. Please help me in this issue. Thanks in advance!!

saurabhsb
02-10-2014, 05:34 AM
I found my mistake guys.. I was doing increment of j by one only. Hence it was getting plotted three times.