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

Author Topic: Thor: Moving particle emitters  (Read 2827 times)

0 Members and 3 Guests are viewing this topic.

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Thor: Moving particle emitters
« on: December 03, 2014, 08:22:54 am »
Hello,

I'm trying out Thor 2.0 with the git development version of SFML and have a basic question about the particle system. However after several attempts and re-reads of the docs, I seem to be missing something simple or fundamental: how do I change the position of the particle emitters themselves after creation?

I need to be able to move emitters along with other moving objects in my game, such as the main character. However subsequent calls to emitter.setParticlePosition() have no effect, unless perhaps I completely remove and re-create the emitter on every frame, which of course doesn't make sense.

According to the tutorial:

Quote
There is one concrete emitter type in Thor, namely thor::UniversalEmitter. This class can determine parameters like emission rate as well as initial particle conditions such as position, rotation or lifetime. However, UniversalEmitter itself has no geometric representation in 2D space.

Since the API doesn't seem to have any obvious setPosition()-like method, beyond setting the initial parameters upon creation, what's the trick to transforming emitters in 2D space?

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Thor: Moving particle emitters
« Reply #1 on: December 03, 2014, 08:42:53 am »
I've never used Thor's particle system, but looking at the tutorial it seems you'd place the position of particles with: emitter.setParticlePosition()

For example:
emitter.setParticlePosition( thor::Distributions::circle(center, radius) )
Where center is the origin of the particles.

The emitters themselves are not objects/entities in the 2D space, they are more like "concepts" something.[/code]
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Thor: Moving particle emitters
« Reply #2 on: December 03, 2014, 08:49:52 am »
I've never used Thor's particle system, but looking at the tutorial it seems you'd place the position of particles with: emitter.setParticlePosition()

Thanks for the reply. Yes, at first glance that would seem like the solution - however as stated in my post, the setParticlePosition method only seems to effect the initial position. Subsequent calls to this method, after the emitter has been added into the particle system, have no effect.

The docs seem to confirm this:

Quote
Sets the initial particle position.

Seems like being able to transform emitters after creation would be basic functionality. I must be missing something.
« Last Edit: December 03, 2014, 09:02:20 am by frosty »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Thor: Moving particle emitters
« Reply #3 on: December 03, 2014, 09:06:11 am »
You're right, my bad.

Anyways it might just be that this is not possible, thus the name "UniversalEmitter". Guess we'll have to wait for a comment by Nexus, maybe it's already planned or we're missing something obvious. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Thor: Moving particle emitters
« Reply #4 on: December 03, 2014, 10:27:43 am »
Okay, I believe I've answered my own question. Or rather, I read the tutorial again and paid closer attention to the "Value and reference semantics" section.

Essentially, adding an emitter into the particle system is actually making a copy of that emitter. This section in the tutorial introduces refEmitter(), which adds it by reference instead. So, instead of doing:

particle_system.addEmitter(emitter);

I just needed to do:

particle_system.addEmitter(thor::refEmitter(emitter));

... and of course make sure the object remains in-scope. I can now successfully transform the emitter.

Very cool little library! Thanks to the author. I was kind of hoping I could skip writing particle and sprite animation stuff myself, at least for now. This looks like it should work for my needs, as long as I can successfully build it on all of the major platforms.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor: Moving particle emitters
« Reply #5 on: December 03, 2014, 10:38:14 am »
Cool that you could fix it :)

As eXpl0it3r said, emitters/affectors are not 2D entities. Nevertheless, it is possible to write your own emitter which has such semantics. For convenience, I provided thor::UniversalEmitter which allows to specify a variety of initial conditions in an easy way.

But instead of calling UniversalEmitter::setParticlePosition() repeatedly with a constant, you could consider passing it a function/functor/lambda expression once. This functor would then infer the position itself.
GameObject obj;
auto positionFunctor = [&obj] () // capture by reference
{
    return obj.getPosition();
};

thor::UniversalEmitter emitter;
emitter.setParticlePosition(positionFunctor);
Of course, you need to make sure that the referenced objects remain valid if you use this approach.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Thor: Moving particle emitters
« Reply #6 on: December 03, 2014, 10:45:20 am »
instead of calling UniversalEmitter::setParticlePosition() repeatedly with a constant, you could consider passing it a function/functor/lambda expression once. This functor would then infer the position itself.

Right on, thanks for the tip. That looks like it would be cleaner.