Struct ParticleSystem

Source
pub struct ParticleSystem<P: Particle, G: Generator> { /* private fields */ }
Expand description

ParticleSystem is particle system. You can use custom shapes and position generator. other way to customize particles it though config.

§example

use rustbatch::{Window, Batch, Vect, FPS};
use rustbatch::render::particle::system::{ ParticleSystem, Initial, RandomizedProperty, Dynamic, Property};
use rustbatch::render::particle::system;
use rustbatch::math::rgba::{Graph, GraphPoint};
use std::f32::consts::PI;
use rustbatch::math::curve::Curve;
use rustbatch::render::particle::shapes::{SymmetricShape, Triangle};
use rustbatch::vect;

let (mut window, mut pump, _f, _g, _r) = Window::new(|sys| sys.window("segmentation", 400, 400).opengl().build().unwrap());
    let mut sys = system::no_texture(system::ParticleConfig {
        rotation_relative_to_spawn_direction: true,
        inverted: false,

        gravity: Vect::DOWN * 2.0,
        color: Graph::new(vec![GraphPoint::new(0.0, [0.0, 0.0, 1.0, 0.5]), GraphPoint::new(0.5, [1.0, 1.0, 0.0, 1.0]), GraphPoint::new(1.0, [0.0, 1.0, 0.0, 0.0])]),
        spread: PI,
        friction: 2.0,

        origin_attraction: 10.0,
        initial: Initial {
            velocity: RandomizedProperty::new(300.0, 150.0),
            rotation: RandomizedProperty::no_random(0.0),
            twerk: RandomizedProperty::no_random(10.0),
            live_time: RandomizedProperty::new(1.0, 0.5),
        },
        dynamic: Dynamic {
            acceleration: Property { curve: Curve::NONE, value: 0.0 },
            twerk_acceleration: Property { curve: Curve::NONE, value: 0.0 },
            scale: Property { curve: Curve::NONE, value: 20.0 }
        }
    }, Triangle::new(&[Vect::unit(0.0), Vect::unit(2.0 * PI/3.0), Vect::unit(4.0 * PI/3.0)]));

    let mut fps = FPS::new(1f32);
    'main: loop {
        for event in pump.poll_iter() {
            match event {
                /// break loop if X button on window is pressed
                sdl2::event::Event::Quit { .. } => break 'main,
                _ => {}
            }
        }

        let delta = fps.increase(0f32);


        window.clear();

        sys.update(delta);

        sys.spawn(10, vect!(0, 0), vect!(1, 0));

        sys.draw(&mut window.canvas);

        window.update();

    }

Implementations§

Source§

impl<P: Particle, G: Generator> ParticleSystem<P, G>

Source

pub fn customized( batch: Batch, config: ParticleConfig, shape: P, generator: G, ) -> Self

this is a core constructor. You will not get more customization then this.

Source

pub fn spawn(&mut self, count: usize, pos: Vect, dir: Vect)

spawns particles on given position in given direction

Source

pub fn update(&mut self, delta: f32)

call it every frame

Source

pub fn draw<T: Target>(&self, target: &mut T)

draw draws particles to target

Auto Trait Implementations§

§

impl<P, G> Freeze for ParticleSystem<P, G>
where P: Freeze, G: Freeze,

§

impl<P, G> RefUnwindSafe for ParticleSystem<P, G>

§

impl<P, G> !Send for ParticleSystem<P, G>

§

impl<P, G> !Sync for ParticleSystem<P, G>

§

impl<P, G> Unpin for ParticleSystem<P, G>
where P: Unpin, G: Unpin,

§

impl<P, G> UnwindSafe for ParticleSystem<P, G>
where P: UnwindSafe, G: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V