Пример #1
0
 std::vector<Real3> splitSphericalLineSegment(const Point& start, const Point& end, Real deltaAngle)
 {
     std::vector<Real3> result;
     
     assert(start.position != -end.position);
     
     auto direction = glm::normalize(glm::cross(start.position, end.position));
     float distance = glm::acos(glm::dot(start.position, end.position));
     
     result.push_back(start.position);
     
     for (auto angle=deltaAngle; angle<distance; angle+=deltaAngle)
     {
         Mat4 rotation = glm::rotate(Mat4(1.0), angle, direction);
         Real3 pos = glm::normalize(Real3(rotation * Real4(start.position, 1.0)));
         
         result.push_back(pos);
     }
     
     result.push_back(end.position);
     
     return result;
 }
void displayTeapot(Camara &cam, Transformacion marco){
//Dibuja la foto de un Cubo con la cam y la pone en t

	// Transformacion de la camara
	Transformacion rotcam;
	Transformacion rotationx, rotationy;
	Punto newAT = AT;
	rotationx.rotX(rotationX);
	rotationy.rotY(rotationY);

	newAT = newAT.transform(rotationx);
	newAT = newAT.transform(rotationy);
	
	Punto vert = Punto(0.0, 1.0, 0.0);
	vert.transform(rotcam);

	canon.at(newAT);
	canon.lookAt(OR);
	canon.setVertical(vert.asVector());

	Punto newFR = FR;
	newFR = newFR.transform(rotationy);
	frontal.at(newFR);
	frontal.lookAt(OR);

	Punto newPE = PE;
	newPE = newPE.transform(rotationy);
	perfil.at(newPE);
	perfil.lookAt(OR);

	Punto newCE = CE;
	newCE = newCE.transform(rotationy);
	cenital.setVertical(newCE.asVector());
	
	rotationx.reset();
	rotationy.reset();


	Transformacion t = marco * cam.getview();
	
	//Dibujo de la tetera
	Transformacion rot; 
	rot.rotX(-90);
	Transformacion mov;
	mov.translation(Real4(0.0, -1.0, 0.0));

	
	for(int k=0;k<32;k++){
		S[k].getPoints(NVERT, sb);
		S[k].getTangents(NVERT, tgU, tgV);
		S[k].getNormals(NVERT, n);
	
		for(int i=0;i<NVERT*NVERT;i++){	
			sb[i] = sb[i].transform(rot).transform(mov);
			sb[i] =	cam.shot(sb[i]).transform(marco);	
		
			float sup_color[] = {0.5, 0.5, 0.5, 1.0}; //Gris
			glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sup_color);
		}

		if(inalambrico){
			for(int i=0;i<NVERT-1;i++){
				for(int j=0;j<NVERT-1;j++){			
					glBegin(GL_QUADS);
					glNormal3f(n[NVERT*i+j].x(),n[NVERT*i+j].y(),n[NVERT*i+j].z());
					glVertex3f(sb[NVERT*i+j].x(),sb[NVERT*i+j].y(),sb[NVERT*i+j].z());

					glNormal3f(n[NVERT*(i+1)+j].x(),n[NVERT*(i+1)+j].y(),n[NVERT*(i+1)+j].z());
					glVertex3f(sb[NVERT*(i+1)+j].x(),sb[NVERT*(i+1)+j].y(),sb[NVERT*(i+1)+j].z());

					glNormal3f(n[NVERT*(i+1)+(j+1)].x(),n[NVERT*(i+1)+(j+1)].y(),n[NVERT*(i+1)+(j+1)].z());
					glVertex3f(sb[NVERT*(i+1)+(j+1)].x(),sb[NVERT*(i+1)+(j+1)].y(),sb[NVERT*(i+1)+(j+1)].z());

					glNormal3f(n[NVERT*i+(j+1)].x(),n[NVERT*i+(j+1)].y(),n[NVERT*i+(j+1)].z());
					glVertex3f(sb[NVERT*i+(j+1)].x(),sb[NVERT*i+(j+1)].y(),sb[NVERT*i+(j+1)].z());

					glEnd();
				};	
			};
		}
		else{
			for(int i=0;i<NVERT;i++){
				glBegin(GL_LINE_STRIP);
					for(int j=0;j<NVERT;j++){
						glVertex3f( (GLfloat)((sb[i*NVERT+j]).x()),
									(GLfloat)((sb[i*NVERT+j]).y()),
									(GLfloat)((sb[i*NVERT+j]).z()));
					}
				glEnd();
			}
 			for(int i=0;i<NVERT;i++){
				glBegin(GL_LINE_STRIP);
					for(int j=0;j<NVERT;j++){
						glVertex3f( (GLfloat)((sb[i+j*NVERT]).x()),
									(GLfloat)((sb[i+j*NVERT]).y()),
									(GLfloat)((sb[i+j*NVERT]).z()));
					}
				glEnd();
			}	
		}
	}
}
Пример #3
0
Real4 GetCol(const Matrix4& A, int col) {
    col = col*4;
    return Real4(A[0+col],A[1+col],A[2+col],A[3+col]) ;
}
Пример #4
0
Real4 GetRow(const Matrix4& A, int row) {
    return Real4(A[0+row],A[4+row],A[8+row],A[12+row]) ;
}
Пример #5
0
void crear_escena(void) {

	Esfera *amarilla, *blanca, *roja, *verde, *azul;
	float radio = 0.59673710213f;

	// Creamos la escena
	if (escena==NULL) 
		escena = new Escena();

	//Esfera
	Esfera *esfera = new Esfera(Punto(0,0.1,-2), 0.8);
	esfera->setColor(Color(1,0,0), Color(1,1,1), 0.3, 0.3, 0.7, 40);
	escena->add(esfera);

	//Caja suelo
	Transformacion t1;
	t1.translation(Real4(0.0, -1.0, -1.5));
	t1.scale(2, 0.1, 2);

	Caja *cajasuelo = new Caja(t1);
	cajasuelo->setColor(Color(1,1,1), Color::BLANCO, 0.1, 0.3, 0.9, 100);
	escena->add(cajasuelo);

	//Caja cubo
	Transformacion t2;
	t2.translation(Real4(-1.0, -0.3, -0.3));
	t2.rotation(60, Vector(1,1,1));
	t2.scale(0.5, 0.5, 0.5);

	Caja *cajacubo = new Caja(t2);
	cajacubo->setColor(Color(0,1,0), Color::BLANCO, 0.1, 0.8, 0.1, 1);
	escena->add(cajacubo);

	// Esfera blanca (detrás)
	/*blanca = new Esfera(Punto(0.0f, 0.0f, -2.0f), radio);
	blanca->setColor(Color::BLANCO);
	escena->add(blanca);*/

	// Esfera amarilla (NO)
	/*amarilla = new Esfera(Punto(-radio, radio,0.0f),radio);
	amarilla->setColor(Color::VERDE+Color::ROJO);
	escena->add(amarilla);*/

	// Esfera roja (SO)
	/*roja = new Esfera(Punto(-radio,-radio,0.0f), radio);
	roja->setColor(Color::ROJO);
	escena->add(roja);

	// Esfera azul (SE)
	/*azul = new Esfera(Punto(radio, -radio,0.0f), radio);
	azul->setColor(Color::AZUL);
	escena->add(azul);/*

	// Esfera verde (NE)
	/*verde = new Esfera(Punto(radio, radio, 0.0f), radio);
	verde->setColor(Color::VERDE);
	escena->add(verde);*/
	
	/*Transformacion t1;
	//t1.translation(Real4(2,2,2,0));
	t1.rotation(30, Vector(0,1,0));
	t1.rotation(-15, Vector(1,0,0));
	t1.scale(0.5, 0.4, 0.3);

	Caja *cajaverde = new Caja(t1);
	cajaverde->setColor(Color::VERDE);
	escena->add(cajaverde);*/
	
	//escena->add(amarilla);
	/*for(int i=0;i<6;i++){
		for(int j=0;j<4;j++){
			printf("%.2f %.2f ", cajaverde->caras[i].vertices[j].x(), cajaverde->caras[i].vertices[j].y());
		}
		printf("\n");
	}*/
}