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

Author Topic: draw ellipses  (Read 12388 times)

0 Members and 1 Guest are viewing this topic.

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
draw ellipses
« on: January 05, 2010, 09:43:54 pm »
How can I draw ellipses?

Cierpliwy

  • Newbie
  • *
  • Posts: 23
    • View Profile
draw ellipses
« Reply #1 on: January 05, 2010, 10:00:19 pm »
SFML doesn't support such primitives, or am i wrong?

So I would try to draw them using fragment shader if it's not a problem for you. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
draw ellipses
« Reply #2 on: January 05, 2010, 10:28:33 pm »
Create a circle shape and scale it in one direction to make it an ellipse.
Laurent Gomila - SFML developer

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
draw ellipses
« Reply #3 on: January 05, 2010, 10:48:25 pm »
the problem is that i'm make this for my paint program, i want to know de math for this

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
draw ellipses
« Reply #4 on: January 05, 2010, 10:50:28 pm »
There's no math.
Code: [Select]
sf::Shape ellipse = sf::Shape::Circle(...);
ellipse.SetScale(2, 1);


But if you're doing a paint program maybe you should manipulate individual pixels directly?
Laurent Gomila - SFML developer

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
draw ellipses
« Reply #5 on: January 05, 2010, 11:45:23 pm »
yes, i'm manipuling the pixels directily, for this, i want to know de math for make elipse with 4 points, X1,Y1,X2,Y2

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
draw ellipses
« Reply #6 on: January 06, 2010, 12:01:17 am »
Look at http://en.wikipedia.org/wiki/Ellipse or use google.

An ellipse is the set of all points, where the sum of distances between the point on the ellipse and each of two other specific points (focus) remains constant.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tomhet

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: draw ellipses
« Reply #7 on: July 06, 2013, 07:31:03 pm »
//math for ellipse

#include<cmath>



#define PI 3.1415926535898

float radius_x=50;
float radius_y=20;
unsigned short quality=70;

sf::ConvexShape ellipse;
    ellipse.setPointCount(quality);

for(unsigned short i=0;i<quality;++i){
    float rad=(360/quality*i)/(360/PI/2);
    float x=cos(rad)*radius_x;
    float y=sin(rad)*radius_y;

    ellipse.setPoint(i,sf::Vector2f(x,y));
};

ellipse.setPosition(100,100);

« Last Edit: July 06, 2013, 08:04:37 pm by Tomhet »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: draw ellipses
« Reply #8 on: July 06, 2013, 09:20:28 pm »
If you're looking for more general curves, you can have a look at sftools::Curve & sftools::CurveInfo here http://mantognini.github.io/sftools/public/doc/html/annotated.html. The code is hosted on github here https://github.com/mantognini/sftools
SFML / OS X developer

 

anything