Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Syndog

Pages: [1]
1
Graphics / ConvexShape::getGlobalBounds() Problem
« on: November 23, 2013, 10:20:25 pm »
Hello, SFML gurus.  :)

I've been kicking around with the ConvexShape class today, and came across something curious.  When I make a call to the ConvexShape::getGlobalBounds() method, it returns a FloatRect whose position and/or size seems to be flawed as the shape rotates.

Here's a simple program to demonstrate...

#include <SFML/Graphics.hpp>

using namespace sf;

int main() {
   RenderWindow window(VideoMode(800, 600), "Bounding Box Demo");

   ConvexShape arrow(4);
   arrow.setPosition(400.0f, 300.0f);
   arrow.setFillColor(Color::Blue);
   arrow.setOutlineColor(Color::Blue);
   arrow.setOutlineThickness(1.0f);
   arrow.setPoint(0, Vector2f(0, -20));
   arrow.setPoint(1, Vector2f(30, 60));
   arrow.setPoint(2, Vector2f(0, 40));
   arrow.setPoint(3, Vector2f(-30, 60));

   Vertex pivotPoint[1];
   pivotPoint[0].position.x = 400.0f;
   pivotPoint[0].position.y = 300.0f;
   pivotPoint[0].color = Color::Yellow;

   FloatRect bounds;
   RectangleShape boundingBox;

   Event event;

   while (window.isOpen()) {
      while (window.pollEvent(event)) {
         if (event.type == sf::Event::Closed) window.close();
      }

      window.clear(Color::Black);

      arrow.rotate(0.01f);

      bounds = arrow.getGlobalBounds();
      boundingBox.setPosition(Vector2f(bounds.left, bounds.top));
      boundingBox.setSize(Vector2f(bounds.width, bounds.height));

      window.draw(boundingBox, RenderStates::Default);
      window.draw(arrow, RenderStates::Default);
      window.draw(pivotPoint, 1, sf::PrimitiveType::Points, RenderStates::Default);

      window.display();
   }

   return 0;
}
 

If the arrow is rotated in any of the cardinal compass directions (0, 90, 180, 270 degrees) , the bounding box matches the vertices flawlessly.  However, as the arrow rotates, the bounding box grows increasingly inaccurate as it approaches the diagonal directions (45, 135, 225, 315 degrees), leaving a sizable gap around the arrow's tip, while remaining true to the two ends of the arrow's tail...








I've tried running this using SFML 2.1, plus the latest source snapshot downloaded from the downloads page, and the same behavior persists.  I'm wondering if there's a problem with the ConvexShape::getGlobalBounds() method, or if perhaps I'm just misunderstanding what it's intended to provide.

Any insight would be greatly appreciated!

- Syn

2
SFML website / Database Errors When Searching
« on: June 08, 2013, 05:02:10 pm »
I'm trying to perform a search of the forums, but consistently get database errors, and told to report the error to an administrator.

Before:


After:


I'm using Google Chrome 27, but have also tried this on Firefox 21 with the same result.  Also tried disabling JavaScript, to no avail.

... --- ...

Pages: [1]