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 강의도 좀 해주셨으면 ㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2676033 | 배열 기초연습중 발생하는 에러 ㅠㅜ... | Creative | 2024-11-23 |
2676005 | keybd_event 게임 제어 | 영글 | 2024-11-23 |
2675900 | 진짜기본적인질문 | 글길 | 2024-11-22 |
2675845 | 수정좀해주세요ㅠㅠㅠ | 해골 | 2024-11-21 |
2675797 | 병합 정렬 소스 코드 질문입니다. (2) | 도래솔 | 2024-11-21 |
2675771 | 큐의 활용이 정확히 어떻게 되죠?? | 해긴 | 2024-11-21 |
2675745 | 도서관리 프로그램 질문이요 | 도리도리 | 2024-11-20 |
2675717 | 2진수로 변환하는것! (3) | 동생몬 | 2024-11-20 |
2675599 | for문 짝수 출력하는 법 (5) | 널위해 | 2024-11-19 |
2675575 | Linux 게시판이 없어서.. | 첫삥 | 2024-11-19 |
2675545 | 구조체 이용할 때 함수에 자료 넘겨주는 것은 어떻게 해야 하나요? | 아연 | 2024-11-19 |
2675518 | 사각형 가로로 어떻게 반복해서 만드는지좀.. 내용 | 신당 | 2024-11-18 |
2675491 | !느낌표를 입력하는것은 어떻게합니까~~?ㅠㅠ (5) | 사지타리우스 | 2024-11-18 |
2675411 | 파일입출력으로 받아온 파일의 중복문자열을 제거한 뒤 파일출력 | 앨버트 | 2024-11-17 |
2675385 | 링크드리스트 주소록 질문드립니다. (1) | 겨루 | 2024-11-17 |
2675356 | 2진수를 10진수로 바꾸려고 하는데 막히네요.. | 풀잎 | 2024-11-17 |
2675297 | Prity 비트 발생기 | 한란 | 2024-11-16 |
2675249 | C책 좀 추천해 주세요 (2) | 딸기우유 | 2024-11-16 |
2675193 | 연습문제 17-1 질문입니다. | 한별나라 | 2024-11-15 |
2675172 | 소스점 | 아이뻐 | 2024-11-15 |