stl: viewer working

git-svn-id: svn://anubis/misc/stl@9 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2007-06-03 04:11:24 +00:00
parent f49335bf37
commit 09b6b4ee69

View File

@ -41,7 +41,7 @@ void reshape(GLsizei w, GLsizei h)
gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 10000.0); gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 10000.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0, 0.0, -3); glTranslatef(0.0, 0.0, -10);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -81,6 +81,7 @@ int main(int argc, char *argv[])
reshape(WIDTH, HEIGHT); reshape(WIDTH, HEIGHT);
display(); display();
SDL_Event event; SDL_Event event;
int dragging = 0;
while (SDL_WaitEvent(&event)) while (SDL_WaitEvent(&event))
{ {
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
@ -89,16 +90,25 @@ int main(int argc, char *argv[])
{ {
if (event.key.keysym.sym == SDLK_ESCAPE) if (event.key.keysym.sym == SDLK_ESCAPE)
break; break;
else if
} }
else if (event.type == SDL_MOUSEDOWN) else if (event.type == SDL_MOUSEBUTTONDOWN)
{ {
if (event.button.button == 1)
dragging = 1;
} }
else if (event.type == SDL_MOUSEUP) else if (event.type == SDL_MOUSEBUTTONUP)
{ {
if (event.button.button == 1)
dragging = 0;
} }
else if (event.type == SDL_MOUSEMOTION) else if (event.type == SDL_MOUSEMOTION)
{ {
if (dragging)
{
glRotatef(event.motion.xrel, 0, 1, 0);
glRotatef(event.motion.yrel, 0, 0, 1);
display();
}
} }
} }
@ -119,7 +129,6 @@ GLuint buildDL(void)
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for (i = 0; i < n_faces; i++) for (i = 0; i < n_faces; i++)
{ {
#if 0
if (stl_attr_color_valid(stl_face(stl, i).attribute)) if (stl_attr_color_valid(stl_face(stl, i).attribute))
{ {
color[0] = stl_attr_color_r(stl_face(stl, i).attribute) / (float) 255; color[0] = stl_attr_color_r(stl_face(stl, i).attribute) / (float) 255;
@ -131,7 +140,6 @@ GLuint buildDL(void)
else if (!dfltClrAct) else if (!dfltClrAct)
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
default_color); default_color);
#endif
stl_get_face_normal(stl, i, normal); stl_get_face_normal(stl, i, normal);
// printf("normal: %f, %f, %f\n", // printf("normal: %f, %f, %f\n",
// normal[0], normal[1], normal[2]); // normal[0], normal[1], normal[2]);
@ -145,6 +153,7 @@ GLuint buildDL(void)
// stl_face(stl, i).vertices[j][2]); // stl_face(stl, i).vertices[j][2]);
glVertex3fv(stl_face(stl, i).vertices[j]); glVertex3fv(stl_face(stl, i).vertices[j]);
} }
// printf("attribute: 0x%x\n", stl_face(stl, i).attribute);
} }
glEnd(); glEnd();
glEndList(); glEndList();