Visualization of STL-files with OpenGL

hi @all.
it’s my first day in this forum, and one month ago i started up with opengl. i try to program a visualization software for .stl data under windows and with visual studio 2010. for now i have the data read, saved in a list of structures and visualized the triangles using GL_TRIANGLES. for now this is ok, but now i want to rotate the 3d-images around the centre of the structures.
i tried to use: glRotatef(rotation,0.0f,1.0f,0.0f);
where rotation is a GLfloat which gets incremented and decremented after pressing a button. but there is no rotation - the image moves to the left getting bigger and to the right getting smaller. where is my fault? how can i find the centre of an 3d image? and how could i rotate the image using the mouse without moving the image, but rotating in the direction i want?
thanks in advance for your tips!

Post the routine where you apply the rotation.

See my drawing code below…
As in the example setting the value for z-rotation to 1.0 the image rotates in clockwise and counterclockwise direction, dependend on decrementing or incrementing the GLfloat rotation.
In order to see anything on the screen i use GLtranslate with parameters of the mean of all x-values, y-values and an appropriate z-value plus a zoom factor. I assume that this translation avoids the proper rotations - as i stated. but without this i can’t see anything. ideas? thanks in advance

int DrawGLScene(GLvoid)
{
struct m_3Dnodes *pointer;
unsigned int through = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(rotation,0.0f,0.0f,1.0f);
glTranslatef(abs((int)meanx),abs((int)meany),350.0f+zoom);
glBegin(display);
glColor3f(0.78f,0.78f,0.75f);
glNormal3f(root->normal.x, root->normal.y, root->normal.z);
glVertex3f(root->vertex1.x, root->vertex1.y, root->vertex1.z);
glVertex3f(root->vertex2.x, root->vertex2.y, root->vertex2.z);
glVertex3f(root->vertex3.x, root->vertex3.y, root->vertex3.z);
glEnd();
pointer = root;

while (through < (num_of_facets-1))
{
	pointer = pointer->next;
	
	glBegin(display);
		glColor3f(0.78f,0.78f,0.75f);
		glNormal3f(pointer->normal.x, pointer->normal.y, pointer->normal.z);
		glVertex3f(pointer->vertex1.x, pointer->vertex1.y, pointer->vertex1.z);
		glColor3f(0.88f,0.88f,0.85f);
		glVertex3f(pointer->vertex2.x, pointer->vertex2.y, pointer->vertex2.z);
		glColor3f(0.98f,0.98f,0.95f);
		glVertex3f(pointer->vertex3.x, pointer->vertex3.y, pointer->vertex3.z);
	glEnd();
	through++;
}
pointer = root;
return TRUE;								

}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.