SFML community forums

General => SFML wiki => Topic started by: Hapax on July 30, 2015, 05:03:11 pm

Title: Sprite3d
Post by: Hapax on July 30, 2015, 05:03:11 pm
NOTE: Sprite 3D is now included (and maintained) as a part of Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki).

Sprite3d (https://github.com/Hapaxia/Sprite3d)

Sprite3d could be considered a follow-up to the sprite animation temporary class, SpinningCard (http://en.sfml-dev.org/forums/index.php?topic=16388.0), which allows you to rotate a sprite around either the x axis or the y axis. It does this by animated the corners in an ellipse.
However, where SpinningCard was only intended to used during the spinning animation and then discarded, Sprite3d is intended to be used on its own.

Sprite3d does not animate corners using an ellipse; it uses a "proper" transformation matrix (albeit a rather compact one) to rotate around the x and y axes. This combined with the usual rotation around the z axis (this class inherits from sf::Transformable) and you can rotate around all three axes.

Sprite3d injects itself into the same namespace as SFML to allow for an easy and seamless transition from sf::Sprite to sf::Sprite3d.
Sprite3d is intended to be able to used in place of a standard SFML sprite with no changes to the code.

The source is, of course, available on my GitHub (https://github.com/Hapaxia/Sprite3d) and is also available on its Wiki page (https://github.com/SFML/SFML/wiki/Source:-Sprite3d).

Here's an early test screenshot (it really does not do it justice!):
(http://i.imgur.com/DCsLqJz.png)

The screenshot doesn't properly show what it does so here is a video of an early test example:
http://youtu.be/EAPDIlVEMKA

One thing to note is that this class doesn't solve the texture mapping problem evident in SpinningCard (and is evident in that screenshot - look at the lines). It does attempt to reduce the effects by a user-controlled number of triangles. The quality of this effect is therefore dependant on both mesh size and apparent depth.

If you want to see the mesh fixing the texture distortion, run the current example and start the rotation (press Space). Increase the Mesh Density to 4 (use the square brackets [ ] to adjust) and turn on dynamic subdivision (Return). Then increase the depth to 50 (use - and = to adjust). The example displays how many triangles are being used at any point in time.
For more controls, see the comments at the head of the example code.

To combat the texture distortion evident when a non-affine transformation (three dimensional rotation is a non-affine transformation as the edges stop being parallel) is applied to a quad, there are three features in Sprite3d that alter the mesh (size and number of triangles).

I invite people to try Sprite3d in place of any standard sprite you already have to see if the replacement is seemless or needs some work. I would appreciate any feedback on this (or any) matter.

GitHub repository for Sprite3d (https://github.com/Hapaxia/Sprite3d).

EDIT: updated to reflect complete version (1.0.0)

If anyone knows if it's possible to use a shader to fix the texture distortion, please let me know how.
Title: Re: Sprite3d
Post by: Ricky on August 02, 2015, 10:39:55 pm
Really cool! Keep up the interesting work Hapax.
Title: Re: Sprite3d
Post by: Hapax on August 03, 2015, 03:05:43 am
Thanks, Ricky  :)
Title: Re: Sprite3d
Post by: Hapax on August 05, 2015, 10:57:33 pm
Sprite3d has finally reached a complete version!
(http://i.imgur.com/DogPHrE.png)

Feel free to try it out and any feedback is welcome.

Updated original post to reflect changes (image and video are still of earlier test version).

As mentioned in the altered original post, I invite people to try Sprite3d in place of any standard sprite you already have to see if the replacement is seemless or needs some work. I would appreciate any feedback on this (or any) matter.
Title: Re: Sprite3d
Post by: Hapax on August 07, 2015, 07:18:34 pm
Finally posted the source on the Wiki (https://github.com/SFML/SFML/wiki/Source:-Sprite3d)  :)

Feedback on this class would be highly appreciated. Could it be improved somehow, or should I just assume it's already perfect?  ;D
Title: Re: Sprite3d
Post by: kitteh-warrior on August 07, 2015, 07:22:20 pm
Finally posted the source on the Wiki (http://en.sfml-dev.org/forums/index.php?topic=18698)  :)

Wouldn't this (https://github.com/SFML/SFML/wiki/Source%3A-Sprite3d) be the link to the Wiki?

The link here:
The source is, of course, available on my GitHub (https://github.com/Hapaxia/Sprite3d) and is also available on its Wiki page (http://en.sfml-dev.org/forums/index.php?topic=18698).
Brings me to this forum thread ;)
Title: Re: Sprite3d
Post by: Hapax on August 07, 2015, 07:46:27 pm
Haha. You're totally right!
I've fixed those links now. Thank you  :)
Title: Re: Sprite3d
Post by: pizzadox9999 on October 30, 2021, 03:05:05 am
Hello,

I would like to ask for a little help. First of all sprite3d looks super cool and so I would also like to use it. But I'm programming with java. It seems to me that this class is only available for c++(the c languages). If i'm wrong I would be a happy. So I would "port" that class over to java but i'm stuck with a lot of null pointer exceptions and magically working code. Like the getTransform() function. It seems like it's working without even declaring it? Also some logic won't explain to my small minded brain. So some help/advice would be cool. ;)
I hope it isn't rude to post just out of the blue here and sorry for the bad English.

Best regards pizzadox9999
Title: Re: Sprite3d
Post by: Hapax on November 06, 2021, 01:27:25 am
Hi and I'm glad you found some interest in Sprite 3D.

Hopefully, you're using the version of Sprite 3D within Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki/Sprite-3D) as the separate version will no longer be updated; it's maintained within Selba Ward. That said, it can still be used separately from the rest of Selba Ward. See the Selba Ward wiki (https://github.com/Hapaxia/SelbaWard/wiki) for some information on that (especially the Setup (https://github.com/Hapaxia/SelbaWard/wiki/Setup) page).

There is no official Java version and no other Java version that I know of so porting it yourself seems to be the only way. I'm unsure as to what null pointer exceptions are in Java and why you are getting them to be honest; I don't work with Java. However, here is a bit of information on why what you mention just 'magically works without declaring it':

SFML's Drawable class has a method called getTransform() that returns a sf::Transform. Sprite3D (both the separate one and the one inside Selba Ward) inherits from the Drawable class so that method is also automatically available to the derived class i.e. Sprite3D. It doesn't have to declare it itself because it's already declared inside SFML and within the Drawable class.

Hope that helps :)