Supportnet Computer
Planet of Tech

Supportnet / Forum / Anwendungen(Java,C++...)

C++/OpenGL turtle painting





Frage

hi ihr da :-) ich hab folgendes programm bisher geschrieben: #include <iostream> #include <GL/glut.h> #include <stdlib.h> float movex = 0.0; float movey = 0.0; static GLint dreieck; static GLint paint = 0 ; //whether paint or not void drawTriangle(void){ glBegin(GL_TRIANGLES); // Drawing Using Triangles glVertex3f(0.0f, 0.2f, 0.0f); // Top glVertex3f(-0.2f,-0.2f, 0.0f); // Bottom Left glVertex3f(0.2f,-0.2f, 0.0f); // Bottom Right glEnd(); } void init(void){ glClearColor(1.0, 1.0, 1.0, 1.0); dreieck = glGenLists(1); glNewList(dreieck, GL_COMPILE); glEndList(); } static void painting(void) { //static GLfloat red[4] = {3.0, 0.1, 0.0, 1.0}; //static GLfloat green[4] = {0.1, 3.0, 0.0, 1.0}; //static GLfloat blue[4] = {0.0, 0.0, 3.0, 1.0}; float x,y,z; glBegin(GL_LINES); glColor3f(3.0,0.0,0.0); x = movex; y = movey; z = 0.0; glVertex3f(x,y,z); x += movex; y += movey; z = 0.0; glVertex3f(x,y,z); glEnd(); glutPostRedisplay(); } static void onReshape(int width, int height){ float ar; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); ar=(float) width / (float) height; glFrustum(-ar, ar, -1.0, 1.0, 0.5, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -1.0); glutPostRedisplay(); } static void onDisplay(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0.0, 0.0, 0.0); drawTriangle(); glutSwapBuffers(); } static void onIdle(void){ glutPostRedisplay(); } static void onKeyPress(unsigned char key, int x, int y){ switch(key){ case ' ': // to pause/restart painting with the space bar paint = !paint ; if (paint) glutIdleFunc(painting) ; else glutIdleFunc(NULL) ; break ; case 27: exit(0); break; } } static void onSpecialKey( int k, int x, int y) { switch ( k) { case GLUT_KEY_UP: glTranslatef(0.0, 0.1, 0.0); //movey += 0.1; break; case GLUT_KEY_DOWN: glTranslatef(0.0, -0.1, 0.0); break; case GLUT_KEY_LEFT: glTranslatef(-0.1, 0.0, 0.0); break; case GLUT_KEY_RIGHT: glTranslatef(0.1, 0.0, 0.0); break; default: return; } glutPostRedisplay(); } int main (int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(640, 480); glutCreateWindow("Test"); init(); glutReshapeFunc(onReshape); glutDisplayFunc(onDisplay); glutSpecialFunc(onSpecialKey); glutKeyboardFunc(onKeyPress); glutIdleFunc(painting); glutMainLoop(); return 0; } das ding zeichnet mir ein dreieck, dass ich in meinem canvas auf der x und y achse rumschieben kann nun soll, wenn man die leertaste drückt, angefangen werden zu zeichen (ob vom mittelpunkt des dreiecks, oder einem seiner ecken is mir wurscht) - ein einfacher strich. dabei soll der strich immer meiner bewegung des dreiecks folgen und solange gezeichnet werden, bis ich wieder die leertaste drücke. ich bin schon recht stolz auf mich, soweit gekommen zu sein. aber ich hab keine ahnung, wie es ab da weitergehen könnte/sollte. jemand ne idee? :-)

Antwort von



Ich möchte kostenlos eine Frage an die Mitglieder stellen:


Ähnliche Themen:


Suche in allen vorhandenen Beiträgen: