Esempio n. 1
0
void display()
{
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glMatrixMode(GL_MODELVIEW);

	/** Todo: Create your own affine transformation matrix here*/
	glLoadIdentity();
	// rotation 
	glMultMatrixf(camera.rotate.m);
	gluLookAt(camera.position.x, camera.position.y, camera.position.z, 
			  camera.lookAt.x,   camera.lookAt.y,   camera.lookAt.z, 
			  camera.up.x,       camera.up.y,       camera.up.z);
	
	// world coordinate
	glPushMatrix();	
	
	glBegin(GL_LINES);	
	    // x axis
		glColor3f(1.0, 0.0, 0.0);
		glVertex3f(0.0, 0.0, 0.0);
		glVertex3f(500.0, 0.0, 0.0);
		// y axis
		glColor3f(0.0, 1.0, 0.0);
		glVertex3f(0.0, 0.0, 0.0);
		glVertex3f(0.0, 500.0, 0.0);
		// z axis
		glColor3f(0.0, 0.0, 1.0);
		glVertex3f(0.0, 0.0, 0.0);
		glVertex3f(0.0, 0.0, 500.0);	
	glEnd();

	glPopMatrix();

	/** Todo: Draw Model (clipping and non-clipping version)*/

	glPushMatrix();
	//glScalef(model.scale.x, model.scale.y, model.scale.z);
	//glTranslatef(model.translate.x, model.translate.y, model.translate.z);
	
	glMultMatrixf(model.scale.m);
	glMultMatrixf(model.translate.m);

	glMultMatrixf(model.shear.m);
	glMultMatrixf(model.rotate.m);
	glGetFloatv(GL_MODELVIEW_MATRIX, mModelView.m);
	model.drawAxes();
	model.drawBox();
	
	if(doClipping) 
		drawModelClipping();
	else
		model.drawModel();
	
	glPopMatrix();
    
	// clipping field
	if(doClipping)
	{
		glPushMatrix(); 
		glLoadIdentity(); 
		glMatrixMode(GL_PROJECTION); 
		glPushMatrix(); 
		glLoadIdentity();
		glColor3f(1.0, 1.0, 0.0);
		glBegin(GL_QUADS); 
			glVertex3f(2.0 * xMin / windowWidth, 2.0 * yMin / windowHeight, -1.0); 
			glVertex3f(2.0 * xMax / windowWidth, 2.0 * yMin / windowHeight, -1.0); 
			glVertex3f(2.0 * xMax / windowWidth, 2.0 * yMax / windowHeight, -1.0); 
			glVertex3f(2.0 * xMin / windowWidth, 2.0 * yMax / windowHeight, -1.0); 
		glEnd();
		glPopMatrix(); 
		glMatrixMode(GL_MODELVIEW); 
		glPopMatrix(); 
	}

	glutSwapBuffers();
}