当前位置: 首页>>代码示例>>C++>>正文


C++ Shape::getPoint方法代码示例

本文整理汇总了C++中sf::Shape::getPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Shape::getPoint方法的具体用法?C++ Shape::getPoint怎么用?C++ Shape::getPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::Shape的用法示例。


在下文中一共展示了Shape::getPoint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Intersection

	bool ICollisionSystem::Intersection(sf::Shape& theMovingShape, sf::Shape& theOtherShape, sf::Vector2f& theMinimumTranslation)
	{
		//Exit if either shape is empty;
		if(theMovingShape.getPointCount()==0 || theOtherShape.getPointCount()==0)
			return false;
		//Variables
		std::vector<sf::Vector2f> anAxes;
		Uint32 anIndex;
		sf::Vector2f anSmallestAxis;
		double anOverlap=std::numeric_limits<double>::max();
		Uint32 anMovingPointCount=theMovingShape.getPointCount();
		Uint32 anOtherPointCount=theOtherShape.getPointCount();
		sf::Vector2f anPointA, anPointB;
		//Axes for this object.
		for(anIndex=0;anIndex<anMovingPointCount-1;++anIndex)
		{
      anPointA=theMovingShape.getPoint(anIndex);
      anPointB=theMovingShape.getPoint(anIndex+1);
      anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		}
    anPointA=theMovingShape.getPoint(anMovingPointCount-1);
    anPointB=theMovingShape.getPoint(0);
		anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		//Axes for other object.
		for(anIndex=0;anIndex<theOtherShape.getPointCount()-1;++anIndex)
		{
      anPointA=theOtherShape.getPoint(anIndex);
      anPointB=theOtherShape.getPoint(anIndex+1);
      anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		}
    anPointA=theOtherShape.getPoint(anOtherPointCount-1);
    anPointB=theOtherShape.getPoint(0);
		anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		for(anIndex=0;anIndex<anAxes.size();++anIndex)
		{
			float anMinA, anMaxA, anMinB, anMaxB;
			// ... project the points of both OBBs onto the axis ...
			ProjectOntoAxis(theMovingShape,anAxes[anIndex], anMinA, anMaxA);
			ProjectOntoAxis(theOtherShape,anAxes[anIndex], anMinB, anMaxB);
			// ... and check whether the outermost projected points of both OBBs overlap.
			// If this is not the case, the Seperating Axis Theorem states that there can be no collision between the rectangles
			if(!((anMinB<=anMaxA)&&(anMaxB>=anMinA)))
			{
				return false;
			}
		  double o;
      if(anMinB<=anMaxA)
        o=anMaxA-anMinB;
      else
        o=anMaxB-anMinA;
      if(o<anOverlap)
      {
        anSmallestAxis=anAxes[anIndex];
        anOverlap=o;
      }
		}
		theMinimumTranslation=anSmallestAxis;
    theMinimumTranslation*=(float)anOverlap;
		return true;
	}
开发者ID:ItsJackson,项目名称:gqe,代码行数:60,代码来源:ICollisionSystem.cpp

示例2: toConvexShape

	sf::ConvexShape toConvexShape(const sf::Shape& shape)
	{
		const unsigned int size = shape.getPointCount();

		sf::ConvexShape convexShape;

		// Adapt shape properties
		convexShape.setFillColor(shape.getFillColor());
		convexShape.setOutlineColor(shape.getOutlineColor());
		convexShape.setOutlineThickness(shape.getOutlineThickness());
		convexShape.setPointCount(size);

		// Adapt transform properties
		convexShape.setPosition(shape.getPosition());
		convexShape.setRotation(shape.getRotation());
		convexShape.setScale(shape.getScale());
		convexShape.setOrigin(shape.getOrigin());

		// Adapt texture properties
		convexShape.setTexture(shape.getTexture());
		convexShape.setTextureRect(shape.getTextureRect());

		for (unsigned int i = 0; i < size; ++i)
		{
			convexShape.setPoint(i, shape.getPoint(i));
		}

		return convexShape;
	}
开发者ID:Psykoangel,项目名称:cpp_projects_repo,代码行数:29,代码来源:Shapes.cpp

示例3: ProjectOntoAxis

  void ICollisionSystem::ProjectOntoAxis(const sf::Shape& theShape, const sf::Vector2f& theAxis, float& theMin, float& theMax)
	{
    sf::Vector2f anPoint=theShape.getTransform().transformPoint(theShape.getPoint(0));
  	GQE::Uint32 anPointCount=theShape.getPointCount();
		theMin = (anPoint.x*theAxis.x+anPoint.y*theAxis.y);
		theMax = theMin;
		for (int j = 1; j<anPointCount; j++)
		{
			anPoint=theShape.getTransform().transformPoint(theShape.getPoint(j));
			float Projection = (anPoint.x*theAxis.x+anPoint.y*theAxis.y);

			if (Projection<theMin)
				theMin=Projection;
			if (Projection>theMax)
				theMax=Projection;
		}
	}
开发者ID:ItsJackson,项目名称:gqe,代码行数:17,代码来源:ICollisionSystem.cpp

示例4: collidesWith

bool TrackChunk::collidesWith(const sf::Shape &shape) const{
    bg::model::ring<sf::Vector2f> ring;
    for (std::size_t i=0; i<shape.getPointCount(); ++i)
        bg::append(ring, shape.getTransform().transformPoint(shape.getPoint(i)));
    return bg::intersects(ring, m_points);
}
开发者ID:Kojirion,项目名称:Tracks,代码行数:6,代码来源:TrackChunk.cpp

示例5:

static sf::Vector2f Shape_point(sf::Shape const& s, unsigned idx)
{
    if (idx >= s.getPointCount())
        throw "point index of shape out of range";
    return s.getPoint(idx);
}
开发者ID:Oberon00,项目名称:jd,代码行数:6,代码来源:SfGraphics.cpp


注:本文中的sf::Shape::getPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。