SFML community forums

General => SFML projects => Topic started by: Spidyy on February 17, 2010, 03:05:12 am

Title: [Utility] Stroke
Post by: Spidyy on February 17, 2010, 03:05:12 am
Hi there!

It doesn't come often that I post some code I made since I focus only on my shmup project. To change this bad habit, I post a little class I made during those 4 last days.

Stroke help you to draw lines from an array of points. Stroke allow you to change the stroke appearance and behavior throught many functions, like its thickness, inner and outer colors, textures, start and end thickness, smoothness (or sweepness), lifetime and many other things.

At first, this was a class to help me draw spaceship trails for my shmup (http://img96.imageshack.us/img96/9738/screenshotbw.jpg), but with time it became a more general class.

I took exemple from sf::Shape and sf::Sprite to compose this class.

Here is a small exemple of what you can do with it :
http://www.megaupload.com/?d=63QNKJ1M

And the Visual Studio project with sources :
http://www.megaupload.com/?d=VNW70BRA

In few words, you have 4 files :
- .cpp and .h of the Stroke class,
- my_utility.h, regrouping some math function from the wiki (http://www.sfml-dev.org/wiki/fr/sources/fonctions_maths) and many other functions I added, like Spline/Bezier function, collisions detection, etc... Functions numbered 2 are for inverted Y axis reference. I apologize but I didn't take time to write english comments, thoses are french ones, but most of function name are explicit.
(Just in case, the ResampleBezier one convert an array of non-equidistant points generated from previous Bezier fonction to another array of equidistant ones of same size.)
- The main.cpp used to create the exemple.

The sources are a bit commented but the class isn't documented.

I hope you will find some use for this class in your projects. :]

And of course, if you want to enhance the class with optimization or new features, feel free to do and share. :D There is plainty of things to do about this class.

EDIT : Last version on the wiki!
Quote

A video : http://www.youtube.com/watch?v=FL4B8KU-B00
A binary exemple (win32) : http://www.megaupload.com/?d=TACO1MWW
The sources of the binary : http://www.megaupload.com/?d=1U5BS38W
And the wiki : http://www.sfml-dev.org/wiki/en/sources/stroke
Title: [Utility] Stroke
Post by: model76 on February 17, 2010, 03:46:46 am
I just had a look at the example, and it looks fantastic!
This could actually replace the need for a full particle engine in many situations, and more. Very impressive!
Title: [Utility] Stroke
Post by: Spidyy on February 17, 2010, 04:52:23 pm
I added some stuff since last night :

Stroke 1.1
- "M_PI" constant has been renamed to "pi".
- A new "stippling" parameter has been added. It allow to add a stip or dot effect to the stroke.
- The exemple file has been updated with the new stippling effect.
- The joint adding system has been enhanced. You don't need to place all the joint of a single straitgh line to build it anymore. Just add the two extremities of the line after specifying a minimum segment lenght (SetMinSegmentLenght()), it will build itself.
- If you give 0 (default value) to the min_segment_lenght parameter, it will no longer add intermediate joints or ignore your joint will placing it. Much better for custom static strokes (road exemple).

Exemple :
http://www.megaupload.com/?d=N0METJ00

Sources :
http://www.megaupload.com/?d=JOCPNNYU
Title: [Utility] Stroke
Post by: JDieskau on February 17, 2010, 06:18:28 pm
It looks very good. I will give it a try. But why are you using megaupload? It looks a little bit "unprofessional". Whats wrong with sourceforge/berlios/github/... ?

EDIT: What version of sfml do you use?
Title: [Utility] Stroke
Post by: Spidyy on February 17, 2010, 06:26:51 pm
Huh, I just don't know those sites. =p

EDIT : I use SFML 2.0. Someone said the renderer is not available in SFML 1.5. I don't know if it will be accessible in SFML 1.6.
Title: [Utility] Stroke
Post by: Spidyy on February 17, 2010, 11:13:15 pm
Here are some few changes :

- Fixed some issue with the joint adding function, making the stroke segments of irregular lenght.
- Added more consistent comments in the main and Stroke.h.
- Changed the my_utility.h's comments to english ones.
- Cleaned some function calls from the main. Thoses calls were here without real meaning.

Exemples :
http://www.megaupload.com/?d=ZJEKHM6W

Sources :
http://www.megaupload.com/?d=LQY9INDP
Title: [Utility] Stroke
Post by: panithadrum on February 18, 2010, 12:19:55 pm
Excellent utility. I was looking for Bezier to compute roads yesterday lol :-D
Title: [Utility] Stroke
Post by: T.T.H. on February 18, 2010, 12:23:13 pm
I didn't have a look at it yet but in case it's only 4 files you could even put them into SFML's wiki (http://www.sfml-dev.org/wiki/en/index).
Title: [Utility] Stroke
Post by: phear- on February 18, 2010, 11:42:53 pm
Didnt look at the source yet but seems like a neat idea.
Title: [Utility] Stroke
Post by: Spidyy on August 05, 2010, 12:08:31 am
Heya! After a few time working on my shmup, I returned on this class to upgrade it with features I need.

Here are the result : 4 rendering mode, shaking, looping for closed shapes, texture management and more.

Here are some links :

A video : http://www.youtube.com/watch?v=FL4B8KU-B00
A binary exemple (win32) : http://www.megaupload.com/?d=TACO1MWW
The sources of the binary : http://www.megaupload.com/?d=1U5BS38W
And the wiki : http://www.sfml-dev.org/wiki/en/sources/stroke

Enjoy!
Title: [Utility] Stroke
Post by: panithadrum on August 05, 2010, 06:47:35 am
Wow Spidyy this is amazing now!
Title: [Utility] Stroke
Post by: ActionBoy on August 13, 2010, 09:36:40 pm
Awesome. The road and the laser is just wow.
Title: Re: [Utility] Stroke
Post by: Nexxtron on November 07, 2012, 12:32:55 am
This class looks really amazing, but the Link is broken... :'(
Has anyone the example project and can upload it?
Title: Re: [Utility] Stroke
Post by: eXpl0it3r on November 07, 2012, 01:52:37 am
You're quite bold to bring up a two year old thread for you first post. ;D
Luckily around community doesn't have anything against that... ;)

Anyways the original author stated that he doesn't have the example anymore but he's working on a new version + example.

See here (http://en.sfml-dev.org/forums/index.php?topic=9438.msg64448#msg64448):
Quote from: Spidyy
Someone really wanted to use the Stroke class, so I'm working on it to port it to SFML 2.0 and give it a few enhancements.

Also I've made a dirty port of the library to SFML 2 here (https://legacy.sfmluploads.org/file/151).
Title: Re: [Utility] Stroke
Post by: SuperV1234 on November 07, 2012, 02:10:45 pm
Impressive! Why not put the code on GitHub?
Title: AW: Re: [Utility] Stroke
Post by: eXpl0it3r on November 07, 2012, 02:24:47 pm
Impressive! Why not put the code on GitHub?
Because the original code is not mine and the new code is a dirty adaption which isn't fully tested and Spidyy said he'd have a new version soon... ;)
Title: Re: [Utility] Stroke
Post by: Nexxtron on November 07, 2012, 06:16:13 pm
I´m glad to hear that this project still goes on  :) can´t wait.
Meanwhile, I try the "dirty" sfml 2 port :D ( my port doesn´t work quite good... )
Title: Re: [Utility] Stroke
Post by: StormWingDelta on November 10, 2012, 11:00:14 pm
This could be useful if updated.  Any word on it yet?
Title: Re: [Utility] Stroke
Post by: Spidyy on November 13, 2012, 03:21:19 am
Well sorry about the "soon", but it takes a bit more time that planned, due to real life priorities.

I'm still working on it, and I can say this for sure :

- All the naming of the class is rewrited to be more in a well made way. (no more this everywhere.)
- Added an Radomizer class with the stroke, that way stroke with randomize themselves even after the disapearance of SFML randomizer.
- No more draw modes, only 2 draw is supported : textured and non textured. I don't think the Line rendering is used for games, more for my own debugging.
- No more sweep attributes, the way the stroke is shaped will be replaced by another more flexible mean, allowing you to shape the Stroke anyway you like from its start to its end.
- No more stippling, as in fact, a little texture trick can do the work.
- A stroke can now be "closed", meaning you can draw perfect circle with it, the start and end point will join themselves nicely.
- You will have to call for an "update" function each frame before rendering to ensure the stroke is correctly computed, except if you don't add any joint or the stroke is not self-animated.

Well I still have the texturing and the shaping system to work on before releasing.
Title: Re: [Utility] Stroke
Post by: Kain5056 on July 22, 2013, 08:53:02 pm
Does anyone still have the files? This looks crazy awesome, and it would be great if someone could re-upload the code.  :)

Or at least some pointers on how it was done, this would also be helpful if the files are already lost.  ;D
Title: Re: [Utility] Stroke
Post by: eXpl0it3r on July 22, 2013, 10:15:14 pm
I really hoped Spidyy would get around to do a whole rewrite, but I don't think that's gonna happen. :-\

Here's my dirty port to SFML 2.0: https://gist.github.com/eXpl0it3r/6057215
But since it's already again quite a few month old, it might not be working anymore.

For the concept, it's mostly just a lot of math. ;)