예제 #1
0
void ClothDemo::Render()
{
	DrawGrid(Vector3(20, 0, 20));

	glTranslatef(-2, 8, -2);
	glRotatef(45, 0, 1, 0);

	cloth.draw();

	const static GLfloat lightPosition[] = { 0, 3, 8, 0 };

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
	glEnable(GL_LIGHT0);
	glEnable(GL_COLOR_MATERIAL);
	glPushMatrix();
	glTranslatef(sphere.pos.x, sphere.pos.y, sphere.pos.z);
	glColor3f(0.9f, 1.0f, 0.0f);
	glutSolidSphere(sphere.radius - 0.1, 50, 50);
	glPopMatrix();
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);
}
예제 #2
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glClearColor(1, 1, 1, 0); //white background
	glEnable(GL_LIGHTING);

	Vector ballLocation(10, -5, 5); 
	float timeStep = .5;
	float radius = 3;
	//cloth
	cloth.clothCalculations(); 
	cloth.gravity(Vector(0, 0, 0.2)*timeStep);
	cloth.ballCollision(ballLocation, radius); 

	glTranslatef(-5, 5, -10);
	glRotatef(120, 1, 0, 0); 
	cloth.draw(); 
	//ball
	glPushMatrix();
		glColor3f(0.0f, 0.0f, 1.0f);  //blue
		glTranslatef(ballLocation.v[0], ballLocation.v[1], ballLocation.v[2]); 
		glutSolidSphere(radius-.1, 20, 20); 
	glPopMatrix();

	glutSwapBuffers();
	glutPostRedisplay();
}