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 강의도 좀 해주셨으면 ㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |