수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

Opengl 마우스를 이용한 회전 큐브 질문드립니다.

노을빛

2023.04.01

#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 강의도 좀 해주셨으면 ㅠㅠ

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2694618 잘몰라서 설명부탁드립니다. scanf 관련 (3) 파라 2025-05-12
2694590 이 코드가 뭐하는 코드일까요? #2 빵순 2025-05-12
2694559 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) 늘솔길 2025-05-12
2694532 네트워크에 관하여... (4) 황소자리 2025-05-12
2694503 프로그램 연산 후 바로 종료되는 현상 (6) Judicious 2025-05-11
2694450 while문질문입니다. (1) 허리품 2025-05-11
2694420 C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) 은새 2025-05-11
2694370 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 들찬 2025-05-10
2694339 putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) 미르 2025-05-10
2694316 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) 나빛 2025-05-10
2694285 언어 공부하는 과정 좀 추천해주세요! (1) 아빠몬 2025-05-09
2694258 카운터.. 질문입니다. (4) 하늘빛눈망울 2025-05-09
2694229 단순한 질문이요 (8) 여름 2025-05-09
2694202 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) 미나 2025-05-09
2694145 화면깜빡임을 없애고 싶은데요... (1) 어서와 2025-05-08
2694069 unsigned 질문입니다. 힘차 2025-05-07
2694012 전공 비전공자 개발자 (10) 말글 2025-05-07
2693984 오버로딩이 무엇인가요? (2) 헛매질 2025-05-07
2693956 PlaySound재생이 안됩니다!(C에 음악넣기) 지존 2025-05-06
2693928 &와 *의 사용에 관한 명확한 이해 제나 2025-05-06
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com