Added SetPointsCount in sf::CircleShape
This commit is contained in:
parent
048abbf46f
commit
c33fa1d290
@ -44,10 +44,11 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// \param radius Radius of the circle
|
||||
/// \param radius Radius of the circle
|
||||
/// \param pointsCount Number of points composing the circle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit CircleShape(float radius = 0);
|
||||
explicit CircleShape(float radius = 0, unsigned int pointsCount = 30);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the radius of the circle
|
||||
@ -69,11 +70,23 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
float GetRadius() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the number of points of the circle
|
||||
///
|
||||
/// \param count New number of points of the circle
|
||||
///
|
||||
/// \see GetPointsCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetPointsCount(unsigned int count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of points of the shape
|
||||
///
|
||||
/// \return Number of points of the shape
|
||||
///
|
||||
/// \see SetPointsCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual unsigned int GetPointsCount() const;
|
||||
|
||||
@ -92,7 +105,8 @@ private :
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
float myRadius; ///< Radius of the circle
|
||||
float myRadius; ///< Radius of the circle
|
||||
unsigned int myPointsCount; ///< Number of points composing the circle
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
@ -120,6 +134,15 @@ private :
|
||||
/// window.Draw(circle);
|
||||
/// \endcode
|
||||
///
|
||||
/// Since the graphics card can't draw perfect circles, we have to
|
||||
/// fake them with multiple triangles connected to each other. The
|
||||
/// "points count" property of sf::CircleShape defines how many of these
|
||||
/// triangles to use, and therefore defines the quality of the circle.
|
||||
///
|
||||
/// The number of points can also be used for another purpose; with
|
||||
/// small numbers you can create any regular polygon shape:
|
||||
/// equilateral triangle, square, pentagon, hexagon, ...
|
||||
///
|
||||
/// \see sf::Shape, sf::RectangleShape, sf::ConvexShape
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -32,9 +32,11 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
CircleShape::CircleShape(float radius)
|
||||
CircleShape::CircleShape(float radius, unsigned int pointsCount) :
|
||||
myRadius (radius),
|
||||
myPointsCount(pointsCount)
|
||||
{
|
||||
SetRadius(radius);
|
||||
Update();
|
||||
}
|
||||
|
||||
|
||||
@ -53,17 +55,26 @@ float CircleShape::GetRadius() const
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void CircleShape::SetPointsCount(unsigned int count)
|
||||
{
|
||||
myPointsCount = count;
|
||||
Update();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int CircleShape::GetPointsCount() const
|
||||
{
|
||||
return 30;
|
||||
return myPointsCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f CircleShape::GetPoint(unsigned int index) const
|
||||
{
|
||||
float angle = index * 2 * 3.141592654f / GetPointsCount();
|
||||
static const float pi = 3.141592654f;
|
||||
|
||||
float angle = index * 2 * pi / myPointsCount - pi / 2;
|
||||
float x = std::cos(angle) * myRadius;
|
||||
float y = std::sin(angle) * myRadius;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user