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

Author Topic: Pentagon not being quite right?  (Read 2450 times)

0 Members and 1 Guest are viewing this topic.

TheTedinator

  • Newbie
  • *
  • Posts: 2
    • View Profile
Pentagon not being quite right?
« on: March 28, 2011, 10:01:45 pm »
Hi, I'm trying to draw a star. A pentagon would be OK too, so that's what I'm working towards. I'm drawing 5 points at 72 degree intervals around the origin, then moving the shape to where you can see it. Unfortunately, it's not working. The angles aren't coming out right. What am I doing wrong?

Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <math.h>


int main()
{
const int pi=3.141592654;
    // Create main window
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Graphics");

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear screen
        App.Clear();

        // Draw apredefined shape
        //App.Draw(sf::Shape::Circle(200, 200, 100, sf::Color::Yellow, 10, sf::Color::Blue));
sf::Shape Star;
//Star.AddPoint((200*cos(((2*pi)/5))), (200*sin(((2*pi)/5))),  sf::Color::Yellow, sf::Color::Red);
// Star.AddPoint((200*cos(((4*pi)/5))), (200*sin(((4*pi)/5))),  sf::Color::Yellow, sf::Color::Blue);
// Star.AddPoint((200*cos(((6*pi)/5))), (200*sin(((6*pi)/5))),  sf::Color::Yellow, sf::Color::Green);
// Star.AddPoint((200*cos(((8*pi)/5))), (200*sin(((8*pi)/5))),  sf::Color::Yellow, sf::Color::Magenta);
// Star.AddPoint((200*cos(10*pi/5)), (200*sin(10*pi/5)),  sf::Color::Yellow, sf::Color::White);

Star.AddPoint((200*cos(((2*pi)/5))), (200*sin(((2*pi)/5))),  sf::Color::Yellow, sf::Color::Red);
//Star.AddPoint((200*cos(((4*pi)/5))), (200*sin(((4*pi)/5))),  sf::Color::Yellow, sf::Color::Blue);
Star.AddPoint((200*cos(((6*pi)/5))), (200*sin(((6*pi)/5))),  sf::Color::Yellow, sf::Color::Green);
//Star.AddPoint((200*cos(((8*pi)/5))), (200*sin(((8*pi)/5))),  sf::Color::Yellow, sf::Color::Magenta);
Star.AddPoint((200*cos(10*pi/5)), (200*sin(10*pi/5)),  sf::Color::Yellow, sf::Color::White);
Star.AddPoint((200*cos(((4*pi)/5))), (200*sin(((4*pi)/5))),  sf::Color::Yellow, sf::Color::Blue);
Star.AddPoint((200*cos(((8*pi)/5))), (200*sin(((8*pi)/5))),  sf::Color::Yellow, sf::Color::Magenta);
Star.Move(300, 300);
Star.EnableFill(true);
Star.EnableOutline(true);
Star.SetOutlineWidth(25);
App.Draw(Star);

        // Finally, display the rendered frame on screen
        App.Display();

    }

    return EXIT_SUCCESS;
}

maidis

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • SFML Geliştirme
Pentagon not being quite right?
« Reply #1 on: March 28, 2011, 10:35:12 pm »
pi must be 3.141592654 :)

const float pi=3.141592654;

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Pentagon not being quite right?
« Reply #2 on: March 29, 2011, 12:14:01 am »
Pi isn't an integer, it's a floating point. Use float or double instead of int.
I use the latest build of SFML2

TheTedinator

  • Newbie
  • *
  • Posts: 2
    • View Profile
Pentagon not being quite right?
« Reply #3 on: March 29, 2011, 02:52:40 am »
/facepalm. I can't believe I was that stupid... It works now, thanks!