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

Author Topic: SFML 2.1 Vertex Example/Tutorial?  (Read 2584 times)

0 Members and 3 Guests are viewing this topic.

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
SFML 2.1 Vertex Example/Tutorial?
« on: September 22, 2014, 08:07:13 pm »
Correct me if I am wrong, but I can design an oddly shaped sprite myself by creating and storing a series of sf::vertex's, right? For instance, if I wanted to get the bounds of a sprite that's not a rectange shape, like a tetrimino that's not a square piece, I could set some sf::vertex's on the tetrimino's actual vertex's and call it a sprite, correct? The documentation is sort of weak on examples, so can somebody provide a more detailed explanation of how to use sf::vertex to create bounds for objects?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #1 on: September 22, 2014, 08:15:19 pm »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #2 on: September 22, 2014, 08:23:32 pm »
A square sprite with transparency (PNG's work well) are also often useful for oddly shaped stuff :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #3 on: September 22, 2014, 08:26:35 pm »
In case it's not clear, note that you can't define a custom shape directly with vertices, you'll have to combine several primitives to create more complex shapes. For a tetromino, you would combine 3, 4 or 5 quads for example.
Laurent Gomila - SFML developer

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #4 on: September 22, 2014, 10:29:34 pm »
In case it's not clear, note that you can't define a custom shape directly with vertices, you'll have to combine several primitives to create more complex shapes. For a tetromino, you would combine 3, 4 or 5 quads for example.
So, I couldn't define an irregular hexagon using a vertex array of 6 points? Are you saying that using several sf::FloatRect's would be the same thing?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #5 on: September 22, 2014, 10:32:55 pm »
You can do that with an sf::TrianglesFan and seven vertices (one for the center).  The tutorial I linked even shows (most of) a regular polygon made out of one.

Fundamentally it's all triangles drawn between vertices you provide.  A quad is just two triangles.  A tetronimo happens to be made of squares so it's probably slightly simpler to do it with quads than triangles.  That's all.

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #6 on: September 22, 2014, 10:52:49 pm »
You can do that with an sf::TrianglesFan and seven vertices (one for the center).  The tutorial I linked even shows (most of) a regular polygon made out of one.

Fundamentally it's all triangles drawn between vertices you provide.  A quad is just two triangles.  A tetronimo happens to be made of squares so it's probably slightly simpler to do it with quads than triangles.  That's all.
How exactly is a trianglesfan used? The tutorial explains what it is but not really how to create one.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #7 on: September 22, 2014, 11:19:40 pm »
You create it by adding the points enumerated in the tutorial image... where exactly is the problem?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #8 on: September 23, 2014, 12:37:16 am »
You create it by adding the points enumerated in the tutorial image... where exactly is the problem?
The problem is I'm trying to find a simple way to do collision detection for a simple game, but can't seem to find a way. I already have a topic on that, but I just posted this to find out if sf::vertex could get the job done. Apparently it would be just the same as using sf::rect, so I'll stick with that. Can you point me to a collisiom detection tutorial you'd recommend?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 2.1 Vertex Example/Tutorial?
« Reply #9 on: September 23, 2014, 09:38:07 am »
SFML's vertices are for rendering, not collision.

Write your own logic for collision detection and response. Which approach you use depends on your requirements regarding shape of the game objects and needed accuracy. Simple approaches entail rectangle or circle collision, more sophisticated ones are the Separating Axis Theorem. For polygon intersection, you can also use existing libraries such as Boost.Geometry.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything