Beispiel #1
0
         cocos2d::Vec2 placePointToRect(const cocos2d::Vec2& point, const cocos2d::Rect& rect)
         {
            cocos2d::Vec2 result = point;

            {
               if (point.x < rect.getMinX())
               {
                  result.x = rect.getMinX();
               }
            }

            {
               if (point.y < rect.getMinY())
               {
                  result.y = rect.getMinY();
               }
            }

            {
               if (point.x > rect.getMaxX())
               {
                  result.x = rect.getMaxX();
               }
            }

            {
               if (point.y > rect.getMaxY())
               {
                  result.y = rect.getMaxY();
               }
            }

            return result;
         }
Beispiel #2
0
         tRectInRectResult isRectInsideRect(const cocos2d::Rect & lhs, const cocos2d::Rect & rhs)
         {
            bool bMinX = lhs.getMinX() >= rhs.getMinX();
            bool bMinY = lhs.getMinY() >= rhs.getMinY();
            bool bMaxX = lhs.getMaxX() <= rhs.getMaxX();
            bool bMaxY = lhs.getMaxY() <= rhs.getMaxY();

            return tRectInRectResult(bMinX, bMinY, bMaxX, bMaxY);
         }
Beispiel #3
0
 cocos2d::Vec2 rect_adjustPointInside(const cocos2d::Rect& rect, const cocos2d::Vec2& pt)
 {
     cocos2d::Point result;
     result.x = letBetween(pt.x, rect.getMinX(), rect.getMaxX());
     result.y = letBetween(pt.y, rect.getMinY(), rect.getMaxY());
     return result;
 }
Beispiel #4
0
         cocos2d::Rect placeRectToRect(const cocos2d::Rect& placedRect, const cocos2d::Rect& placeToRect)
         {
            cocos2d::Rect result = placedRect;

            bool bCanBePlacedInside = isRectCanBePlacesInsideRect(placedRect, placeToRect);

            if (true == bCanBePlacedInside)
            {
               auto rectInsideResult = isRectInsideRect(placedRect, placeToRect);
               if (false == rectInsideResult.bResult)
               {
                  result.origin = placedRect.origin;

                  if (false == rectInsideResult.bMinX || false == rectInsideResult.bMinY)
                  {
                     Vec2 movePoint(placedRect.getMinX(), placedRect.getMinY());
                     movePoint = placePointToRect(movePoint, placeToRect) - movePoint;
                     result.origin += movePoint;
                     result = placeRectToRect(result, placeToRect);
                  }
                  else if (false == rectInsideResult.bMaxX || false == rectInsideResult.bMaxY)
                  {
                     Vec2 movePoint(placedRect.getMaxX(), placedRect.getMaxY());
                     movePoint = placePointToRect(movePoint, placeToRect) - movePoint;
                     result.origin += movePoint;
                     result = placeRectToRect(result, placeToRect);
                  }
               }
            }

            return result;
         }
Beispiel #5
0
cocos2d::Vec2 GameLayer::getIntersection_NPC_and_SPELayerRect(cocos2d::Rect rect ,cocos2d::Point p)
{

	/*
			D---------C
			|		 |
			A---------B
	*/
	Vec2 A(rect.getMinX(),rect.getMinY());
	Vec2 B(rect.getMaxX(),rect.getMinY());
	Vec2 C(rect.getMaxX(),rect.getMaxY());
	Vec2 D(rect.getMinX(),rect.getMaxY());

	Vec2 PlayerP = getChildByTag(kTagPlayer)->getPosition();
	Vec2 npcP = p;

	Vec2 point;
	if ( Vec2::isSegmentIntersect(A, B, PlayerP,p)){
		point = Vec2::getIntersectPoint(A,B,PlayerP,p);
	}
	else if (Vec2::isSegmentIntersect(B, C, PlayerP, p)){
		point = Vec2::getIntersectPoint(B,C, PlayerP, p);
	}
	else if (Vec2::isSegmentIntersect(C, D, PlayerP, p)){
		point = Vec2::getIntersectPoint(C, D, PlayerP, p);
	}
	else if (Vec2::isSegmentIntersect(A, D, PlayerP, p)){
		point = Vec2::getIntersectPoint(A, D, PlayerP, p);
	}

	return point;
}
nav::Circle DelaunayAlgorithm::calculateCircleByRect(const cocos2d::Rect&rect)
{
	CCASSERT(rect.size.width > 0 && rect.size.height > 0, "create circle must rect");
	cocos2d::Point center(rect.getMidX(), rect.getMidY());
	cocos2d::Point topright(rect.getMaxX(), rect.getMaxY());
	float distance = center.getDistance(topright);
	nav::Circle circle(center, distance);
	return circle;
}
void BlueParticles::SetArea(cocos2d::Rect rect, bool draw)
{
	m_area = rect;
	m_area.origin += getPosition();
	if (draw)
	{
		cocos2d::DrawNode* draw = cocos2d::DrawNode::create();
		draw->drawRect(cocos2d::Vec2::ZERO, cocos2d::Vec2(m_area.size.width, m_area.size.height), cocos2d::Color4F(1.0f, 0.0f, 0.0f, 0.5f));
		addChild(draw);
	}
	cocos2d::Rect textRect = cocos2d::Rect(rect.getMidX(), rect.getMidY(), rect.getMaxX() - rect.getMinX(), rect.getMaxY() - rect.getMinY());
	this->setTextureRect(rect);
	cocos2d::Texture2D::TexParams params = cocos2d::Texture2D::TexParams();
	params.magFilter = GL_LINEAR;
	params.minFilter = GL_LINEAR;
	params.wrapS = GL_REPEAT;
	params.wrapT = GL_REPEAT;
	getTexture()->setTexParameters(params);
}