Esempio n. 1
0
bool CollisionManager::PixelsToRect(const CollisionPixelData * pixels, double px, double py, double rx, double ry, double rw, double rh) const
{
	double overlapRectX, overlapRectY, overlapRectW, overlapRectH,x,y;
	if (RectsOverlap(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh)) {
		OverlappingRect(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh, &overlapRectX, &overlapRectY, &overlapRectW, &overlapRectH);
		x = overlapRectX;
		y = overlapRectY;

		bool collision = false;
		while (!collision && y < (overlapRectY + overlapRectH))
		{
			while (!collision && x <(overlapRectX + overlapRectW))
			{
				collision = pixels->GetData(x - px, y - py);
				x++;
			}
			y++;
			x = overlapRectX;
		}
		return collision;
	}
	else {
return false;
	}
	
}
Esempio n. 2
0
bool CollisionManager::CircleToPixels(double cx, double cy, double cr, const CollisionPixelData * pixels, double px, double py) const
{
	double overlapRectX, overlapRectY, overlapRectW, overlapRectH;
	double x, y;
	//check overlap
	if (RectsOverlap(cx-cr, cy-cr, cr*2, cr*2, px, py, pixels->GetWidth(), pixels->GetHeight())) {
		//get overlapingRect
		OverlappingRect(cx-cr, cy-cr, cr * 2, cr * 2, px, py, pixels->GetWidth(), pixels->GetHeight(), &overlapRectX, &overlapRectY, &overlapRectW, &overlapRectH);
		//reference coords
		x = overlapRectX;
		y = overlapRectY;

		//cicle through pixels
		bool collision = false;
		while (!collision && y < (overlapRectY + overlapRectH))
		{
			while (!collision && x <(overlapRectX + overlapRectW))
			{
				collision = pixels->GetData(x - px, y - py) && Distance(x, y, cx, cy) < cr;
				x++;
			}
			y++;
			x = overlapRectX;
		}
		return collision;
	}
	else {
return false;
	}

	
}
Esempio n. 3
0
bool CollisionManager::PixelsToPixels(const CollisionPixelData * p1, double x1, double y1, const CollisionPixelData * p2, double x2, double y2) const
{
	double overlapRectX, overlapRectY, overlapRectW, overlapRectH;
	double x, y, p1x, p1y, p2x, p2y;
	if(RectsOverlap(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight())){
	OverlappingRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight(), &overlapRectX, &overlapRectY, &overlapRectW, &overlapRectH);
	x = overlapRectX;
	y = overlapRectY;

	bool collision = false;
	while (!collision && y < (overlapRectY + overlapRectH))
	{
		while (!collision && x <(overlapRectX + overlapRectW))
		{
			collision = (p1->GetData(x - x1, y - y1) && p2->GetData(x - x2, y - y2));
			x++;
		}
		y++;
		x = overlapRectX;
	}
	return collision;
	}
	else {
		return false;
	}
}
bool CollisionManager::PixelsToRect(const CollisionPixelData* pixels, double px, double py, double rx, double ry, double rw, double rh) const
{
	bool result = false;

	if ( RectToRect(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh) )
	{
		// Obtenemos rectangulo del solapamiento.
		double rectx = 0;
		double recty = 0;
		double rectw = 0;
		double recth = 0;
		OverlappingRect(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh, &rectx, &recty, &rectw, &recth);

		// Obtenemos primer pixel de cada rectangulo.
		uint32 coordXFirstPixel1 = ( uint32 )( rectx - px );
		uint32 coordYFirstPixel1 = ( uint32 )( recty - py );

		// Comprobamos la colision
		for (uint16 i = 0; i < rectw; i++)
			for (uint16 j = 0; j < recth; j++)
				if ( pixels->GetData(coordXFirstPixel1 + i, coordYFirstPixel1 + j) )
					result = true;
	}

	return result;
}
Esempio n. 5
0
bool ObjectClusterer::ArePlanesInTheSameObject(const Segment& firstPlane, const Segment& secondPlane)
{
#ifdef DEBUG_ObjectClusterBase
    dbgFirstId = firstPlane.id;
    dbgSecondId = secondPlane.id;
#endif
    if(DoRectsOverlap(firstPlane.rect, secondPlane.rect)==false)
        return false;
    ImRect ovlRect = OverlappingRect(firstPlane.rect, secondPlane.rect);

    vecPairOfPixels connPixels;
    if(ArePlanesConnected(ovlRect, firstPlane, secondPlane, connPixels)==false)
        return false;

    if(clAngleBetweenVectorsLessThan(firstPlane.normal, secondPlane.normal, 5.f, true))
        return true;

    float angleDegree;
    try{
        angleDegree = InnerAngleBetweenPlanes(firstPlane, secondPlane, connPixels);
    } catch (int code) {
        qDebug() << "exception code" << code;
        return false;
    }

    if(IsConcave(angleDegree))
        return true;
    return !DetermineConvexity(firstPlane, secondPlane);
}
bool CollisionManager::CircleToPixels(double cx, double cy, double cr, const CollisionPixelData* pixels, double px, double py) const
{
	bool result = false;

	if ( CircleToRect(cx, cy, cr, px, py, pixels->GetWidth(), pixels->GetHeight()) )
	{
		// Obtenemos rectangulo del solapamiento.
		double rx = 0;
		double ry = 0;
		double rw = 0;
		double rh = 0;
		OverlappingRect(cx - cr, cy - cr, cr * 2, cr * 2, px, py, pixels->GetWidth(), pixels->GetHeight(), &rx, &ry, &rw, &rh);

		// Obtenemos primer pixel del rectangulo.
		uint32 coordXFirstPixel1 = ( uint32 )( rx - px );
		uint32 coordYFirstPixel1 = ( uint32 )( ry - py );

		// Comprobamos la colision
		for (uint16 i = 0; i < rw; i++)
			for (uint16 j = 0; j < rh; j++)
				if ( pixels->GetData(coordXFirstPixel1 + i, coordYFirstPixel1 + j) )
					if ( SquaredDistance(cx, cy, rx + i, ry + j) <= Pow(cr, 2) )
						result = true;
	}

	return result;
}
bool CollisionManager::PixelsToPixels(const CollisionPixelData* p1, double x1, double y1, const CollisionPixelData* p2, double x2, double y2) const
{
	bool result = false;

	if ( RectToRect(x1, y1, p1->GetWidth(), p2->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight()) )
	{
		// Obtenemos rectangulo del solapamiento.
		double rx = 0;
		double ry = 0;
		double rw = 0;
		double rh = 0;
		OverlappingRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight(), &rx, &ry, &rw, &rh);

		// Obtenemos primer pixel de cada rectangulo.
		uint32 coordXFirstPixel1 = ( uint32 )( rx - x1 );
		uint32 coordYFirstPixel1 = ( uint32 )( ry - y1 );
		uint32 coordXFirstPixel2 = ( uint32 )( rx - x2 );
		uint32 coordYFirstPixel2 = ( uint32 )( ry - y2 );

		// Comprobamos la colision.
		for (uint16 i = 0; i < rw; i++)
			for (uint16 j = 0; j < rh; j++)
				if ( p1->GetData(coordXFirstPixel1 + i, coordYFirstPixel1 + j) && p2->GetData(coordXFirstPixel2 + i, coordYFirstPixel2 + j) )
					result = true;
	}

	return result;
}
Esempio n. 8
0
//comprobamos si colisionan los rectangulos que contienen los pixeles, obtenemos la zona en la que se solapan y comprobamos en esa zona si hay un pixel para los dos sprites
bool CollisionManager::PixelsToPixels(const CollisionPixelData* p1, double x1, double y1, const CollisionPixelData* p2, double x2, double y2) const
{
	//si los dos rectangulos se solapan
	if (RectsOverlap(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight())) 
	{
		double rx, ry, rw, rh;
		
		//obtenemos el rectangulo de solapamiento
		OverlappingRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight(), &rx, &ry, &rw, &rh);

		//obtenemos los pixeles del los dos rectangulos donde empieza al rectangulo de solapamiento
		uint16 rect1x = uint16(rx - x1);
		uint16 rect1y = uint16(ry - y1);
		uint16 rect2x = uint16(rx - x2);
		uint16 rect2y = uint16(ry - y2);

		//recorremos desde esos puntos nuestro buffer de booleanos y si los dos son opacos, 
		for (int i = 0; i < rw; i++)
			for (int j = 0; j < rh; j++)
				if (p1->GetData(rect1x + i, rect1y + j)  &&  p2->GetData(rect2x + i, rect2y + j))
					return true;
	}

	return false;
}
bool CollisionManager::PixelsToFoot(double x1, double y1, const CollisionPixelData* p1, double x2, double y2, double w2, double h2) const
{
	bool result = false;

	if ( RectToRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, w2, h2) )
	{
		// Get overlapping rectangle.
		double rectx = 0;
		double recty = 0;
		double rectw = 0;
		double recth = 0;
		OverlappingRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, w2, h2, &rectx, &recty, &rectw, &recth);

		// Get first pixel of each rectangle.
		unsigned int coordXFirstPixel = static_cast<unsigned int>(rectx - x1);
		unsigned int coordYFirstPixel = static_cast<unsigned int>(recty - y1);

		// Check collision.
		for (unsigned short i = 0; i < rectw; i++)
			for (unsigned short j = 0; j < recth; j++)
				if (p1->GetData(coordXFirstPixel + i, coordYFirstPixel + j))
					result = true;
	}

	return result;
}
Esempio n. 10
0
bool CollisionManager::PixelsToRect(const CollisionPixelData* pixels,
	double px, double py, double rx, double ry, double rw, double rh) const{

	if (RectsOverlap(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh)){
		double outx, outy, outwidth, outheight;
		OverlappingRect(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh, &outx, &outy, &outwidth, &outheight);
		uint32 px1 = outx - px;
		uint32 py1 = outy - py; //1º pixel relativo a p1
		for (int32 pyy = 0; pyy < outheight; pyy++){
			for (int32 pxx = 0; pxx < outwidth; pxx++){
				if (pixels->GetData(px1 + pxx, py1 + pyy) == true) return true;
			}
		}
	}


	return false;
}
bool CollisionManager::CircleToPixels(double cx, double cy, double cr, const CollisionPixelData * pixels, double px, double py) const {
	if (RectsOverlap(cx - cr, cy - cr, cr * 2, cr * 2, px, py, pixels->GetWidth(), pixels->GetHeight())) {
		double overlapX, overlapY, overlapWidth, overlapHeight;
		OverlappingRect(cx - cr, cy - cr, cr * 2, cr * 2, px, py, pixels->GetWidth(), pixels->GetHeight(), &overlapX, &overlapY, &overlapWidth, &overlapHeight);
		double offY = overlapY - py;
		double offX;
		while (offY < overlapHeight + overlapY - py) {
			offX = overlapX - px;
			while (offX < overlapWidth + overlapX - px) {
				if (pixels->GetData(offX, offY) && Distance(cx, cy, offX + px, offY + py) <= cr)
					return true;
				offX++;
			}
			offY++;
		}
	}
	return false;
}
Esempio n. 12
0
bool CollisionManager::PixelsToPixels(const CollisionPixelData* p1,
	double x1, double y1, const CollisionPixelData* p2, double x2, double y2) const{

	if (RectsOverlap(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight())){
		double outx, outy, outwidth, outheight;
		OverlappingRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight(), &outx, &outy, &outwidth, &outheight);
		uint32 px1 = outx - x1;
		uint32 py1 = outy - y1; //1º pixel relativo a p1
		uint32 px2 = outx - x2;
		uint32 py2 = outy - y2; //1º pixel relativo a p2
		for (int32 py = 0; py < outheight; py++){
			for (int32 px = 0; px < outwidth; px++){
				if (p1->GetData(px1 + px, py1 + py) == true && p2->GetData(px2 + px, py2 + py) == true) return true;
			}
		}
	}

	return false;
}
bool CollisionManager::PixelsToRect(const CollisionPixelData * pixels, double px, double py, double rx, double ry, double rw, double rh) const {
	if (RectsOverlap(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry , rw, rh)) {
		double overlapX, overlapY, overlapWidth, overlapHeight;
		OverlappingRect(px, py, pixels->GetWidth(), pixels->GetHeight(), rx, ry, rw, rh, &overlapX, &overlapY, &overlapWidth, &overlapHeight);
		double offsetY = overlapY - py;
		double offsetX;
		while (offsetY < overlapHeight + overlapY - py) {
			offsetX = overlapX - px;
			while (offsetX < overlapWidth + overlapX - px) {
				if (pixels->GetData(offsetX, offsetY))
					return true;
				offsetX++;
			}
			offsetY++;
		}
	}

	return false;
}
Esempio n. 14
0
//comprobamos si colisiona el rectangulo y el rectangulo que contiene los pixeles, obtenemos la zona en la que se solapan y comprobamos en esa zona si hay un pixel opaco en el buffer
bool CollisionManager::PixelsToRect(const CollisionPixelData* pixels, double px, double py, double rx, double ry, double rw, double rh) const
{	
	if (RectsOverlap(px,py, pixels->GetWidth(), pixels->GetHeight(),rx,ry,rw,rh))
	{
		double overlapx, overlapy, overlapw, overlaph;
		OverlappingRect(px,py,pixels->GetWidth(), pixels->GetHeight(),rx,ry,rw,rh,&overlapx,&overlapy,&overlapw, &overlaph);

		uint16 rect1x = uint16(overlapx - px);
		uint16 rect1y = uint16(overlapy - py);
		uint16 rect2x = uint16(overlapx - rx);
		uint16 rect2y = uint16(overlapy - ry);

		//recorremos desde esos puntos nuestro buffer de booleanos y si algun pixel es opaco colisionan
		for (int i = 0; i < overlapw; i++)
			for (int j = 0; j < overlaph; j++)
				if (pixels->GetData(rect1x + i, rect1y + j))
					return true;
	}

	return false;
}
Esempio n. 15
0
bool CollisionManager::CircleToPixels(double cx, double cy, double cr,
	const CollisionPixelData* pixels, double px, double py) const{

	//Si chocan sus rectangulos
	if (RectsOverlap(px, py, pixels->GetWidth(), pixels->GetHeight(), cx, cy, 2 * cr, 2 * cr)){
		//Calculamos el rectangulo de colision
		double outx, outy, outwidth, outheight;
		OverlappingRect(px, py, pixels->GetWidth(), pixels->GetHeight(), cx, cy, 2*cr, 2*cr, &outx, &outy, &outwidth, &outheight);

		uint32 px1 = outx - px;
		uint32 py1 = outy - py; //1º pixel relativo a p1
		for (int32 pyy = 0; pyy < outheight; pyy++){
			for (int32 pxx = 0; pxx < outwidth; pxx++){
				//if one pixel is visible and inside the circle
				if (pixels->GetData(px1 + pxx, py1 + pyy) == true && Distance(cx + cr, cy + cr, outx + pxx, outy + pyy) < cr) return true;
			}
		}

	}
	return false;
}
bool CollisionManager::PixelsToPixels(const CollisionPixelData * p1, double x1, double y1, const CollisionPixelData * p2, double x2, double y2) const {
	if (RectsOverlap(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight())) {
		double overlapX, overlapY, overlapWidth, overlapHeight;
		OverlappingRect(x1, y1, p1->GetWidth(), p1->GetHeight(), x2, y2, p2->GetWidth(), p2->GetHeight(), &overlapX, &overlapY, &overlapWidth, &overlapHeight);
		double py1 = overlapY - y1;
		double py2 = overlapY - y2;
		double px1, px2;
		while (py1 < overlapHeight + overlapY - y1 && py2 < overlapHeight + overlapY - y2) {
			px1 = overlapX - x1;
			px2 = overlapX - x2;
			while (px1 < overlapWidth + overlapX - x1 && px2 < overlapWidth + overlapX - x2) {
				if (p1->GetData(px1, py1) && p2->GetData(px2, py2)) {
					return true;
				}
				px1++;
				px2++;
			}
			py1++;
			py2++;
		}
	}
	return false;
}