void display() { glClear( GL_COLOR_BUFFER_BIT ); Origami.draw( View.eyePosition() ); if( State.drawAxis ) { glBegin(GL_LINES); glColor3ub(255, 0, 0); glVertex3d(-20.0,0.0,0.0); glColor3ub(255,255,255); glVertex3d( 0.0,0.0,0.0); glVertex3d(0.0,0.0,0.0); glColor3ub(255, 0, 0); glVertex3d( 20.0,0.0,0.0); glColor3ub( 0,255, 0); glVertex3d(0.0,-20.0,0.0); glColor3ub(255,255,255); glVertex3d(0.0, 0.0,0.0); glVertex3d(0.0,0.0,0.0); glColor3ub( 0,255, 0); glVertex3d(0.0, 20.0,0.0); glColor3ub( 0, 0,255); glVertex3d(0.0,0.0,-20.0); glColor3ub(255,255,255); glVertex3d(0.0,0.0, 0.0); glVertex3d(0.0,0.0,0.0); glColor3ub( 0, 0,255); glVertex3d(0.0,0.0, 20.0); glEnd(); } Origami.drawAdjust(); glutSwapBuffers(); }
void folding(Vector source, Vector destination) { // Origami.listVertex(); // printf("\n"); // source.print(); View.world2window( source, Cursor3D.x, Cursor3D.y, Cursor3D.z ); Line line = View.cursorLine( Cursor3D.x, Cursor3D.y ); // line.print(); source = Origami.pickVertex( line ); glutWarpPointer( Cursor3D.x, Cursor3D.y ); // destination.print(); // printf("\n"); Origami.moveVertex( destination, View.eyePosition(), false); View.world2window( destination, Cursor3D.x, Cursor3D.y, Cursor3D.z ); Origami.releaseVertex(); }
void timer(int value) { bool redisplay = false; // modify view double angle = 1.5/double(State.fps); double delta = 1.5/double(State.fps); double deltaZ = 0.015/double(State.fps); double scale = 1.0+1.5/double(State.fps); if( Special.down(GLUT_KEY_LEFT) ) { View.twistLeft( angle ); redisplay=true; } if( Special.down(GLUT_KEY_RIGHT) ) { View.twistRight( angle ); redisplay=true; } if( Special.down(GLUT_KEY_UP) ) { View.zoom( 1.0/scale ); redisplay=true; } if( Special.down(GLUT_KEY_DOWN) ) { View.zoom( scale ); redisplay=true; } if( Key.down('4') || State.inRotation ) { View.rotateLeft( angle ); redisplay=true; } // need numlock on if( Key.down('6') ) { View.rotateRight( angle ); redisplay=true; } if( Key.down('8') ) { View.rotateUp( angle ); redisplay=true; } if( Key.down('2') ) { View.rotateDown( angle ); redisplay=true; } if( Key.down('1') ) { View.slideLeft( delta ); redisplay=true; } if( Key.down('3') ) { View.slideRight( delta ); redisplay=true; } if( Key.down('5') ) { View.lookAt( 0, 0, 40, 0, 0, 0, 0, 1, 0 ); redisplay=true; } // renew folding if( State.inFolding ) { bool inBending = false; if( Key.down('m') ) { Cursor3D.z -= deltaZ; inBending = true; }else if( Key.down('n') ) { Cursor3D.z += deltaZ; } Vector destination; View.window2world( Cursor3D.x, Cursor3D.y, Cursor3D.z, destination ); Origami.moveVertex( destination, View.eyePosition(), inBending ); View.world2window( destination, Cursor3D.x, Cursor3D.y, Cursor3D.z ); redisplay = true; }else if( State.inAnimation ) { if( Origami.play( State.fps ) ) State.inAnimation = false; redisplay = true; } if(redisplay) glutPostRedisplay(); glutTimerFunc(1000/State.fps, timer, 0); }