Ejemplo n.º 1
0
double WorldObject::getAngleAtPos(RECT object)
{
	dispBufUpdate();
	double angle = 0;
	Point2D line;
	if(object.right > dispBuffObj[3].x && object.right < dispBuffObj[0].x)
	{
		angle = atan( (appearance.getShapeFromVert(3).y - appearance.getShapeFromVert(0).y) 
			/ (appearance.getShapeFromVert(0).x - appearance.getShapeFromVert(3).x));
		line.x = dispBuffObj[0].x;
		line.y = dispBuffObj[0].y;
		if(checkLineIntersect(object, line, angle))
			return -angle;
		else
			return 0;
	}
	else if(object.right > dispBuffObj[0].x && object.right < dispBuffObj[1].x)
	{
		return 100;
	}
	else if(object.left > dispBuffObj[1].x && object.left < dispBuffObj[2].x)
	{
		angle = atan( (appearance.getShapeFromVert(2).y - appearance.getShapeFromVert(1).y) 
			/ (appearance.getShapeFromVert(2).x - appearance.getShapeFromVert(1).x));
		line.x = dispBuffObj[2].x;
		line.y = dispBuffObj[2].y;
			return angle;
	}
	else
		return 0;
}
Ejemplo n.º 2
0
bool CollisionDetection::checkRectLineIntersect(Point _rp, float _width, float _height, Point _p1, Point _p2)
{
	Point p1 = _rp;
	Point p2 = { _rp.x + _width, _rp.y };
	Point p3 = { _rp.x + _width, _rp.y + _height };
	Point p4 = { _rp.x , _rp.y + _height };
	if (checkLineIntersect(p1, p2, _p1, _p2))
	{
		return true;
	}
	if (checkLineIntersect(p2, p3, _p1, _p2))
	{
		return true;
	}
	if (checkLineIntersect(p3, p4, _p1, _p2))
	{
		return true;
	}
	if (checkLineIntersect(p4, p1, _p1, _p2))
	{
		return true;
	}
	return false;
}
Ejemplo n.º 3
0
Point CollisionDetection::getClosestRectLineIntersect(Point _rp, float _width, float _height, Point _p1, Point _p2)
{
	Point p1 = _rp;
	Point p2 = { _rp.x + _width, _rp.y };
	Point p3 = { _rp.x + _width, _rp.y + _height };
	Point p4 = { _rp.x , _rp.y + _height };
	Point pp1;
	Point pp2;
	Point pp3;
	Point pp4;
	int array[2][4];

	for (int i = 0; i < 4; i++)
	{
		array[1][i] = i;
		array[0][i] = 100000;
	}
	if (checkLineIntersect(p1, p2, _p1, _p2))
	{
		pp1 = getLineIntersect(p1, p2, _p1, _p2);
		array[0][0] = finddistance(_p2.x, _p2.y, pp1.x, pp1.y);
	}
	if (checkLineIntersect(p2, p3, _p1, _p2))
	{
		pp2 = getLineIntersect(p2, p3, _p1, _p2);
		array[0][1] = finddistance(_p2.x, _p2.y, pp2.x, pp2.y);
	}
	if (checkLineIntersect(p3, p4, _p1, _p2))
	{
		pp3 = getLineIntersect(p3, p4, _p1, _p2);
		array[0][2] = finddistance(_p2.x, _p2.y, pp3.x, pp3.y);
	}
	if (checkLineIntersect(p4, p1, _p1, _p2))
	{
		pp4 = getLineIntersect(p4, p1, _p1, _p2);
		array[0][3] = finddistance(_p2.x, _p2.y, pp4.x, pp4.y);
	}

	int currentmin;
	int currentmini;
	for (int i = 0; i < 4; i++) {
		currentmin = 1000000000;
		currentmini = -1;

		for (int j = 0; j < 4; j++) {
			if (array[0][j] < currentmin) {
				currentmin = array[0][j];
				currentmini = j;
			}
		}
	}
	switch (currentmini)
	{
	case 0:
		return pp1;
		break;
	case 1:
		return pp2;
		break;
	case 2:
		return pp3;
		break;
	case 3:
		return pp4;
		break;
	}
}