Example #1
0
void drawScene(void) {
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);

    glEnable(GL_LIGHTING);
    // set up the scene
    pool.render();
    basin.render();
    ground.render();
    // sky
    glDisable(GL_LIGHTING);
    skybox.render();

    // water in the air
    glDisable(GL_TEXTURE_2D);
    glColor4fv(WATER_COLOR);
    fountain.render();
    glEnable(GL_LIGHTING);

    glDisable(GL_BLEND);
}
Example #2
0
void display()									
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW); 
	


	glm::mat4 ViewMatrix;
	glm::vec3 cameraPos;
	glm::vec3 fpLookat;
	switch (camNum)
	{
		case 1://normal benhind copter rotates with copter
			cameraPos = glm::vec3(0, -8, 35);
			cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0));
			ViewMatrix = glm::lookAt(cameraPos, copter.position,
				glm::vec3(0, 1, 0));
			break;
		case 2://birdseye
			cameraPos = glm::vec3(0,-60,1);
			cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0));
			ViewMatrix = glm::lookAt(cameraPos, copter.position,
				glm::vec3(0, 1, 0));
			break;
		case 3://first person
			fpLookat = glm::vec3(0, -5, -60);
			
			fpLookat = copter.position - glm::rotate(fpLookat, spinY, glm::vec3(0, 1, 0));
			
			cameraPos = glm::vec3(0, 0, -25);
			//cameraPos = glm::rotate(cameraPos, -tiltZ, glm::vec3(1, 0, 0));
			//cameraPos = glm::rotate(cameraPos, -tiltX, glm::vec3(0, 0, 1));
			cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0));
			ViewMatrix = glm::lookAt(cameraPos, fpLookat,
				glm::vec3(0, 1, 0));
			
			break;
		case 4://side view
			cameraPos = glm::vec3(50, 0, 1);
			cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0));
			ViewMatrix = glm::lookAt(cameraPos, copter.position,
				glm::vec3(0, 1, 0));
			break;
		case 5://cinematic
			cameraPos = glm::vec3(100, 100, 100);
			ViewMatrix = glm::lookAt(cameraPos, copter.position,
				glm::vec3(0, 1, 0));
			break;
		default:
			cameraPos = glm::vec3(0, -8, 35);
			cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0));
			ViewMatrix = glm::lookAt(cameraPos, copter.position,
				glm::vec3(0, 1, 0));
	}
		

	

	glUseProgram(cubeShader.handle());
	//All of our geometry will have the same projection matrix.
	//we only need to set it once, since we are using the same shader.
	GLuint matLocation = glGetUniformLocation(cubeShader.handle(), "ProjectionMatrix");
	glUniformMatrix4fv(matLocation, 1, GL_FALSE, &ProjectionMatrix[0][0]);
	cubeOne.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, 20, 0));

	glUniformMatrix4fv(glGetUniformLocation(cubeShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &cubeOne.ModelViewMatrix[0][0]);
	//cubeOne.render();
	worldCube.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, 0, 0));

	glUniformMatrix4fv(glGetUniformLocation(cubeShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &worldCube.ModelViewMatrix[0][0]);

	//worldCube.render();

	glUseProgram(0);
	glUseProgram(myShader.handle());  // use the shader


	

	glUniform1f(glGetUniformLocation(myShader.handle(), "displacement"), amount);
	glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ProjectionMatrix"), 1, GL_FALSE, &ProjectionMatrix[0][0]);
	
	
	//viewMatrix = glm::lookAt(glm::vec3(0, 0, -100), glm::vec3(30, 0, 0),
		//glm::vec3(0, 1, 0));
	glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ViewMatrix"), 1, GL_FALSE, &ViewMatrix[0][0]);
	//Changing from daylight to night setting
	

	//Lighting Properties passed to the shader
	if (dayNight == 0)
	{
		Light_Ambient_And_Diffuse = glm::vec4{ 0.8, 0.8, 0.6, 1.0 };
		Light_Specular = glm::vec4{ 0.8, 0.8, 0.8, 1.0 };
	}
	else 
	{
		Light_Ambient_And_Diffuse = glm::vec4{ 0.2, 0.2, 0.2, 1.0 };
		Light_Specular = glm::vec4{ 0.2, 0.2, 0.2, 1.0 };
	}
	glUniform4fv(glGetUniformLocation(myShader.handle(), "LightPos"), 1, &LightPos[0]);
	glUniform4fv(glGetUniformLocation(myShader.handle(), "light_ambient"), 1, &Light_Ambient_And_Diffuse[0]);
	glUniform4fv(glGetUniformLocation(myShader.handle(), "light_diffuse"), 1, &Light_Ambient_And_Diffuse[0]);
	glUniform4fv(glGetUniformLocation(myShader.handle(), "light_specular"), 1, &Light_Specular[0]);


	

	//DRAW THE MODEL
	copter.ModelViewMatrix = glm::translate(ViewMatrix, copter.position);
	copter.ModelViewMatrix = glm::rotate(copter.ModelViewMatrix, spinY, glm::vec3(0, 1, 0));	//rotate object about y axis
	copter.ModelViewMatrix = glm::rotate(copter.ModelViewMatrix, tiltX, glm::vec3(0, 0, 1)); //tilts the cube around x
	copter.ModelViewMatrix = glm::rotate(copter.ModelViewMatrix, tiltZ, glm::vec3(1, 0, 0)); //tilts the cube around z
	
	//Pass the uniform for the modelview matrix 
	glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &copter.ModelViewMatrix[0][0]);
	
	glm::mat4 normalMatrix;
	glm::mat4 NormalMatrix = ModelViewMatrix * normalMatrix;
	glUniformMatrix3fv(glGetUniformLocation(myShader.handle(), "NormalMatrix"), 1, GL_FALSE, &normalMatrix[0][0]);
	
	copter.render();
	//model.drawElementsUsingVBO(&myShader);
	
	//prop.ModelViewMatrix = glm::translate(prop.ModelViewMatrix, glm::vec3(0, 0, 0));
	prop.ModelViewMatrix = copter.ModelViewMatrix;

	

	prop.render(propSpin);
	//Drawing the world
	
	
	world.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, 1790, 0));
	glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &world.ModelViewMatrix[0][0]);
	world.render();
	
	ground.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, -55, 0));
	glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &ground.ModelViewMatrix[0][0]);
	ground.render();

	//for (int i = 0; i < houses.size(); i++)
	//{
	//	houses[i].render(ViewMatrix);
	//}
	//for (int i = 0; i < trees.size(); i++)
	//{
	//	trees[i].render(ViewMatrix);
	//}
	houseOne.render(ViewMatrix);
	houseTwo.render(ViewMatrix);
	houseThree.render(ViewMatrix);
	houseFour.render(ViewMatrix);
	houseFive.render(ViewMatrix);
	houseSix.render(ViewMatrix);
	treeOne.render(ViewMatrix);
	treeTwo.render(ViewMatrix);
	treeThree.render(ViewMatrix);
	treeFour.render(ViewMatrix);
	treeFive.render(ViewMatrix);
	treeSix.render(ViewMatrix);
	treeSeven.render(ViewMatrix);
	treeEight.render(ViewMatrix);
	treeNine.render(ViewMatrix);
	treeTen.render(ViewMatrix);
	leafOne.render(ViewMatrix);
	leafTwo.render(ViewMatrix);
	leafThree.render(ViewMatrix);
	leafFour.render(ViewMatrix);
	

	glUseProgram(0); //turn off the current shader
}