예제 #1
0
 bool tSegmento::colisionVsPelota(tPelota* pelota, double& tIn, PuntoV2F*& normal)
 {
      PuntoV2F* posicion = new PuntoV2F(pelota->getPosicion());
      PuntoV2F* sentido = new PuntoV2F(pelota->getSentido());
      sentido->sumar(posicion);
      PuntoV2F *puntocolision = new PuntoV2F();
      double tinpre;
      double modulototal;
      puntocolision =  inteseccionSegmento(posicion,sentido,getVertice(0),getVertice(1));
      if(puntocolision!=NULL){


            tinpre=(sqrt(pow((puntocolision->getX() - posicion->getX()),2)+pow((puntocolision->getY() - posicion->getY()),2))) ;
            modulototal =(sqrt(pow((sentido->getX() - posicion->getX()),2)+pow((sentido->getY() - posicion->getY()),2))) ;
            tIn = tinpre / modulototal;
            normal = getNormal(0);
            normal = new PuntoV2F(normal);
      }

      if(puntocolision==NULL){
            puntocolision =  inteseccionSegmento(posicion,sentido,getVertice(1),getVertice(0));
            if(puntocolision!=NULL){
                tinpre=(sqrt(pow((puntocolision->getX() - posicion->getX()),2)+pow((puntocolision->getY() - posicion->getY()),2))) ;
                modulototal =(sqrt(pow((sentido->getX() - posicion->getX()),2)+pow((sentido->getY() - posicion->getY()),2))) ;
                tIn = tinpre / modulototal;
                normal = getNormal(1);
                normal = new PuntoV2F(normal);
            }
            
      }

      return (puntocolision != NULL);
 }
예제 #2
0
 void tSegmento::draw()
 {
	glColor3f(1,1,0);
	glBegin(GL_LINES);
		for (int i=0;i<getNumVertices();i++){
			glVertex2f(getVertice(i)->getX(),getVertice(i)->getY());
		}
	glEnd();
    /*
    //Para las pruebas, dibujar las normales
    glColor3f(0.5,0.5,0.5);
	glBegin(GL_POINTS);
		for (int i=0;i<getNumVertices();i++){
			glVertex2f(getNormal(i)->getX(),getNormal(i)->getY());
		}
	glEnd();*/
 }
예제 #3
0
void RandomHeightmap::faultAlgorithm()
{
	int x1, x2, y1, y2;
	x1 = (int) getRandomHeight() * 11% this->width;
	y1 = (int)getRandomHeight() *3 % this->height;
	x2 = (int)getRandomHeight() % this->width;
	y2 = (int)getRandomHeight() * 7% this->height;
	//Gerade
	int gx = x2 - x1;
	int gy = y2 - y1;
	static float breite = 15000;
	breite -= 20.5;
	float dist;
	static float faktor = 2.5;
	//faktor += 0.0001f;
	if(faktor < 2.8) faktor = 2.8;
	for(int i=0;i<width;i++)
	{
		for(int j=0;j<height;j++)
		{
		Vertices v = getVertice(i,j);
		dist = gx * (4 - j) - gy * (i - x1);

		if(fabs(dist) < breite)
		{
			v.y += (0.8 + cos(PI * dist / breite)) * faktor;
		}
		else if(dist <= 0)
		{
			v.y -= (faktor * 0.2);
		}
		else
		{
			v.y -= (faktor * 0.2);
		}
		setVertice(i,j,v);
		//cout << "Dist: " << dist << endl;
		//cout << "Zufallspunkte "<< x1 << " "<< x2 << " " << y1 << " " << y2 << endl;
		//cout << "gerade " << gx << " " << gy << endl;
		}
	}
}
예제 #4
0
RandomHeightmap::RandomHeightmap(int width, int height) {
	this->width = width;
	this->height = height;
	this->vertices = new Vertices[width*height];
	this->color = new Vertices[width*height];
	this->normale = new Vertices[width*height];
	this->faces = new Faces[(width-1)*(height-1)*2];

	for(int i = 0;i<width*height;i++)
	{
		this->normale[i].x = 0;
		this->normale[i].y = 0;
		this->normale[i].z = 0;
	}

	//Erstelle DES!
	for(int i=0;i<width;i++)
	{
		for(int j=0;j<height;j++)
		{
			Vertices v = {i*2.0,0,j*2.0};
			setVertice(i,j,v);
		}
	}
	//Berechne The Fault Algorithm
	for(int i=0;i<400;i++)
	{
		faultAlgorithm();
	}

	//Berechne Color
	for(int i=0;i<width;i++)
	{
		for(int j=0;j<height;j++)
		{
			Vertices v = getVertice(i,j);
			Vertices c;
			if(v.y < -150)
			{
				c.x = 0;
				c.y = 0;
				c.z = 1.0;
				setColor(i,j,c);
			}
			else if(v.y < -140)
			{
				c.x = 0.9;
				c.y = 1.0;
				c.z = 0;
				setColor(i,j,c);
			}
			else if(v.y < -65)
			{
				c.x = 0;
				c.y = 1.0;
				c.z = 0;
				setColor(i,j,c);
			}
			else if(v.y < 2)
			{
				c.x = 0.0;
				c.y = .33;
				c.z = 0;
				setColor(i,j,c);
			}
			else if(v.y < 20)
			{
				c.x = 0.370;
				c.y = 0.370;
				c.z = 0.370;
				setColor(i,j,c);
			}
			else
			{
				c.x = 1.0;
				c.y = 1.0;
				c.z = 1.0;
				setColor(i,j,c);
			}
		}
	}
	int index = 0;
	//Berechne Faces
	for(int i = 0;i<this->width-1;i++)
	{
		for(int j=0;j<height-1;j++)
		{
			this->faces[index].f1 = this->width * j + i;
			this->faces[index].f2 = this->width * j + (i+1);
			this->faces[index].f3 = this->width * (j+1) + i;
			index++;
			this->faces[index].f1 = this->width * i + (j+1);
			this->faces[index].f2 = this->width * (i+1) + (j+1);
			this->faces[index].f3 = this->width * (i+1) + j;
			index++;

		}
	}
	//Berechne Normale
	for(int i = 0;i<(width-1)*(height-1)*2;i++)
	{
		Faces f = this->faces[i];
		Vertices v1 = this->vertices[f.f1];
		Vertices v2 = this->vertices[f.f2];
		Vertices v3 = this->vertices[f.f3];
		//cout << "VERTICES TO CALC FOR NORMALS" << endl;
		//printVertices(v1);
		//printVertices(v2);
		//printVertices(v3);
		//cout << "Vertices after sub"<< endl;
		Vertices v1_v2 = subVertice(v1, v2);
		Vertices v2_v3 = subVertice(v2, v3);
		//printVertices(v1_v2);
		//printVertices(v2_v3);
		// v1-v2 x v2-v3
		//cout << "Berechnete Normale" << endl;
		Vertices kreuz = kreuzVertice(v1_v2, v2_v3);
		//printVertices(kreuz);
		this->normale[f.f1].x += kreuz.x;
		this->normale[f.f1].y += kreuz.y;
		this->normale[f.f1].z += kreuz.z;

		this->normale[f.f2].x += kreuz.x;
		this->normale[f.f2].y += kreuz.y;
		this->normale[f.f2].z += kreuz.z;

		this->normale[f.f3].x += kreuz.x;
		this->normale[f.f3].y += kreuz.y;
		this->normale[f.f3].z += kreuz.z;

	}
	cout << "NORMALISIEREN" << endl;
	//Vektoren Normalisieren
	for(int i = 0;i<width*height;i++)
	{
		Vertices v = this->normale[i];
		GLfloat sum = -1 * sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
		normale[i].x = normale[i].x / sum;
		normale[i].y = normale[i].y / sum;
		normale[i].z = normale[i].z / sum;
		//cout << "normale:" << normale[i].x << " " << normale[i].y << " " << normale[i].z << endl;
	}


}