Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create enum EmitterShape to allow for emitters other than circles #33

Merged
merged 4 commits into from
Jan 25, 2023

Conversation

MonaMayrhofer
Copy link
Contributor

I quickly threw this together for a project of mine, and thought I could as well ask if this is something that could be integrated into the upstream library.

I ran into a situation where I needed particles to be emitted from a line (think Clouds in the background e.g) and found no easy way to do this with this library, so I bundled the three spawn_radius, emitter_shape and emitter_angle properties of the ParticleSystem together into an enum EmitterShape::CircleSegment. Another variant of this enum is EmitterShape::Line which has similar fields that describe a line with a given length - possibly at an angle.

This enum has an impl with the sample function, which returns a random point on the shape of the emitter, which gets used by the particle_spawner system to determine the position and orientation of a newly spawned particle.

I also updated all the examples to account for this (breaking) change.

Copy link
Owner

@abnormalbrain abnormalbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks great. One small comment about what I think may be a bug, but otherwise very happy with it.

let rotation = Quat::from_rotation_z(angle);

Transform::from_translation(rotation * vec3(0.0, distance, 0.0))
.with_rotation(rotation)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this causes us to not correctly respect rotate_to_movement_direction if it is false. So I think we don't want to set transform rotation here (or for CircleSegment) and let the code in the spawn system do it after we return this transform.

Copy link
Contributor Author

@MonaMayrhofer MonaMayrhofer Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should get accounted for in the particle_spawner system in Line 142 and the following, where I override the transform.rotation if rotate_to_movement_direction is false. My thinking behind doing it that way, was that we need some way of communicating the movement direction of the particle from the EmitterShape back to the system, because the system does not really have a way of determining it. So some information about direction has to be communicated back from .sample anyways.

So the rotation of that transform basically describes the direction of movement, and not necessarily the rotation of the particle.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, ok, I see it now. Perfect!

let rotation = Quat::from_rotation_z(angle);

Transform::from_translation(rotation * vec3(0.0, distance, 0.0))
.with_rotation(rotation)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, ok, I see it now. Perfect!

Co-authored-by: Abnormal Brain Studios <102993888+abnormalbrain@users.noreply.github.com>
@abnormalbrain abnormalbrain merged commit 6348677 into abnormalbrain:main Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants