그래픽스 실습 4.27
Sorce Bank 2010. 4. 27. 15:56
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | #include<iostream> #include <gl glut.h=""> void draw_axes(); void init(); void draw_drag(); void display( void ); void mouse( int button, int status, int x, int y); void motion( int , int ); int last_x,last_y; //last (x,y) position , where the left button pressed. int current_x, current_y; // current (x,y) position bool b_draw_dragbox = false ; int main() { glutCreateWindow( "TransFormation" ); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); init(); glutMainLoop(); return 0; } void init() { glClearColor(1.0f,1.0f,1.0f,1.0f); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set the current camera // f) extrinsic camera property, which can be specified by GL_MODELVIEW matirix // s) intrinsic camera property, which can be specified by GL_PROJECTION matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1,1,- 1,1 ,-1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // M = I gluLookAt(0, 0, 1, 0, 0, 0, 0, 1 , 0); draw_axes(); // Object를 조작함. //glRotatef(75.0f,0,0,1); // R 메트릭스 M *=R => M=R //glScalef(2.0f,2.0f,2.0f); // S 메트릭스 M *=S => M=RS glTranslatef(0.3f,0.3f,0.0f); // T 메트릭스 M *=T => M=RST // T ( S ( Rx)) // Model Matrix Continue.... M' = RSTx => T먼저 적용됨. // Draw DragBox if (b_draw_dragbox) draw_drag(); //Drawing an object (a red box) // Object는 절대 건들이지 않는다. 메트릭스만 곱해서 조절 ->그리는건 조형대 애들이. glColor3f(1.0f,0.0f,0.0f); glBegin(GL_QUADS); // ------------------------------- glVertex2f(0.5f,0.5f); glVertex2f(-0.5f,0.5f); // x메트릭스 glVertex2f(-0.5f,-0.5f); glVertex2f(0.5f,-0.5f); // ------------------------------- glEnd(); // = > Tx glFlush(); } void draw_drag() { glColor3f(0.0f,1.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex2f(last_x,last_y); glVertex2f(last_x,current_y); glVertex2f(current_x,current_y); glVertex2f(current_x,last_y); glEnd(); printf ( "adfasd" ); } void draw_axes() { glMatrixMode(GL_MODELVIEW); glBegin(GL_LINES); glColor3f(1.0f,0.0f,0.0f); glVertex2d(-5,0); glVertex2d(5,0); glColor3f(1.0f,1.0f,0.0f); glVertex2d(0,-5); glVertex2d(0,5); glEnd(); glFlush(); } void mouse( int button, int state, int x, int y) { if ( button == GLUT_LEFT_BUTTON&& state == GLUT_DOWN) { printf ( "left mouse button is pressed!\n" ); last_x = x; last_y = y; b_draw_dragbox= true ; // 네모 그리고 } else if ( button == GLUT_LEFT_BUTTON && state == GLUT_UP) { printf ( "left mouse button is Releassed!\n" ); b_draw_dragbox= false ; // 네모지우고 } } void motion( int x, int y) { current_x =x; current_y = y; printf ( "mouse is dragging : x : %d y: %d \n" ,x,y); } </gl></iostream> |
'Sorce Bank' 카테고리의 다른 글
Python HW 2번문제 (0) | 2010.05.06 |
---|---|
Python HW 1번문제 (0) | 2010.05.06 |
파이썬 c API 하다 만거 (0) | 2010.04.15 |
네트워크 홈워크 1 (0) | 2010.03.25 |
GeneralTree to BinaryTree (2) | 2010.03.18 |