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

Author Topic: sf::vertexarray to make circles  (Read 8240 times)

0 Members and 2 Guests are viewing this topic.

ansh93

  • Newbie
  • *
  • Posts: 10
    • View Profile
sf::vertexarray to make circles
« on: November 15, 2014, 11:45:54 am »
I want to make circle using vertex arrays, how can I do that ?

I only want to be able to see the outline of the circle, I dont want a circle filled with a color, cuz I want to use it for debug drawing.
Help !!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::vertexarray to make circles
« Reply #1 on: November 15, 2014, 11:57:47 am »
What about spending 10 secs looking through the official tutorials before asking?

http://sfml-dev.org/tutorials/2.1/graphics-shape.php
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ansh93

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: sf::vertexarray to make circles
« Reply #2 on: November 15, 2014, 12:00:07 pm »
What about reading the whole question before replying ?
I said I want to create circle using vertex array, not using sf::CircleShape
« Last Edit: November 15, 2014, 12:02:20 pm by ansh93 »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::vertexarray to make circles
« Reply #3 on: November 15, 2014, 12:01:59 pm »
You approximate a circle with a polygon of many points. The points have the following positions:
center.x + radius * cos(angle)
center.y + radius * sin(angle)
angle is increased stepwise, so it's uniformly distributed in [0, 2*pi[.

Alternatively, you could use thor::PolarVector2f.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::vertexarray to make circles
« Reply #4 on: November 15, 2014, 12:16:29 pm »
You could always set the outline color and a transparent fill color for a shape.

If you otherwise want to use something "lower level" you might just have to learn the math behind it, as Nexus pointed out.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ansh93

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: sf::vertexarray to make circles
« Reply #5 on: November 15, 2014, 12:27:56 pm »
Cool I got the circle made up using the above method
Thanks  :D

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::vertexarray to make circles
« Reply #6 on: November 16, 2014, 02:18:20 am »
It's good that you got the vertex array working to make the circle as you wanted but, since you're only using it for "debugging" (assuming something like showing position feedback visually), you may way to look at what eXpl0it3r was talking about. CircleShapes can be much quicker and easier to set up than vertex arrays and they can easily draw rings (circle outlines with no fill).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ansh93

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: sf::vertexarray to make circles
« Reply #7 on: November 16, 2014, 09:41:53 am »
It's good that you got the vertex array working to make the circle as you wanted but, since you're only using it for "debugging" (assuming something like showing position feedback visually), you may way to look at what eXpl0it3r was talking about. CircleShapes can be much quicker and easier to set up than vertex arrays and they can easily draw rings (circle outlines with no fill).

Yup right, thats what my debug draw does, it just shows the collision boxes of all the objects.
I know sf::CircleShape method already, but I dont want to do it that way thats why I specifically for how to do them with vertex arrays.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: sf::vertexarray to make circles
« Reply #8 on: November 16, 2014, 01:46:38 pm »
A few years ago I wrote this tools: https://github.com/mantognini/sftools/blob/develop/include/sftools/Curve.hpp It can display arbitrary curves with custom color/thickness. In case that helps you..
SFML / OS X developer