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

Author Topic: Sprite3d  (Read 31223 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Sprite3d
« on: July 30, 2015, 05:03:11 pm »
NOTE: Sprite 3D is now included (and maintained) as a part of Selba Ward.

Sprite3d

Sprite3d could be considered a follow-up to the sprite animation temporary class, SpinningCard, 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 and is also available on its Wiki page.

Here's an early test screenshot (it really does not do it justice!):


The screenshot doesn't properly show what it does so here is a video of an early test example:


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).
  • Mesh Density
    This is how many points are used per dimension, not including the edges. For example, if the mesh is created from 5x5 points, that's 5 points per dimension - 3 points per dimension, not including the edges. So, a mesh density of 3 would give you a mesh created from 5x5 points (a single quad is 2x2 points; 5x5 points creates 4x4 quads)
  • Subdivision level
    This is very similar to Mesh Density. It changes how many points are used for the mesh. Each subdivision divides each quad in the mesh into four quads. e.g.: 1 quad that is subdivided once becomes 4 quads, 1 quad that is subdivided twice becomes 16 quads, etc.
  • Dynamic Subdivision
    When enabled, Dynamic Subdivision changes the subdivision level automatically based on the most extreme angle. That is, the greatest rotation angle of pitch and yaw (around the x and y axes respectively). The range of subdivision can be specified; the default range is 1 to 4.
    Example: Using the default range, if pitch and yaw are both 0 (object is flat), the subdivision level would be 1, whereas if pitch or yaw is close to 90°, the subdivision level would be 3. Subdivision level 2 would be used if the most extreme angle was not almost 90° but was not almost flat.
    The range is interpolated linearly so (in the case of the default range) from 0° up to 30° the subdivision level would be 1, from 30° up to 60° degrees it would be 2, from 60° up to 90° it would be 3, and at 90° it would be 4.

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.

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.
« Last Edit: November 17, 2015, 11:55:16 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Ricky

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Tejada
    • Email
Re: Sprite3d
« Reply #1 on: August 02, 2015, 10:39:55 pm »
Really cool! Keep up the interesting work Hapax.
Wilt thou yet say before him that slayeth thee, I am God? but thou shalt be a man, and no God, in the hand of him that slayeth thee.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite3d
« Reply #2 on: August 03, 2015, 03:05:43 am »
Thanks, Ricky  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite3d
« Reply #3 on: August 05, 2015, 10:57:33 pm »
Sprite3d has finally reached a complete version!


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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite3d
« Reply #4 on: August 07, 2015, 07:18:34 pm »
Finally posted the source on the Wiki  :)

Feedback on this class would be highly appreciated. Could it be improved somehow, or should I just assume it's already perfect?  ;D
« Last Edit: August 07, 2015, 07:45:33 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

kitteh-warrior

  • Guest
Re: Sprite3d
« Reply #5 on: August 07, 2015, 07:22:20 pm »
Finally posted the source on the Wiki  :)

Wouldn't this be the link to the Wiki?

The link here:
The source is, of course, available on my GitHub and is also available on its Wiki page.
Brings me to this forum thread ;)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite3d
« Reply #6 on: August 07, 2015, 07:46:27 pm »
Haha. You're totally right!
I've fixed those links now. Thank you  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

pizzadox9999

  • Newbie
  • *
  • Posts: 4
  • SORRYZ
    • View Profile
    • Email
Re: Sprite3d
« Reply #7 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
https://github.com/pizzadox9999?tab=repositories
contains java ports of Hapax's c++ libs

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite3d
« Reply #8 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 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 for some information on that (especially the 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 :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*