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

Author Topic: Thor C++ Library – An SFML extension  (Read 137956 times)

0 Members and 2 Guests are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #90 on: July 04, 2011, 12:23:41 pm »
thor::ScaleAffector is now ready to use.

I have found out that making the constructors private is a bad idea since it prevents justified use cases like inheriting or aggregating an existing affector/emitter, therefore I won't do it.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Haikarainen

  • Guest
Thor C++ Library – An SFML extension
« Reply #91 on: July 04, 2011, 01:40:03 pm »
Quote from: "Nexus"
Do you have a suggestion how I could make it more configurable? I don't know how to set the strength, because the glow just influences the OpenGL blend mode (ParticleSystem.cpp, line 300).


Hmm googled around on the function and it uses, and it became clear to me that it's the textures that have to be modified. Apparently too much lightness and too little transparency creates a way too bright result.

Haikarainen

  • Guest
Thor C++ Library – An SFML extension
« Reply #92 on: July 04, 2011, 01:58:42 pm »
Quote from: "Nexus"
thor::ScaleAffector is now ready to use.


Sweet ! :D

Btw, I fixed the cmake issue, can configure, generate and compile :) After cleaning up everything, all old sfml and thor-stuff, paths in env-vars etc, and downloading fresh copies, it STILL didn't work.

What I had to do was set the "CMAKE_MODULE_PATH" in cmake manually to "sfml2dir/cmake/Modules", weirdly enough it wasnt able to find the FindSFML file until then, even when I set the SFML_DIR and SFMLDIR path's correctly!

Ohwell it works now, even tho the binaries were placed in the src-dir, i really hope i helped out someone else with the same problem :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #93 on: July 04, 2011, 03:32:33 pm »
Quote
What I had to do was set the "CMAKE_MODULE_PATH" in cmake manually to "sfml2dir/cmake/Modules"

If you install SFML properly (I insist on "install", not "compile") the FindSFML.cmake file should be copied to the CMake directory and therefore be automatically available. So I think you just forgot to install it ;)
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Thor C++ Library – An SFML extension
« Reply #94 on: July 04, 2011, 04:25:44 pm »
Quote from: "Laurent"
Quote
What I had to do was set the "CMAKE_MODULE_PATH" in cmake manually to "sfml2dir/cmake/Modules"

If you install SFML properly (I insist on "install", not "compile") the FindSFML.cmake file should be copied to the CMake directory and therefore be automatically available. So I think you just forgot to install it ;)


Oooooooh :D Thanks for filling that in for me, now i should know in the future :) Doing stuff i always use linux for, in windows is confusing. hehe

Edit: Btw, did you mean the sfmldir/cmake dir ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #95 on: July 04, 2011, 07:28:53 pm »
Quote
Edit: Btw, did you mean the sfmldir/cmake dir ?

Hum? I was just talking about the FindSFML.cmake file.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #96 on: July 05, 2011, 12:25:07 am »
Didn't I tell you this in the other thread? Okay, it was probably not that clear :P

Back to topic: I finally need to make the animations more flexible. I have thought about a design like this:
Code: [Select]
class Animation
{
    public:
        virtual ~Animation();
        virtual void Apply(sf::Sprite& sprite, float passedTime) = 0;
};

Concrete animations modifying different properties of a sprite (subrect, color, ...) are represented by separate derived classes. This is very similar to the thor::Affector class hierarchy. The important point is that the user can write his own animations.

The thor::Animator class is going to remain more or less the same, except that it takes shared_ptr<Animation> instead of copies and that there is no more default subrect, but a default animation being applied when no other animation is active. And perhaps I am going to transform it to a template in order to allow arbitrary IDs (not only strings).

Then I also need a way to combine multiple animations: Parallel (modify subrect and color at the same time) and perhaps also sequential (after setting the subrects, change color). I can achieve this by writing a class like this:
Code: [Select]
class CombinedAnimation : public Animation
{
    public:
        // Adds an animation that starts delay seconds after the normal
        // start (so we can parallelize time-shifted versions)
        void AddAnimation(shared_ptr<Animation> anim, float delay = 0.f);

        // Applies all animations
        virtual void Apply(sf::Sprite& sprite, float passedTime);
};

Maybe also a separate class for sequential animations, although this can theoretically be done with the above delay. I don't know whether this delay is a good idea, I will probably not add it from beginning.

What do you think? Far too complicated? Not generic enough? All suggestions are welcome!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gavintlgold

  • Newbie
  • *
  • Posts: 21
    • View Profile
Thor C++ Library – An SFML extension
« Reply #97 on: July 05, 2011, 12:33:58 am »
I was thinking about this very recently, and how it might be useful to me. Basically, what would be great to have is a tweener system, that interpolates any float variables. I'm not sure exactly how this could be done, but perhaps if you wrap a small struct around a variable such as a float or Vector2f (sort of like a smart pointer does) and then use that, it might work very well. This would support animations that involve movement, fading, zooming, and really anything you can think of, since it's generic enough to apply to anything.

Where this sort of thing gets very powerful is in interpolation types--adding in support for linear, cubic, 'bouncy' (overshooting), and other stuff. This would be useful for a huge amount of purposes--title screen animations, fading sprites in and out, particle affectors, even cameras (zoomy cameras look nicer--I'm using a homemade one myself but it's a lot of messiness to manage)

There are tweening libraries out there, for example http://code.google.com/p/cpptweener/ . If you think making a tweener is out of the scope of Thor, I'll probably end up using that instead--but having it integrated into particles and things would be very nice indeed.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #98 on: July 05, 2011, 01:03:57 am »
You won't believe it, I have already had some kind of an interval class in mind, also to produce random numbers. I haven't considered it useful enough yet... But I will certainly take a look at the cpptweener library, thanks for the link.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gavintlgold

  • Newbie
  • *
  • Posts: 21
    • View Profile
Thor C++ Library – An SFML extension
« Reply #99 on: July 05, 2011, 01:21:35 am »
Sounds good. cpptweener's method, which basically involves references to variables, seems somehow unsafe. Also, it uncouples the variable from the tweener, which is nice if you need to tween multiple things with one tweener, but not so good for making quick tweens as it involves at least two variables to juggle. However, it's likely a great source for the math behind nonlinear tweens--it can get a little heady at times, at least for me.

I think having a wrapper with an operator() or somesuch to get the contained type would be a neater way to do it properly. Calling it "Range<contained>" might work nicely. I imagine something like this:

Code: [Select]
template <typename T>
class Range
{
    public:
        const T& operator()() // could also be GetValue() or somesuch
        {
            return mType;
        }

        void Update(float percentage);
        void SetStep(float step);

    private:
        T mType;
        float mStep;
};


I imagine you can derive different types of tweens from that, like LinearRange, CubicRange etc. Alternatively you can have an enum for range types, but I think this way is better.

EDIT: Changed to floats for timestep

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Thor C++ Library – An SFML extension
« Reply #100 on: July 05, 2011, 01:38:24 am »
When doing a game I'm interested on updating animations accordingly to the current game frame, which is an integer for me. I tell an animation when it started, then I ask it to update accordingly to the current frame. Animation duration is in frames. This way an animation always run the same way whatever the frame rate is. This isn't generic, neither using a float for time.

I strongly recommend a float interpolation param from 0 to 1. It's simple to convert between game time/frames to animation time, knowing when the animation started and it's duration (whatever that means for the user).

I'm working on a project which intends to provide a generic sprite format for 2D games and that's how I intend to provide animations mainly. I'll post about it when I get the binding for SFML working..
Edit: Actually I stick with the integer duration but provide both time and 0-1 float access.
Pluma - Plug-in Management Framework

gavintlgold

  • Newbie
  • *
  • Posts: 21
    • View Profile
Thor C++ Library – An SFML extension
« Reply #101 on: July 05, 2011, 01:48:07 am »
Yes, you're right. The container's progress should be measured in a float between 0 and 1, so that you don't have to deal with time at all. I think having the two methods "Update" and "SetStep" are good though, as that way some people can set the value manually, and others can attach it to existing timers.

It gets rid of having to scale the timestep within the class as well, instead it can be handled by the user like this: Update((float)dt * 0.25f) or whatever.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #102 on: July 05, 2011, 01:56:28 pm »
I have downloaded cppTweener, but up to now, I haven't been able to create meaningful scenarios. The code is completely undocumented and the examples  depend on other libraries. Apart from that, some code in cppTweeners relies on unspecified behavior and is thus not standard-conforming. For example, the evaluation order of t and --t in the following statement is not defined by the C++ standard.
Code: [Select]
return -c/2 * (((t-2)*(--t)) - 1) + b;
Would you mind explaining me the most important functionality? Is the basic concept a function that takes a float in [0, 1] and returns a scaled version in [a, b], whereby this transformation can be linear, cubic or whatever?

I rather don't plan to provide all these mathematical mappings, but maybe an interface that allows customization by the user. Do you have concrete suggestions for an integration into Animations?

By the way, what do you think about the basic Animation design as described above?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gavintlgold

  • Newbie
  • *
  • Posts: 21
    • View Profile
Thor C++ Library – An SFML extension
« Reply #103 on: July 05, 2011, 08:48:03 pm »
I never really looked at the code for it, and I may have confused it with another library which I took a closer look at. But yes, the idea is that you can set a starting and end position and it will give you an interpolation between 0 and 1. The simplest example is linear, where 0 equals the starting position and 1 equals the ending position, and anything in between is just an even subdivision. More useful are the other types though, which allow you to have movement that starts out fast and slows down as it gets closer to its target. Then you have ease in and ease out, which allow you to start slowly and speed up or start fast and slow down, or start and end slowly.

Basically it's useful when you don't want to snap directly to a target but move there smoothly. It's a bit hard for me to describe properly, but maybe this video makes more sense:

If you look at the time I've linked to, when the desktop is zooming out it speeds up near the middle and slows down right before it reaches its target. It would look bad if it was just a linear scaling effect, but since it uses tweening it looks 'smooth'.

Anyway, that's an example of how you can apply an effect to a sprite, but it's also useful for fading text and moving views, and things like that. That's why I suggested making it more generic to accept any sort of variable.

Again, if you don't think it's something that would fit into Thor, don't worry about it--I'll probably try to make my own version. I most likely release it, too.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Thor C++ Library – An SFML extension
« Reply #104 on: July 06, 2011, 12:42:59 am »
I think it would be enough to provide a generic interface for animations with an update function which takes a float param ranging from 0-1. It's then the implementations that decide how to deal with it to interpolate its information.

You can eventually overload the function to accept an extra argument of some class or function pointer that transforms the argument with a math function. In that case you can supply some strategies by default, like polynomial and trigonometric.
Pluma - Plug-in Management Framework

 

anything