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 강의도 좀 해주셨으면 ㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2658192 | C언어기초3문제 (3) | 해샘찬 | 2024-06-13 |
2658165 | 로또게임질문 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ | 내꽃 | 2024-06-13 |
2658136 | 구조체 부분에서 막혔습니다.. (3) | 난슬 | 2024-06-13 |
2658106 | c언어 간단한 질문입니다 (4) | 아잉누님 | 2024-06-13 |
2658077 | security가 붙은 함수 관련 질문 | 횃대비 | 2024-06-12 |
2658050 | 기초 c언어 프로그램 짜는데 어려워서 글올려요 | 꺆잉 | 2024-06-12 |
2658021 | #define 문 정말 간단한 질문있습니다. | 심플포텐 | 2024-06-12 |
2657962 | IPv6에서 RAS 사용요 | 상1큼한렩 | 2024-06-11 |
2657935 | 도와주세요 배열및 함수관련. (4) | 하루키 | 2024-06-11 |
2657885 | 두개의 소문자입력뒤 비트연산자로 대문자오바꾸기 | 풀잎 | 2024-06-11 |
2657830 | 경우의 수 구하기.. (1) | 흰우유 | 2024-06-10 |
2657806 | 연산자 질문요 (1) | 네코 | 2024-06-10 |
2657782 | 콘솔창 꽉채우기 | 미쁘다 | 2024-06-10 |
2657754 | 유니코드 기반으로 문자 입출력받는데 안됩니다 | 어리버리 | 2024-06-09 |
2657728 | 포인터 배열도 동적할당(malloc)를 통해서 생성이 가능한가요? | 우미 | 2024-06-09 |
2657700 | 오류 해석을 못하겠어요. | 해길 | 2024-06-09 |
2657642 | 출력부분에서.. | 앨버트 | 2024-06-08 |
2657620 | 파일 입출력 함수 반복문 .. | 서리서리 | 2024-06-08 |
2657594 | 인수의 존재 여부를 검사 (1) | 다이 | 2024-06-08 |
2657566 | 서비스팩을 설치하더니 잘되는데요.... | 감추어왔던 | 2024-06-08 |