p->colour = colour;
}
+static void particle_spawn_cone( particle_system *sys,
+ v3f co, v3f dir, f32 angle, f32 speed,
+ f32 lifetime, u32 colour ){
+ if( sys->alive == sys->max ) return;
+
+ particle *p = &sys->array[ sys->alive ++ ];
+
+ v3f tx, ty;
+ v3_tangent_basis( dir, tx, ty );
+
+ v3f rand;
+ vg_rand_cone( &vg.rand, rand, angle );
+ v3_muls( tx, rand[0]*speed, p->v );
+ v3_muladds( p->v, ty, rand[1]*speed, p->v );
+ v3_muladds( p->v, dir, rand[2]*speed, p->v );
+
+ p->life = lifetime;
+ p->colour = colour;
+ v3_copy( co, p->co );
+}
+
static void particle_system_update( particle_system *sys, f32 dt ){
u32 i = 0;
iter: if( i == sys->alive ) return;
VG_CHECK_GL_ERR();
}
-static void particle_init( particle_system *sys, u32 max ){
+static void particle_alloc( particle_system *sys, u32 max ){
static int reg = 1;
if( reg ){
shader_particle_register();
size_t stride = sizeof(particle_vert);
- particles_grind.max = max;
- particles_grind.array =
- vg_linear_alloc( vg_mem.rtmemory, max*sizeof(particle) );
- particles_grind.vertices =
- vg_linear_alloc( vg_mem.rtmemory, max*stride*4 );
+ sys->max = max;
+ sys->array = vg_linear_alloc( vg_mem.rtmemory, max*sizeof(particle) );
+ sys->vertices = vg_linear_alloc( vg_mem.rtmemory, max*stride*4 );
vg_async_item *call =
vg_async_alloc( sizeof(particle_system *) + max*sizeof(u16)*6 );
v3f v, right;
v3_copy( p->v, v );
- v3_normalize( v );
+
+ f32 vm = v3_length( p->v );
+ v3_muls( v, 1.0f/vm, v );
v3_cross( v, (v3f){0,1,0}, right );
- f32 l = 0.3f, w = 0.025f;
+ f32 l = (sys->scale+sys->velocity_scale*vm),
+ w = sys->width;
v3f p0, p1;
v3_muladds( p->co, p->v, l, p0 );
static void particle_system_render( particle_system *sys, camera *cam ){
glDisable( GL_CULL_FACE );
- glDisable( GL_DEPTH_TEST );
+ glEnable( GL_DEPTH_TEST );
shader_particle_use();
shader_particle_uPv( cam->mtx.pv );