Use new sf::Vector2<T> utilities
This commit is contained in:
parent
411d702d7a
commit
7dfc7f0202
@ -36,18 +36,12 @@ namespace
|
|||||||
// Compute the normal of a segment
|
// Compute the normal of a segment
|
||||||
sf::Vector2f computeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2)
|
sf::Vector2f computeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2)
|
||||||
{
|
{
|
||||||
sf::Vector2f normal(p1.y - p2.y, p2.x - p1.x);
|
sf::Vector2f normal = (p2 - p1).perpendicular();
|
||||||
float length = std::sqrt(normal.x * normal.x + normal.y * normal.y);
|
float length = normal.length();
|
||||||
if (length != 0.f)
|
if (length != 0.f)
|
||||||
normal /= length;
|
normal /= length;
|
||||||
return normal;
|
return normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the dot product of two vectors
|
|
||||||
float dotProduct(const sf::Vector2f& p1, const sf::Vector2f& p2)
|
|
||||||
{
|
|
||||||
return p1.x * p2.x + p1.y * p2.y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -280,9 +274,9 @@ void Shape::updateOutline()
|
|||||||
|
|
||||||
// Make sure that the normals point towards the outside of the shape
|
// Make sure that the normals point towards the outside of the shape
|
||||||
// (this depends on the order in which the points were defined)
|
// (this depends on the order in which the points were defined)
|
||||||
if (dotProduct(n1, m_vertices[0].position - p1) > 0)
|
if (n1.dot(m_vertices[0].position - p1) > 0)
|
||||||
n1 = -n1;
|
n1 = -n1;
|
||||||
if (dotProduct(n2, m_vertices[0].position - p1) > 0)
|
if (n2.dot(m_vertices[0].position - p1) > 0)
|
||||||
n2 = -n2;
|
n2 = -n2;
|
||||||
|
|
||||||
// Combine them to get the extrusion direction
|
// Combine them to get the extrusion direction
|
||||||
|
Loading…
Reference in New Issue
Block a user