本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}