SFML community forums

General => SFML projects => Topic started by: Hapax on September 24, 2014, 02:16:06 am

Title: Spinning Card
Post by: Hapax on September 24, 2014, 02:16:06 am
NOTE: you may be interested in the much more flexible follow-up to this class, called Sprite3D (http://en.sfml-dev.org/forums/index.php?topic=18698).
Sprite 3D is now included (and maintained) as a part of Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki).



I remember someone once mentioning animating a card so that it spins around without using OpenGL. I think the answer was simply "scale the width". I had said it could be faked by animating the corners but I think they thought that might be too complicated.

It inspired me to create something that spins a card easily without using OpenGL but still looks 3D (enough).

I bring you...
Spinning Card (https://github.com/Hapaxia/SpinningCard)

Here's a video of a really basic example of it in action (source code for example is on github):
http://www.youtube.com/watch?v=u428K0xyorI
The example code uses two SpinningCards - one for the front and one for the back - and switches which one to draw depending on the current angle. It animates the angle linearly from 0 to 360 degrees and animates the scale depending on the angle (to make it float forwards).
In this example, the card starts the spinning animation whenever the Space Bar is pressed. The "stuttering" is because of the key pressed quickly.

The class takes a sprite and mimics it by creating a vertex array and taking the sprite's position, origin, scale, rotation, colour, and its texture, which it takes a pointer to.

The card, by the way, can also be spun vertically.

If you can think of something that this class is missing, let me know. It's a simple class with a specific task in mind, though, so it probably shouldn't start including an ability to bend the card or anything  :P

As always, feel free to let me know if my code could be improved and how.  ;)
Title: Re: Spinning Card
Post by: Tommas on September 24, 2014, 09:10:06 pm
Thank you so much for this! I just got to the point in my card game where I was thinking, "Hmm... Now how do I flip the card over?" You were inspired.   :D
Title: Re: Spinning Card
Post by: Hapax on September 24, 2014, 11:08:37 pm
how do I flip the card over?
You could just animate the card's width  :P
This class was to give that spin a little more...depth. In fact, if you set the depth in this class to zero, it looks the same as just animating the width/height!

I'm glad you like it and it was of some help to you  :)
Title: Re: Spinning Card
Post by: zsbzsb on September 25, 2014, 02:20:26 am
Just my personal opinion... but I think this should belong in the 'wiki' section of the forum and maybe you should also post it on the actual SFML wiki.  ;)
Title: Re: Spinning Card
Post by: Hapax on September 25, 2014, 10:39:58 pm
this should belong in the 'wiki' section of the forum
I must admit that I'm not fully sure that I understand what the difference is between the two forums  ???
Title: Re: Spinning Card
Post by: zsbzsb on September 25, 2014, 10:55:43 pm
What is the difference between github gists and full github repos? Really its not that complicated. Projects belong here, small snippets belong on the wiki.
Title: Re: Spinning Card
Post by: eXpl0it3r on September 25, 2014, 11:25:17 pm
Slow down zsbzsb. ;D

The Projects sub forum is for any kind of project you want to present. You're free to choose how much you want to share and place it wherever you want to have it placed.

The Wiki sub forum is to link your tutorials or source codes which you've posted on the official wiki here in the forum as well.

If someone makes a small example of something, it's nice if they put it on the wiki as well, so it wouldn't get lost as easily, but just because something has a small code base doesn't mean it belongs into the wiki sub forum. ;)

Anyways, back to topic. The effect looks really cool, nicely done! :)
Title: Re: Spinning Card
Post by: zsbzsb on September 25, 2014, 11:40:15 pm
I thought we were already in my personal opinion land  :P (*writes note to start every post with IMO) Hapax asked what the difference was between the two forums and I said what I think people should use to separate them.

Quote
The Projects sub forum is for any kind of project you want to present.

Of course, nobody said otherwise.

Quote
it's nice if they put it on the wiki as well, so it wouldn't get lost as easily

And yes, that is another good reason to put it on the wiki (and the thread in that section), so it doesn't get lost.

And on topic... It does look really good.  :)
Title: Re: Spinning Card
Post by: Hapax on September 25, 2014, 11:50:44 pm
What is the difference between github gists and full github repos?
I have absolutely no idea. What's a gist?

The effect looks really cool, nicely done! :)
Thank you so much  :)

If I made an error and you think this post should be in a different forum, please feel free to move it.
Title: Re: Spinning Card
Post by: dabbertorres on September 26, 2014, 12:26:37 am
I have absolutely no idea. What's a gist?
It's github's version of pastebin pretty much.

And this does look quite good! Good job!
Title: Re: Spinning Card
Post by: Hapax on September 26, 2014, 04:02:35 pm
pastebin
???
I think you're underestimating just how noob I am  :P

And this does look quite good! Good job!
It does look really good.  :)
Thanks. I really appreciate this  :)
Title: Re: Spinning Card
Post by: dabbertorres on September 26, 2014, 06:46:51 pm
lol. Here's a link: https://gist.github.com

It's essentially a place to store codes snippets. Say... minimal examples?
Title: Re: Spinning Card
Post by: Jesper Juhl on September 26, 2014, 06:52:38 pm
Nice effect. I may be tempted to "borrow" it if I ever make a card game  ;D
Title: Re: Spinning Card
Post by: Hapax on September 27, 2014, 09:06:44 pm
I wanted to experiment to see what I could do with this class and I came up with this short experimental animation:
http://www.youtube.com/watch?v=yNSEmSMfbgQ
The class was unaltered  8)
It also allowed me to test out some of my mini-codes (easing, for example).

p.s. It seems ten seconds before beginning is a little too much  :'(

EDIT: If anyone's interested, here are the textures for the SFML card (front and back). Both are PNG format (they have rounded corners).
Download SFML card textures from MediaFire (http://www.mediafire.com/download/xfavekka35ez60u/SFML_Card.zip)
The only face provided is the SFML one. I doubt you'll have much need for the Hapax ones  ;D

Nice effect. I may be tempted to "borrow" it if I ever make a card game  ;D
Thanks :)
Title: Re: Spinning Card
Post by: StormWingDelta on November 28, 2014, 08:51:01 pm
hmm looks interesting.
Title: Re: Spinning Card
Post by: Raincode on April 18, 2015, 12:11:39 am
Hi,

I would like to use your class in an open-source game. I am kind of inexperienced with licensing and I don't know what I have to do so I am allowed to use your code.

BTW, I would like to add you to my credits section, however, I am unsure about how to actually credit you.

Raincode
Title: AW: Spinning Card
Post by: eXpl0it3r on April 18, 2015, 12:38:21 am
It uses the same license as SFML does. As long as you don't claim you wrote that piece of code, mark modifications as sucg and keep the license with the source, you're covered.
Crediting is not necessary but usually welcome and can be done in anyway you want, e.g. stating his name and maybe add a link. But of course if Hapax has a special wish he might say it himself. ;)
Title: Re: Spinning Card
Post by: Raincode on April 18, 2015, 10:38:01 am
Hi,

thanks for answering.

Does that mean I simply copy the license.txt from github into the game folder when I redistribute it?

Does this mean, that my game must run under the same license?

Raincode
Title: Re: Spinning Card
Post by: eXpl0it3r on April 18, 2015, 11:11:17 am
As far as I understand it, you only have to provide the license file when distributing the source code, so you won't even have to provide it, when you ship the binaries.
And no, you can pick nearly any license you want for your own source code.
Title: Re: Spinning Card
Post by: Raincode on April 18, 2015, 02:22:47 pm
I think I understood it now.

I have one more question regarding the SpinningCard: In my game, I have a vector of Cards (a own class that kind of combines 2 spinning cards to get an actual card (front+back)). I want to use std::random_shuffle on it, but I get this error with VC++:

std::random_shuffle(field.begin(), field.end());
error C2582: 'operator =' function is unavailable in 'hx::Misc::SpinningCard'

As I understand it, the default Copy-Assignment-Operator is not there (and the compiler can't provide one).
I am really unsure about how this function

SpinningCard& SpinningCard::operator=(const SpinningCard&);

would have to look like. Also, do I need a copy-constructor, too?

I would be very happy if someone could help me out with that, or maybe give me some alternatives where I don't need to define these.
Title: Re: Spinning Card
Post by: Nexus on April 18, 2015, 02:41:25 pm
Yes, your elements must support copy semantics (C++98) or at least move semantics (C++11) in order to be shuffled. That is, copy/move constructor and copy/move assignment operator must be accessible.

You're hijacking a project thread with basic C++ questions that are not even related to SFML... That's not nice. You should really have a look at a good C++ book, and ask programming-related questions on a different platform (e.g. StackOverflow).

Please don't pollute this thread further with off-topic discussions, let's focus on Spinning Card :)
Title: Re: Spinning Card
Post by: Hapax on April 19, 2015, 10:05:43 pm
Hi, Raincode. I'm glad that you are interested in using this class. It's nice that it's useful :)

Licensing-wise, it just requires that you include the licence with the source code and that you don't claim to have created it (this class).
It doesn't require credit outside of the source code but, of course, any is extremely appreciated. That said, suggested possible ways to credit - if you do still choose to do so - would be a link to my github (https://github.com/Hapaxia), a link to my profile on the SFML forum (http://en.sfml-dev.org/forums/index.php?action=profile;u=13086), my email (included in the licence), or just Hapax or Hapaxia  ;)

Spinning Card wasn't designed to be used as an actual object itself (that is copied, moved, compared, sorted etc.) but rather an animation object that temporarily replaces a standard sprite (the card) during the spin animation and then re-replaced by the sprite (the card - most likely, the other side). This way, if you only spin one card at a time, you only require one instance of SpinningCard, and it only needs to exist for the duration of the spin animation.
Title: AW: Spinning Card
Post by: eXpl0it3r on April 20, 2015, 04:00:12 pm
Btw it should be called license.txt and not licence.txt. ;)
Title: Re: Spinning Card
Post by: Raincode on April 23, 2015, 12:03:13 am
thanks for mentioning possible ways to credit. Additionally, thanks for the hint about the "correct" use of the class.

Maybe I can change my Code so it works the way you described, that way seems like it makes more sense.

Sorry for posting questions beforehand that were off-topic, it was wrong to do so.
Title: Re: AW: Spinning Card
Post by: Hapax on April 26, 2015, 09:32:56 pm
@Raincode
Don't worry too much about your questions. If I was clear about how the class worked, you wouldn't've needed to ask them (for this particular case) here.
I do have one request that I forgot to mention. If you do use this class, it would be great if you could 1) mention or link your project in this thread so that I can see how people found a use for it, and 2) "star" the repository on github (https://github.com/Hapaxia/SpinningCard). Thanks  :)

it should be called license.txt and not licence.txt. ;)
I beg to differ (http://www.future-perfect.co.uk/grammar-tip/is-it-license-or-licence/)  :P
Title: Re: AW: Spinning Card
Post by: eXpl0it3r on April 27, 2015, 09:38:53 am
it should be called license.txt and not licence.txt. ;)
I beg to differ (http://www.future-perfect.co.uk/grammar-tip/is-it-license-or-licence/)  :P
Ah well, it's again an British vs American English issue. ;D
Title: Re: Spinning Card
Post by: FRex on April 27, 2015, 01:43:51 pm
Quote
Ah well, it's again an British vs American English issue. ;D
The EU calls our driver permits "licence" in English texts (and Switzerland, despite not being a member, adopted some of the legislation of EU about driving licences and Swiss one has the word "licence" written on it too.. :D) so I'd say it's the correct one for us Europeans... :P
Title: Re: Spinning Card
Post by: Hapax on April 28, 2015, 02:12:04 am
I succumb to using American English in code for consistencies (e.g. color) but find no real reason to use it for comments, documentation, filenames, etc..
Of course, one is allowed to use which ever version one prefers/feels more comfortable with so I won't complain if anyone uses something I don't  :D