그래픽스 실습 4.27



#include
#include 


void draw_axes();
void init();
void draw_drag();
void display(void);
void mouse(int button,int status,int x, int y);
void motion(int,int);

int last_x,last_y;			//last (x,y) position , where the left button pressed.
int current_x, current_y;   // current (x,y) position 
bool b_draw_dragbox = false;

int main()
{
	glutCreateWindow("TransFormation");
	glutDisplayFunc(display);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);
	init();
	
	glutMainLoop();

	return 0;
}

void init()
{

	glClearColor(1.0f,1.0f,1.0f,1.0f);

}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// set the current camera
	// f) extrinsic camera property, which can be specified by GL_MODELVIEW matirix
	// s) intrinsic camera property, which can be specified by GL_PROJECTION matrix

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1,1,- 1,1 ,-1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();														// M = I
	gluLookAt(0, 0, 1, 0, 0, 0, 0, 1 , 0);
	
	draw_axes();
	// Object를 조작함.
	//glRotatef(75.0f,0,0,1);											// R 메트릭스    M *=R   => M=R 
	//glScalef(2.0f,2.0f,2.0f);										// S 메트릭스		M *=S   => M=RS
	glTranslatef(0.3f,0.3f,0.0f);										// T 메트릭스		M *=T   => M=RST
																				// T ( S ( Rx))
	// Model Matrix Continue....																		M'  = RSTx    => T먼저 적용됨.

	// Draw DragBox
	if(b_draw_dragbox)
		draw_drag();

	

	//Drawing an object (a red box)
	// Object는 절대 건들이지 않는다. 메트릭스만 곱해서 조절 ->그리는건 조형대 애들이. 
	glColor3f(1.0f,0.0f,0.0f);
	glBegin(GL_QUADS);
	// -------------------------------
	glVertex2f(0.5f,0.5f);
	glVertex2f(-0.5f,0.5f);											// x메트릭스
	glVertex2f(-0.5f,-0.5f);
	glVertex2f(0.5f,-0.5f);
	// -------------------------------
	glEnd();
																				//  = > Tx
	glFlush();


}

void draw_drag()
{
	glColor3f(0.0f,1.0f,0.0f);
	glBegin(GL_LINE_LOOP);
	glVertex2f(last_x,last_y);
	glVertex2f(last_x,current_y);
	glVertex2f(current_x,current_y);
	glVertex2f(current_x,last_y);
	glEnd();
	printf("adfasd");

}
void draw_axes()
{
	glMatrixMode(GL_MODELVIEW);
	glBegin(GL_LINES);

	glColor3f(1.0f,0.0f,0.0f);
	glVertex2d(-5,0);
	glVertex2d(5,0);


	glColor3f(1.0f,1.0f,0.0f);
	glVertex2d(0,-5);
	glVertex2d(0,5);
	glEnd();
	glFlush();

}

void mouse(int button,int state,int x, int y)
{
	if( button == GLUT_LEFT_BUTTON&& state == GLUT_DOWN)
	{
		printf("left mouse button is pressed!\n");
		last_x = x;
		last_y = y;
		b_draw_dragbox=true;
		// 네모 그리고 
	} else if( button == GLUT_LEFT_BUTTON && state == GLUT_UP)
	{
		printf("left mouse button is Releassed!\n");
		b_draw_dragbox=false;
		// 네모지우고
	}
}


void motion(int x,int y)
{
	current_x =x;
	current_y = y;
	printf("mouse is dragging : x : %d   y: %d \n",x,y);

}

'Sorce Bank' 카테고리의 다른 글

Python HW 2번문제  (0) 2010.05.06
Python HW 1번문제  (0) 2010.05.06
파이썬 c API 하다 만거  (0) 2010.04.15
네트워크 홈워크 1  (0) 2010.03.25
GeneralTree to BinaryTree  (2) 2010.03.18