Opengl 마우스를 이용한 회전 큐브 질문드립니다.
노을빛
#include windows.h // standard header for most programs#include gl/gl.h // the gl header file#include gl/glut.h // the gl utility toolkit (glut) header// create main function for bringing it all together
float rtri; // angle for the trianglefloat rquad; // angle for the quad// create some everyday functionsvoid init(glvoid){glshademodel(gl_smooth); // enable smooth shadingglclearcolor(0.0f, 0.0f, 0.0f, 0.5f); // black backgroundglcleardepth(1.0f); // depth buffer setupglenable(gl_depth_test); // enables depth testinggldepthfunc(gl_lequal); // the type of depth testing to doglenable(gl_color_material);}// create the reshape function (the viewport)void reshape(int w, int h){glviewport(0, 0, w, h);glmatrixmode(gl_projection); // select the projection matrixglloadidentity( ); // reset the projection matrix// calculate the aspect ratio of the windowif (h == 0) gluperspective(80, (float) w, 1.0, 5000.0);else gluperspective(80, (float)w / (float)h, 1.0, 5000.0);glmatrixmode(gl_modelview); // select the model view matrixglloadidentity( ); // reset the model view matrix}
// create keyboard functionvoid keyboard(unsigned char key, int x, int y){switch (key) {case 27: // when escape is pressed...exit(0); // exit the programbreak; // ready for next casedefault: // now wrap it upbreak;}}// create special function (required for arrow keys)void arrow_keys(int a_keys, int x, int y){switch (a_keys) {case glut_key_up: // when up arrow is pressed...glutfullscreen(); // go into full screen modebreak;case glut_key_down: // when down arrow is pressed...glutreshapewindow(500, 500); // go into a 500 by 500 windowbreak;default:break;}}//create the display functionvoid display(void){glclear(gl_color_buffer_bit| gl_depth_buffer_bit);glloadidentity( );glpushmatrix();gltranslatef(-1.5f, 0.0f, -6.0f);glrotatef(rtri, 0.0f, 1.0f, 0.0f);glbegin(gl_triangles);glcolor3f(1.0f,0.0f,0.0f); // redglvertex3f( 0.0f, 1.0f, 0.0f); // top of triangle (front)glcolor3f(0.0f,1.0f,0.0f); // greenglvertex3f(-1.0f,-1.0f, 1.0f); // left of triangle (front)glcolor3f(0.0f,0.0f,1.0f); // blueglvertex3f( 1.0f,-1.0f, 1.0f); // right of triangle (front)glcolor3f(1.0f,0.0f,0.0f); // redglvertex3f( 0.0f, 1.0f, 0.0f); // top of triangle (right)glcolor3f(0.0f,0.0f,1.0f); // blueglvertex3f( 1.0f,-1.0f, 1.0f); // left of triangle (right)glcolor3f(0.0f,1.0f,0.0f); // greenglvertex3f( 1.0f,-1.0f, -1.0f); // right of triangle (right)glcolor3f(1.0f,0.0f,0.0f); // redglvertex3f( 0.0f, 1.0f, 0.0f); // top of triangle (back)glcolor3f(0.0f,1.0f,0.0f); // greenglvertex3f( 1.0f,-1.0f, -1.0f); // left of triangle (back)glcolor3f(0.0f,0.0f,1.0f); // blueglvertex3f(-1.0f,-1.0f, -1.0f); // right of triangle (back)glcolor3f(1.0f,0.0f,0.0f); // redglvertex3f( 0.0f, 1.0f, 0.0f); // top of triangle (left)glcolor3f(0.0f,0.0f,1.0f); // blueglvertex3f(-1.0f,-1.0f,-1.0f); // left of triangle (left)glcolor3f(0.0f,1.0f,0.0f); // greenglvertex3f(-1.0f,-1.0f, 1.0f); // right of triangle (left)glend( );glloadidentity( );gltranslatef(1.5f,0.0f,-6.0f);glrotatef(rquad, 1.0f, 0.0f, 0.0f);glbegin(gl_quads);glcolor3f(0.0f,1.0f,0.0f); // set the color to blueglvertex3f( 1.0f, 1.0f,-1.0f); // top right of the quad (top)glvertex3f(-1.0f, 1.0f,-1.0f); // top left of the quad (top)glvertex3f(-1.0f, 1.0f, 1.0f); // bottom left of the quad (top)glvertex3f( 1.0f, 1.0f, 1.0f); // bottom right of the quad (top)glcolor3f(1.0f,0.5f,0.0f); // set the color to orangeglvertex3f( 1.0f,-1.0f, 1.0f); // top right of the quad (bottom)glvertex3f(-1.ex3f(-1.0f,-1.0f, 1.0f); // top left of the quad (bottom)glvertex3f(-1.0f,-1.0f,-1.0f); // bottom left of the quad (bottom)glvertex3f( 1.0f,-1.0f,-1.0f); // bottom right of the quad (bottom)glcolor3f(1.0f,0.0f,0.0f); // set the color to redglvertex3f( 1.0f, 1.0f, 1.0f); // top right of the quad (front)glvertex3f(-1.0f, 1.0f, 1.0f); // top left of the quad (front)glvertex3f(-1.0f,-1.0f, 1.0f); // bottom left of the quad (front)glvertex3f( 1.0f,-1.0f, 1.0f); // bottom right of the quad (front)glcolor3f(1.0f,1.0f,0.0f); // set the color to yellowglvertex3f( 1.0f,-1.0f,-1.0f); // bottom left of the quad (back)glvertex3f(-1.0f,-1.0f,-1.0f); // bottom right of the quad (back)glvertex3f(-1.0f, 1.0f,-1.0f); // top right of the quad (back)glvertex3f( 1.0f, 1.0f,-1.0f); // top left of the quad (back)glcolor3f(0.0f,0.0f,1.0f); // set the color to blueglvertex3f(-1.0f, 1.0f, 1.0f); // top right of the quad (left)glvertex3f(-1.0f, 1.0f,-1.0f); // top left of the quad (left)glvertex3f(-1.0f,-1.0f,-1.0f); // bottom left of the quad (left)glvertex3f(-1.0f,-1.0f, 1.0f); // bottom right of the quad (left)glcolor3f(1.0f,0.0f,1.0f); // set the color to violetglvertex3f( 1.0f, 1.0f,-1.0f); // top right of the quad (right)glvertex3f( 1.0f, 1.0f, 1.0f); // top left of the quad (right)glvertex3f( 1.0f,-1.0f, 1.0f); // bottom left of the quad (right)glvertex3f( 1.0f,-1.0f,-1.0f); // bottom right of the quad (right)glend( );glpopmatrix( );rtri += 0.02f;rquad -= 0.015f;glutswapbuffers( );}
void main(int argc, char** argv){glutinit(&argc, argv);glutinitdisplaymode(glut_rgb | glut_double);glutinitwindowsize(500, 500);glutcreatewindow(opengl programmig);init( );glutdisplayfunc(display);glutreshapefunc(reshape);glutkeyboardfunc(keyboard);glutspecialfunc(arrow_keys);glutidlefunc(display);glutmainloop( );}
======================================================================================
rotation 하는 직육면체와 삼각뿔 예제인데요.
이 예제를 마우스 움직임에 따라 rotaion하게 만들고 싶은데 어떻게 구성해야할지 모르겠습니다.
main 메소드쪽에 glutmousefunc(); 를 추가하고 어떻게 해야할지 막막하네요.
윤성수다님 opengl 강의도 좀 해주셨으면 ㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2685477 | 소수점이하 출력하는거요 | 널위해 | 2025-02-18 |
2685449 | printf배우고있는데요 궁금한게있어요 (8) | 꽃큰 | 2025-02-18 |
2685393 | c언어 질문이요.... | 붕붕 | 2025-02-18 |
2685365 | 윈도우7에서 visual studio c++6.0 (1) | 빛길 | 2025-02-17 |
2685317 | segmentation fault가 나요 | 가람 | 2025-02-17 |
2685292 | 다중스택질문 | 올해1살 | 2025-02-17 |
2685231 | C언어와 닷넷에 대해서 질문!! (2) | 설아 | 2025-02-16 |
2685206 | VisualBasic 과 DEV++ 의 장단점과 만든 파일 호환 가능하나요? | 에드워드 | 2025-02-16 |
2685154 | 배열 크기조절 | 해찬솔 | 2025-02-15 |
2685124 | 수정이거 제가 뭐가 잘못한거죠 ? | 아이돌 | 2025-02-15 |
2685096 | 포인터의 고수분들 모두 보세요!! 제발 ㅠ_ㅠ 헷갈려헷갈려..갈려헷.. (7) | 치킨마루 | 2025-02-15 |
2685045 | 전처리기 질문 | 치에미 | 2025-02-14 |
2685016 | 오류 좀 확인해 주시면 감사하겠습니다 | 초코맛사탕 | 2025-02-14 |
2684917 | 알고리즘을 이용한 행렬의 전치// 문제다운 문제네요. | 뿡뿡 | 2025-02-13 |
2684868 | 양방향 연결리스트에서 실행도중 죽는 이유좀 찾아주세요. (2) | 예다움 | 2025-02-13 |
2684844 | 시계프로그램인데 도저히 모르겠어요ㅠ (1) | 비내리던날 | 2025-02-12 |
2684812 | 레포트좀도와주세요ㅠㅠ (2) | 갈매빛 | 2025-02-12 |
2684780 | 채팅창 흉내내보려고하는데요 ㅜ.ㅜ (1) | 바름 | 2025-02-12 |
2684729 | 내일 시험인데 메모리 그리는것좀 도와주세요 ㅠ (1) | 상처주지마 | 2025-02-11 |
2684701 | 버퍼 관련 질문 3가지 (이전거랑 달라요) | 한국녀 | 2025-02-11 |