Esempio n. 1
0
	//functia de afisare (lucram cu banda grafica)
	void notifyDisplayFrame() {
		// Deseneaza doar daca s-a modificat pozitia camerei sau perspectiva (a fost apasata o tasta).
		if (modified) {
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			// Foloseste shaderul.
			glUseProgram(gl_program_shader);

			// Trimite variabile uniforme la shader.
			glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "projection_matrix"), 1, false, glm::value_ptr(projection_matrix));
			glUniform1i(glGetUniformLocation(gl_program_shader, "tps_color"), 0);
			glUniform3f(glGetUniformLocation(gl_program_shader, "light_position"),
				view1->getPosition().x, view1->getPosition().y, view1->getPosition().z);
			glUniform3f(glGetUniformLocation(gl_program_shader, "eye_position"),
				view1->getPosition().x, view1->getPosition().y, view1->getPosition().z);
			glUniform3f(glGetUniformLocation(gl_program_shader, "light_direction"),
				view1->getForward().x, view1->getForward().y, view1->getForward().z);
			glUniform1i(glGetUniformLocation(gl_program_shader, "material_shininess"), material_shininess);

			if (is_fps)
				vehicle->drawGeometry(gl_program_shader, textures.size());

			view_matrix = is_fps ? view1->getViewMatrix() : view2->getViewMatrix();
			glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "view_matrix"), 1, false, glm::value_ptr(view_matrix));
			glUniform1f(glGetUniformLocation(gl_program_shader, "material_kd"), is_fps ? material_kd : 0);
			glUniform1f(glGetUniformLocation(gl_program_shader, "material_ks"), is_fps ? material_ks : 0);

			std::vector<glm::vec4> plane_coefs;
			glm::mat4 pv = projection_matrix * view1->getViewMatrix();

			// Calculeaza coeficientii ecuatiilor pentru planurile frustumului.
			plane_coefs.push_back(glm::vec4(pv[0][3] + pv[0][0], pv[1][3] + pv[1][0], pv[2][3] + pv[2][0], pv[3][3] + pv[3][0])); // left
			plane_coefs.push_back(glm::vec4(pv[0][3] - pv[0][0], pv[1][3] - pv[1][0], pv[2][3] - pv[2][0], pv[3][3] - pv[3][0])); // right
			plane_coefs.push_back(glm::vec4(pv[0][3] + pv[0][1], pv[1][3] + pv[1][1], pv[2][3] + pv[2][1], pv[3][3] + pv[3][1])); // bottom
			plane_coefs.push_back(glm::vec4(pv[0][3] - pv[0][1], pv[1][3] - pv[1][1], pv[2][3] - pv[2][1], pv[3][3] - pv[3][1])); // top
			plane_coefs.push_back(glm::vec4(pv[0][3] + pv[0][2], pv[1][3] + pv[1][2], pv[2][3] + pv[2][2], pv[3][3] + pv[3][2])); // near
			plane_coefs.push_back(glm::vec4(pv[0][3] - pv[0][2], pv[1][3] - pv[1][2], pv[2][3] - pv[2][2], pv[3][3] - pv[3][2])); // far

			quad->drawGeometry(gl_program_shader, is_fps, plane_coefs);
			city->draw(gl_program_shader, is_fps, plane_coefs);
			modified = false;
		}
	}
Esempio n. 2
0
	//tasta apasata
	void notifyKeyPressed(unsigned char key_pressed, int mouse_x, int mouse_y){
		if(key_pressed == 27) lab::glut::close();	//ESC inchide glut si 
		if(key_pressed == 32) {	//SPACE
			//reincarca shader
			glDeleteProgram(gl_program_shader_gouraud);
			gl_program_shader_gouraud = lab::loadShader("shadere\\shader_gouraud_vertex.glsl", "shadere\\shader_gouraud_fragment.glsl");
		}
		// grid view
		if(key_pressed == 'g'){
			static bool wire =true;
			wire=!wire;
			glPolygonMode(GL_FRONT_AND_BACK, (wire?GL_LINE:GL_FILL));
		}
		// directional
		if (key_pressed == '1') {
			directional ^= 1;
		}
		// circular
		if (key_pressed == '2') {
			circular ^= 1;
		}
		// inainte
		if (key_pressed == 'w') {
			FPS.translateForward(1);
			eye_position = FPS.getPosition();
		}
		// inapoi 
		if (key_pressed == 's') {
			FPS.translateForward(-1);
			eye_position = FPS.getPosition();
		}
		// rotire stanga
		if (key_pressed == 'a') {
			FPS.rotateFPS_OY(5);
			eye_position = FPS.getPosition();
		}
		// rotire dreapta
		if (key_pressed == 'd') {
			FPS.rotateFPS_OY(-5);
			eye_position = FPS.getPosition();
		}
		// rotire sus
		if (key_pressed == 'q') {
			FPS.rotateFPS_OX(-5);
			eye_position = FPS.getPosition();
		}
		// rotire jos
		if (key_pressed == 'e') {
			FPS.rotateFPS_OX(5);
			eye_position = FPS.getPosition();
		}
		// rotire oz
		if (key_pressed == 'z') {
			FPS.rotateFPS_OZ(-5);
			eye_position = FPS.getPosition();
		}
		// rotire oz
		if (key_pressed == 'c') {
			FPS.rotateFPS_OZ(5);
			eye_position = FPS.getPosition();
		}

	}