Exemplo n.º 1
0
//----------------------------------------------------------------------------
// Callback method called when system is idle.
void Window::idleCallback()
{
	Matrix4 transform;
	Matrix4 temp;
	Matrix4 reverseTemp;
	temp = leftArmRotation.get();
	reverseTemp = temp;
	if (walk) {
		if (forw) {
			temp.makeRotateX(degree);
			reverseTemp.makeRotateX(-degree);
			degree++;
			if (degree == 20)
				forw = !forw;
		}
		else {
			temp.makeRotateX(degree);
			reverseTemp.makeRotateX(-degree);
			std::cout << "ASD" << std::endl;
			degree--;
			if (degree == -20)
				forw = !forw;
		}
	}
	else {
		degree = 0;
		temp.identity();
		reverseTemp.identity();
	}
	transform.makeTranslate(0, -1.5, 0);
	temp = temp * transform;
	reverseTemp = reverseTemp * transform;
	transform.makeTranslate(0, 1.5, 0);
	temp = transform * temp;
	reverseTemp = transform * reverseTemp;
	leftArmRotation.set(temp);
	rightLegRotation.set(temp);
	rightArmRotation.set(reverseTemp);
	leftLegRotation.set(reverseTemp);
    displayCallback();         // call display routine to show the object
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------
// Callback method called by GLUT when window readraw is necessary or when glutPostRedisplay() was called.
void Window::displayCallback()
{

	glEnable(GL_LIGHT0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // clear color and depth buffers
	glColor3f(0, 0, 1);
	//Setting moving camera
	Matrix4 glmatrix;
	if (cam) {
		if (t == 99) {
			back = true;
		}
		if (t == 0)
			back = false;
		Vector3 upd = belzCamera.upd;
		belzCamera.set(points[t], Vector3(0,0,0), upd);
		std::cout << t << std::endl;
	}
	if (altCam) {
		glmatrix = belzCamera.getInverse();
	}
	else {
		glmatrix = camera.getInverse();
	}
	//Drawing Light Source

	Matrix4 temp;
	temp.makeTranslate(position[0], position[1], position[2]);
	setMatrix(glmatrix, temp);
	glColor3f(1, 1, 0);
	glutSolidSphere(.5, 100, 100);
	setMatrix(glmatrix);
	glLightfv(GL_LIGHT0, GL_POSITION, position);
	//glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);

	/*
	//Seting main objects
	glColor3d(1, 0, 0);
	setMatrix(glmatrix, object.getMatrix());
	glutSolidCube(2);
	temp.makeTranslate(3, 1.5, 0);
	setMatrix(glmatrix, temp);
	glColor3d(1, 0, 1);
	glutSolidCube(3); 
	temp.makeTranslate(0, 1.5, 3);
	setMatrix(glmatrix, temp);
	glColor3d(0, 1, 1);
	glutSolidCube(3);
	temp.makeTranslate(0, 1.5, -3);
	setMatrix(glmatrix, temp);
	glColor3d(1, 1, 0);
	glutSolidCube(3);
	temp.makeTranslate(-3, 1.5, 0);
	setMatrix(glmatrix, temp);
	glColor3d(1, 1, 1);
	glutSolidCube(3);

	//Setting Floor
	setMatrix(glmatrix);
	glBegin(GL_QUADS);
	glNormal3d(0, 1, 0);
	glColor3d(0.5, 0.6, 0.7);
	glVertex3d(-10, 0, -10);
	glVertex3d(-10, 0, 10);
	glVertex3d(10, 0, 10);
	glVertex3d(10, 0, -10);
	glEnd();*/
	setMatrix(glmatrix);	
	if (light) {
		Globals::shader->bind();
	}
	else
		Globals::shader->unbind();
	glutSolidTeapot(5);
	plane.animate();
	plane.draw();
	Globals::shader->unbind();
	//Drawing Bezier Curve
	glBegin(GL_LINE_STRIP);
	for (int i = 0; i < 99; i++) {
		Vector3 current = points[i];
		Vector3 next = points[i + 1];
		glLineWidth(2.5);
		glColor3f(1.0, 1.0, 0.0);
		glVertex3d(current.getX(), current.getY(), current.getZ());
		glVertex3d(next.getX(), next.getY(), next.getZ());
	}
	glEnd();

	//Drawing Head
	glActiveTexture(GL_TEXTURE0);
	temp = glmatrix;
	control.set(person.getMatrix());
	character.draw(temp, light);
	
	//Drawing Camera
	setMatrix(glmatrix, cameraObject.getMatrix());
	glColor3f(0, 1, 1);
	glutSolidSphere(.5,100,100);
	if (cam) {
		Vector3 current;
		current = points[t];
		cameraObject.set(current.getX(), current.getY(), current.getZ());
		if (automatic) {
			if (!back) {
				t++;
			}
			else {
				t--;
			}
		}
	}
	glFlush();
	glutSwapBuffers();
}