opengl의 마우스 이벤트에 관해서

Kirics의 이미지

#include <glut.h>
#include <GLU.h>
#include <stdio.h>
#define TRUE 1
#define FALSE 0
static int SpinAngle = 0;
 
 
 
 
 
void InitLight(){
	GLfloat light0_ambient[] = {0.5, 0.4, 0.3, 1.0};
	GLfloat light0_diffuse[] = {0.8, 0.7, 0.6, 1.0};
	GLfloat light0_specular[] = {1.0, 1.0, 1.0, 1.0};
 
	GLfloat material_ambient[] = {0.4, 0.4, 0.4, 1.0};
	GLfloat material_diffuse[] = {0.9, 0.9, 0.9, 1.0};
	GLfloat material_specular[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat material_shininess[] = {25.0};
 
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
	}
 
	void MyDisplay(){
		GLfloat LightPosition[] = {0.0, 0.0, 1.5, 1.0};
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glPushMatrix();
		glTranslatef(0.0, 0.0, -5.0);
		glPushMatrix();
			glRotatef(SpinAngle, 1.0, 0.0, 0.0);
			glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
			glTranslatef(0.0, 0.0, 1.5);
			glDisable(GL_LIGHTING);
			glColor3f(0.9, 0.9, 0.9);
			glutWireSphere(0.06, 10, 10);
			glEnable(GL_LIGHTING);
		glPopMatrix();
		glutSolidSphere(1.0, 400, 400);
		glPopMatrix();
		glFlush();
	}
 
	void MyReshape(int w, int h){
		glViewport(0, 0, (GLsizei)w, (GLsizei)h);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(40.0, (GLfloat)w/(GLfloat)h, 1.0, 20.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
	}
 
	void MyTimer(int Value){			
	SpinAngle = SpinAngle +15;
	glutPostRedisplay();
	glutTimerFunc(50,MyTimer, 1);
    }
 
	void MyMouse(int button, int state, int x, int y){
		switch(button){
		case GLUT_LEFT_BUTTON:
			if(state == GLUT_DOWN){
				SpinAngle = (SpinAngle + 15) % 360;				
				glutPostRedisplay();
			}
			break;
 
 
 
 
		case GLUT_RIGHT_BUTTON:
			if(state == GLUT_DOWN){
				SpinAngle = (SpinAngle + -15) % 360;
				glutPostRedisplay();
			}
 
			break;
		default:
			break;
		}
 
	}
 
 
	int main(int argc, char** argv){
		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
		glutInitWindowSize(500, 500);
		glutInitWindowPosition(100, 100);
		glutCreateWindow("OpenGL Sample Drawing");
		InitLight();
		glutDisplayFunc(MyDisplay);
		glutReshapeFunc(MyReshape);
		glutMouseFunc(MyMouse);
		glutTimerFunc(50, MyTimer, 1);
		glutMainLoop();
		return 0;
	}
 
 
책에도 있는 간단한 예제에 추가를 하는건데요
마우스 왼쪽버튼을 눌렀을 시엔 아래로 한칸 오른쪽 버튼을 눌렀을 시엔 위로한칸이 움직이고
마우스 왼쪽버튼을 계속 누르고 있을시에는 아래쪽으로 계속 회전을 할수 있게 하고싶은데 
타이머 콜백을 준후에 마우스 이벤트를 어떻게 줘야될지 모르겠습니다..
 
초보에게 도움을 주세요 ;ㅅ;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.