Exemplo n.º 1
0
	//constructor .. e apelat cand e instantiata clasa
	Laborator(){
		//setari pentru desenare, clear color seteaza culoarea de clear pentru ecran (format R,G,B,A)
		glClearColor(0.5,0.5,0.5,1);
		glClearDepth(1);			//clear depth si depth test (nu le studiem momentan, dar avem nevoie de ele!)
		glEnable(GL_DEPTH_TEST);	//sunt folosite pentru a determina obiectele cele mai apropiate de camera (la curs: algoritmul pictorului, algoritmul zbuffer)
		
		//incarca un shader din fisiere si gaseste locatiile matricilor relativ la programul creat
		gl_program_shader = lab::loadShader("shadere\\shader_vertex.glsl", "shadere\\shader_fragment.glsl");
		

		//Initializam pod_racer
		player = new Object("resurse\\pod racer.obj");
		//player->scale(2, 2, 2);
		player->rotate(180, 0, 1, 0);
		objects.push_back(player);
		//Initializam stadion
		//stadium = new Object("resurse\\Stadion.obj");
		//objects.push_back(stadium);
		
		//matrici de modelare si vizualizare
		cam1.set(glm::vec3(0,2,-4), glm::vec3(0,5,-100), glm::vec3(0,1,0));
		cam2.set(glm::vec3(0, 0, 40), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
		cam3.set(glm::vec3(0, 0, 40), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));

		//desenare wireframe
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glLineWidth(10);
		glPointSize(10);

	}
Exemplo n.º 2
0
	Tema4() {
		// Setari pentru desenare, clear color seteaza culoarea de clear pentru ecran (format R,G,B,A).
		glClearColor(0.0, 0.0, 0.0, 1);
		glClearDepth(1);			// clear depth si depth test sunt folosite pentru a determina obiectele cele mai apropiate de camera.
		glEnable(GL_DEPTH_TEST);
		
		// Incarca un shader din fisiere si gaseste locatiile matricilor relativ la programul creat.
		gl_program_shader = lab::loadShader("shadere\\shader_vertex.glsl", "shadere\\shader_fragment.glsl");
		
		// Incarca texturi.
		textures.push_back(lab::loadTextureBMP("resurse\\b1.bmp"));
		textures.push_back(lab::loadTextureBMP("resurse\\b2.bmp"));
		textures.push_back(lab::loadTextureBMP("resurse\\b3.bmp"));
		textures.push_back(lab::loadTextureBMP("resurse\\b4.bmp"));
		textures.push_back(lab::loadTextureBMP("resurse\\b5.bmp"));
		textures.push_back(lab::loadTextureBMP("resurse\\flying_car_texture.bmp"));

		for (int i = 0; i < textures.size(); ++i) {
			glActiveTexture(GL_TEXTURE0 + i + 1);
			glBindTexture(GL_TEXTURE_2D, textures[i]);
		}

		srand(time(NULL));

		// Camere
		view1 = new lab::Camera();
		view1->set(glm::vec3(-10, Building::MAX_HEIGHT + 10, 500), glm::vec3(490, Building::MAX_HEIGHT + 10, 500), glm::vec3(0, 1, 0));
		view2 = new lab::Camera();
		view2->set(glm::vec3(500, 750, 500), glm::vec3(500.1, 0, 500.1), glm::vec3(0, 1, 0));
		view2->rotateFPSoX(-45);
		is_fps = true;

		vehicle = new Vehicle();
		quad = new Quad(1000);
		// Folosesc primele 5 texturi pentru cladiri.
		city = new City(textures.size() - 1);

		// Lumina & material
		material_shininess = 10;
		material_kd = 0.4;
		material_ks = 0.1;

		// Desenare solid
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

		modified = true;
	}
Exemplo n.º 3
0
	//tasta speciala (up/down/F1/F2..) apasata
	void notifySpecialKeyPressed(int key_pressed, int mouse_x, int mouse_y){

		float moveSpeed = 5;
		float rotateSpeedOX = moveSpeed / 200;
		float rotateSpeedOY = moveSpeed / 200;
		float rotateSpeedOZ = moveSpeed / 200;

		// Camera Rotate FPS
		if(key_pressed == GLUT_KEY_F1) lab::glut::enterFullscreen();
		if(key_pressed == GLUT_KEY_F2) lab::glut::exitFullscreen();

		if (key_pressed == GLUT_KEY_RIGHT) { camera.rotateFPS_OY(rotateSpeedOY); }
		if (key_pressed == GLUT_KEY_LEFT) { camera.rotateFPS_OY(-rotateSpeedOY); }

		if (key_pressed == GLUT_KEY_UP) { camera.rotateFPS_OX(rotateSpeedOX); }
		if (key_pressed == GLUT_KEY_DOWN) { camera.rotateFPS_OX(-rotateSpeedOX); }

	}
Exemplo n.º 4
0
	//constructor .. e apelat cand e instantiata clasa
	Laborator(){
		//setari pentru desenare, clear color seteaza culoarea de clear pentru ecran (format R,G,B,A)
		glClearColor(0.8,0.8,0.8,1);
		glClearDepth(1);			//clear depth si depth test (nu le studiem momentan, dar avem nevoie de ele!)
		glEnable(GL_DEPTH_TEST);	//sunt folosite pentru a determina obiectele cele mai apropiate de camera (la curs: algoritmul pictorului, algoritmul zbuffer)
		
		//initializari
		timp = 0.0f;
		amplitudine = 1.5f;
		frecventa = glm::pi<float>() /15;  // 2pi/lungime   ---    lungime e 30
		faza = frecventa /2 ;// viteza * frecventa ---- viteza = 0.5
		directional = 0; circular = 0; // unde
		directie = glm::vec3(1, 0, 1);
		centru.x = 150;
		centru.z =  10;
		drawable = 0;
		//incarca un shader din fisiere si gaseste locatiile matricilor relativ la programul creat
		gl_program_shader_gouraud = lab::loadShader("shadere\\shader_gouraud_vertex.glsl", "shadere\\shader_gouraud_fragment.glsl");

		//incarca o sfera
		lab::loadObj("resurse\\sphere.obj",mesh_vao_sphere, mesh_vbo_sphere, mesh_ibo_sphere, mesh_num_indices_sphere);	

		//incarca un plan
		//lab::loadObj("resurse\\plane.obj",mesh_vao_ground, mesh_vbo_ground, mesh_ibo_ground, mesh_num_indices_ground);	
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				ver.push_back(lab::VertexFormat(i, 0, -j, 0, 1, 0));
			}
		}
		for (int i = 0; i < 99; i++) {
			for (int j = 0; j < 99; j++) {
				ind.push_back(glm::uvec3(i * 100 + j, (i + 1) * 100 + j, (i + 1) * 100 + j + 1));
				ind.push_back(glm::uvec3(i * 100 + j, (i + 1) * 100 + j + 1, i * 100 + j + 1));
			}
		}
		// create grid
		createGrid();

		//lumina & material
		eye_position = glm::vec3(50, 25, 0);
		FPS.set(glm::vec3(50, 25, 0), glm::vec3(50, 0, -15), glm::vec3(0, 1, 0));
		
		light_position = glm::vec3(50,10,-50);
		material_shininess = 30;
		material_kd = 0.5;
		material_ks = 0.5;

		//matrici de modelare si vizualizare
		model_matrix = glm::mat4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);

		//desenare wireframe
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}
Exemplo n.º 5
0
	//functie chemata inainte de a incepe cadrul de desenare, o folosim ca sa updatam situatia scenei ( modelam/simulam scena)
	void notifyBeginFrame(){
		if (up_pressed){
			glm::vec3 temp = glm::normalize(cam1.getforward());
			printf("%f %f %f \n", temp.x, temp.y, temp.z);
			//player->translate2(temp*viteza);
			player->translate2(temp*(-viteza));
			cam1.translateForward(viteza);
		}
		if (down_pressed){
			glm::vec3 temp = glm::normalize(cam1.getforward());
			//player->translate2(temp*(-viteza));
			player->translate2(temp*viteza);
			cam1.translateForward(-viteza);
		}
		if (right_pressed){
			player->rotate(-5.7f, 0, 1, 0);
			cam1.rotateTPSoY(0.1, -4);
		}
		if (left_pressed){
			player->rotate(5.7f, 0, 1, 0);
			cam1.rotateTPSoY(-0.1, -4);
		}

		if (enemy_state == 1){
			//player->translate(0, 0, viteza);
		}
		else{

		}

		//player->rotate(1.0f, 0, 1, 0);
	}
Exemplo n.º 6
0
	//constructor .. e apelat cand e instantiata clasa
	Laborator(){
		//setari pentru desenare, clear color seteaza culoarea de clear pentru ecran (format R,G,B,A)
		glClearColor(0.5,0.5,0.5,1);
		glClearDepth(1);			//clear depth si depth test (nu le studiem momentan, dar avem nevoie de ele!)
		glEnable(GL_DEPTH_TEST);	//sunt folosite pentru a determina obiectele cele mai apropiate de camera (la curs: algoritmul pictorului, algoritmul zbuffer)
		
		//incarca un shader din fisiere si gaseste locatiile matricilor relativ la programul creat
		lab::gl_program_shader_gouraud = lab::loadShader("shadere\\shader_gouraud_vertex.glsl", "shadere\\shader_gouraud_fragment.glsl");
	
		//incarca o sfera
		lab::loadObj("resurse\\sphere.obj",mesh_vao_sphere, mesh_vbo_sphere, mesh_ibo_sphere, mesh_num_indices_sphere);	

		ground = myLoadGround_as_Mesh();

		// init camera
		camera.set(glm::vec3(0, 10, 50), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));

		//lumina & material
		eye_position = glm::vec3(0, 10, 50);
		light_position = glm::vec3(10, 7, -100);
		material_shininess = 30;
		material_kd = 0.5;
		material_ks = 0.5;
		
		amplitudine[0] = 5.0f;
		amplitudine[1] = 5.0f;
		amplitudine[2] = 5.0f;
		lungime_unda[0] = 40.0f;
		lungime_unda[1] = 40.0f;
		lungime_unda[2] = 40.0f;
		viteza_s[0] = 2.0f;
		viteza_s[1] = 2.0f;
		viteza_s[2] = 0.5f;
		
		centru = glm::vec2(10, 10);

		for (int i = 0; i < 3; i++){	
			frecv[i] = 2 * pi / lungime_unda[i];
			faza[i] = viteza_s[i] * 2 * pi / lungime_unda[i];
		}

		timp = 1;

		//matrici de modelare si vizualizare
		model_matrix = glm::mat4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
		//view_matrix = glm::lookAt(eye_position, glm::vec3(0,0,0), glm::vec3(0,1,0));
		matrice_translatie_1 = glm::translate(model_matrix, glm::vec3(light_position.x, light_position.y, light_position.z + 100));
		//desenare wireframe
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}
Exemplo n.º 7
0
	//functia de afisare (lucram cu banda grafica)
	void notifyDisplayFrame(){
		//bufferele din framebuffer sunt aduse la valorile initiale (setate de clear color si cleardepth)
		//adica se sterge ecranul si se pune culoare (si alte propietati) initiala
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//foloseste shaderul
		glUseProgram(gl_program_shader_gouraud);
				
		//trimite variabile uniforme la shader
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(model_matrix));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "view_matrix"),1,false,glm::value_ptr(view_matrix));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "projection_matrix"),1,false,glm::value_ptr(projection_matrix));
		glUniform3f(glGetUniformLocation(gl_program_shader_gouraud, "light_position"),light_position.x, light_position.y, light_position.z);
		glUniform3f(glGetUniformLocation(gl_program_shader_gouraud, "eye_position"),eye_position.x, eye_position.y, eye_position.z);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "material_shininess"),material_shininess);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "material_kd"),material_kd);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "material_ks"),material_ks);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "timp"), timp);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "amplitudine"), amplitudine);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "faza"), faza);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "frecventa"), frecventa);
		glUniform2f(glGetUniformLocation(gl_program_shader_gouraud, "directie"), directie.x,directie.z);
		glUniform2f(glGetUniformLocation(gl_program_shader_gouraud, "centru"), centru.x, centru.z);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "directional"), directional);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "circular"), circular);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "toDraw"), drawable);
		//pune si un sol
		//matrice_translatie = glm::translate(model_matrix, glm::vec3(0,0,0));
		//glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(matrice_translatie));

		glBindVertexArray(mesh_vao_ground);
		glDrawElements(GL_TRIANGLES, indecsi, GL_UNSIGNED_INT, 0);
		drawable = 1;
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "toDraw"), drawable);
		//pune o sfera la pozitia luminii
		glm::mat4 matrice_translatie = glm::translate(model_matrix, glm::vec3(light_position.x,light_position.y,light_position.z));
		glm::mat4 matrice_scalare = glm::scale(model_matrix, glm::vec3(0.1,0.1,0.1));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(matrice_translatie * matrice_scalare));
		
		glBindVertexArray(mesh_vao_sphere);
		glDrawElements(GL_TRIANGLES, mesh_num_indices_sphere, GL_UNSIGNED_INT, 0);
		drawable = 0;
		// camera
		view_matrix = FPS.getViewMatrix();

		
	}
Exemplo n.º 8
0
	//functia de afisare (lucram cu banda grafica)
	void notifyDisplayFrame(){

		//bufferele din framebuffer sunt aduse la valorile initiale (setate de clear color si cleardepth)
		//adica se sterge ecranul si se pune culoare (si alte propietati) initiala
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//foloseste shaderul
		glUseProgram(lab::gl_program_shader_gouraud);
				
		//trimite variabile uniforme la shader
		view_matrix = camera.getViewMatrix();

		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(model_matrix));
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "view_matrix"), 1, false, glm::value_ptr(view_matrix));
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "projection_matrix"), 1, false, glm::value_ptr(projection_matrix));
		glUniform3f(glGetUniformLocation(lab::gl_program_shader_gouraud, "light_position"), light_position.x, light_position.y, light_position.z);
		glUniform3f(glGetUniformLocation(lab::gl_program_shader_gouraud, "eye_position"), eye_position.x, eye_position.y, eye_position.z);
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "material_shininess"), material_shininess);
		glUniform1f(glGetUniformLocation(lab::gl_program_shader_gouraud, "material_kd"), material_kd);
		glUniform1f(glGetUniformLocation(lab::gl_program_shader_gouraud, "material_ks"), material_ks);
		glUniform1fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "amplitudine"), 3, &amplitudine[0]);
		glUniform1fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "frecventa"), 3,  &frecv[0]);
		glUniform1fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "faza"), 3,  &faza[0]);
		glUniform2fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "centru"), 2, &centru[0]);
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "timp"), timp/10);
		timp++;
	
		//pune o sfera la pozitia luminii
		flag = 0;
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "flag"), flag);
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "model_matrix"), 1, false, glm::value_ptr(matrice_translatie_1));
		lab::setColorObject(1, 1, 0, 0);
		glBindVertexArray(mesh_vao_sphere);
		glDrawElements(GL_TRIANGLES, mesh_num_indices_sphere, GL_UNSIGNED_INT, 0);

		//pune si un sol
		flag = 1;
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "flag"), flag);
		matrice_translatie_2 = glm::translate(model_matrix, glm::vec3(-500, -200, -800));
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "model_matrix"), 1, false, glm::value_ptr(matrice_translatie_2));
		
		ground->setColor(0, 0.2, 1);
		lab::drawMesh(ground, 0);
	}
Exemplo n.º 9
0
	void camera_3(Object* obj){
		glViewport(0, 0, screen_width, screen_height);

		//foloseste shaderul
		glUseProgram(gl_program_shader);

		//trimite variabile uniforme la shader
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "model_matrix"), 1, false, glm::value_ptr(obj->model_matrix));
		glm::mat4 view_matrix = glm::lookAt(glm::vec3(0, 170, -15), glm::vec3(0, 0, -15), glm::vec3(-1, 0, 0));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "view_matrix"), 1, false, glm::value_ptr(view_matrix));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "projection_matrix"), 1, false, glm::value_ptr(projection_matrix));

		//bind obiect
		glBindVertexArray(obj->mesh_vao);
		glDrawElements(GL_TRIANGLES, obj->mesh_num_indices, GL_UNSIGNED_INT, 0);

		//deseneaza axe camera
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "model_matrix"), 1, false, glm::value_ptr(glm::mat4()));	//identity
		cam1.drawGeometry();
	}
Exemplo n.º 10
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(lab::gl_program_shader_gouraud);
			lab::gl_program_shader_gouraud = lab::loadShader("shadere\\shader_gouraud_vertex.glsl", "shadere\\shader_gouraud_fragment.glsl");
		}

		if (key_pressed == 'h'){
			static bool wire = true;
			wire = !wire;
			glPolygonMode(GL_FRONT_AND_BACK, (wire ? GL_LINE : GL_FILL));
		}
		if (key_pressed == 'a') {
			matrice_translatie_1 *= myTranslate(-2.0f, 0, 0);
			light_position.x -= 10;
		}
		if (key_pressed == 'd') {
			matrice_translatie_1 *= myTranslate(2.0f, 0, 0);
			light_position.x += 10;
		}
		if (key_pressed == 'w') {
			matrice_translatie_1 *= myTranslate(0, 0, -2.0f);
			light_position.z -= 10;
		}
		if (key_pressed == 's') {
			matrice_translatie_1 *= myTranslate(0, 0, 2.0f);
			light_position.z += 10;
		}

		float moveSpeed = 5;

		// Camera Translation
		if (key_pressed == 'u') { camera.translateForward(moveSpeed); }
		if (key_pressed == 'h') { camera.translateRight(-moveSpeed); }
		if (key_pressed == 'j') { camera.translateForward(-moveSpeed); }
		if (key_pressed == 'k') { camera.translateRight(moveSpeed); }
		if (key_pressed == 'i') { camera.translateUpword(moveSpeed); }
		if (key_pressed == 'y') { camera.translateUpword(-moveSpeed); }
	}
Exemplo n.º 11
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 shaderul si recalculeaza locatiile (offseti/pointeri)
			glDeleteProgram(gl_program_shader);
			gl_program_shader = lab::loadShader("shadere\\shader_vertex.glsl", "shadere\\shader_fragment.glsl");
		}
		if(key_pressed == 'i'){
			static bool wire =true;
			wire=!wire;
			glPolygonMode(GL_FRONT_AND_BACK, (wire?GL_LINE:GL_FILL));
		}
		if(key_pressed == 'w') { cam1.translateForward(1.0f); }
		if(key_pressed == 'a') { cam1.translateRight(-1.0f); }
		if(key_pressed == 's') { cam1.translateForward(-1.0f); }
		if(key_pressed == 'd') { cam1.translateRight(1.0f); }
		if(key_pressed == 'r') { cam1.translateUpword(1.0f); }
		if(key_pressed == 'f') { cam1.translateUpword(-1.0f); }
		if(key_pressed == 'q') { cam1.rotateFPSoY(1.0f); }
		if(key_pressed == 'e') { cam1.rotateFPSoY(-1.0f); }
		if(key_pressed == 'z') { cam1.rotateFPSoZ(-1.0f); }
		if(key_pressed == 'c') { cam1.rotateFPSoZ(1.0f); }
		if(key_pressed == 't') { cam1.rotateFPSoX(1.0f); }
		if(key_pressed == 'g') { cam1.rotateFPSoX(-1.0f); }
		if(key_pressed == 'o') { cam1.set(glm::vec3(0,0,40), glm::vec3(0,0,0), glm::vec3(0,1,0)); }
		if(key_pressed == '1') { cam1.rotateTPSoX(1.0f,40.0f); }
		if(key_pressed == '2') { cam1.rotateTPSoX(-1.0f,40.0f); }
		if(key_pressed == '3') { cam1.rotateTPSoY(1.0f,40.0f); }
		if(key_pressed == '4') { cam1.rotateTPSoY(-1.0f,40.0f); }
		if(key_pressed == '5') { cam1.rotateTPSoZ(1.0f,40.0f); }
		if(key_pressed == '6') { cam1.rotateTPSoZ(-1.0f,40.0f); }
		if (key_pressed == '7') { active_camera = 1; }
		if (key_pressed == '8') { active_camera = 2; }
		if (key_pressed == '9') { active_camera = 3; }
		if (key_pressed == '0') { active_camera = 4; }
		
	}
Exemplo n.º 12
0
	void notifyKeyPressed(unsigned char key_pressed, int mouse_x, int mouse_y){
		//ESC inchide glut.
		if (key_pressed == 27) lab::glut::close();
		if (key_pressed == 'W') {
			static bool wire = true;
			wire = !wire;
			glPolygonMode(GL_FRONT_AND_BACK, (wire ? GL_LINE : GL_FILL));
		}
		// Taste pentru deplasarea camerei FPS de sus.
		if (key_pressed == 'w')
			view1->translateForward(1.0f);
		if (key_pressed == 's')
			view1->translateForward(-1.0f);
		if (key_pressed == 'q')
			view1->translateUpword(1.0f);
		if (key_pressed == 'e')
			view1->translateUpword(-1.0f);
		if (key_pressed == 'a')
			view1->translateRight(-1.0f);
		if (key_pressed == 'd')
			view1->translateRight(1.0f);
		if (key_pressed == '1')
			view1->rotateFPSoX(1.0f);
		if (key_pressed == '2')
			view1->rotateFPSoX(-1.0f);
		if (key_pressed == '3')
			view1->rotateFPSoY(1.0f);
		if (key_pressed == '4')
			view1->rotateFPSoY(-1.0f);
		if (key_pressed == '5')
			view1->rotateFPSoZ(1.0f);
		if (key_pressed == '6')
			view1->rotateFPSoZ(-1.0f);
		if (key_pressed == 'c')
			is_fps = !is_fps;
		modified = true;
	}
Exemplo n.º 13
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;
		}
	}
Exemplo n.º 14
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();
		}

	}