libpsys
changeset 8:a10f19674147
ha!
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Tue, 27 Sep 2011 21:47:27 +0300 |
parents | 3c0a306c5f01 |
children | 9c24273f211b |
files | examples/simple/simple.c src/pattr.c src/psys.c src/rndval.c src/rndval.h |
diffstat | 5 files changed, 51 insertions(+), 6 deletions(-) [+] |
line diff
1.1 --- a/examples/simple/simple.c Tue Sep 27 07:52:01 2011 +0300 1.2 +++ b/examples/simple/simple.c Tue Sep 27 21:47:27 2011 +0300 1.3 @@ -12,6 +12,7 @@ 1.4 #include <imago2.h> 1.5 #include "psys.h" 1.6 1.7 +void cleanup(void); 1.8 void disp(void); 1.9 void idle(void); 1.10 void reshape(int x, int y); 1.11 @@ -41,21 +42,30 @@ 1.12 glClearColor(0.05, 0.05, 0.05, 1); 1.13 1.14 if(!(tex = load_texture("pimg.png"))) { 1.15 - fprintf(stderr, "failed to load the FUCKING TEXTURE GOD DAMN IT\n"); 1.16 + fprintf(stderr, "failed to load the texture\n"); 1.17 return 1; 1.18 } 1.19 1.20 if(!(ps = psys_create())) { 1.21 return 1; 1.22 } 1.23 - psys_set_grav(ps, v3_cons(0, -9, 0), 0); 1.24 - psys_set_life(ps, 2, 0); 1.25 - psys_set_texture(ps, tex); 1.26 + psys_set_value3(&ps->attr.grav, 0, v3_cons(0, -9, 0)); 1.27 + psys_set_anm_rnd(&ps->attr.life, 0, 2, 0); 1.28 + psys_set_value3(&ps->attr.spawn_range, 0, v3_cons(0.2, 0.2, 0.2)); 1.29 + psys_set_anm_rnd3(&ps->attr.dir, 0, v3_cons(0, 0, 0), v3_cons(2, 2, 2)); 1.30 + ps->attr.tex = tex; 1.31 + 1.32 + atexit(cleanup); 1.33 1.34 glutMainLoop(); 1.35 return 0; 1.36 } 1.37 1.38 +void cleanup(void) 1.39 +{ 1.40 + psys_free(ps); 1.41 +} 1.42 + 1.43 void disp(void) 1.44 { 1.45 static unsigned int prev_msec; 1.46 @@ -101,7 +111,7 @@ 1.47 { 1.48 bnstate[bn - GLUT_LEFT_BUTTON] = state == GLUT_DOWN; 1.49 if(bn == GLUT_LEFT_BUTTON) { 1.50 - psys_set_rate(ps, state == GLUT_DOWN ? 30.0 : 0.0, 0); 1.51 + psys_set_value(&ps->attr.rate, 0, state == GLUT_DOWN ? 30.0 : 0.0); 1.52 psys_set_pos(ps, get_mouse_hit(x, y), 0); 1.53 } 1.54 }
2.1 --- a/src/pattr.c Tue Sep 27 07:52:01 2011 +0300 2.2 +++ b/src/pattr.c Tue Sep 27 21:47:27 2011 +0300 2.3 @@ -34,6 +34,10 @@ 2.4 goto err; 2.5 2.6 attr->max_particles = -1; 2.7 + 2.8 + anm_set_track_default(&attr->size.value.trk, 1.0); 2.9 + anm_set_track_default(&attr->life.value.trk, 1.0); 2.10 + 2.11 return 0; 2.12 2.13 err:
3.1 --- a/src/psys.c Tue Sep 27 07:52:01 2011 +0300 3.2 +++ b/src/psys.c Tue Sep 27 21:47:27 2011 +0300 3.3 @@ -173,7 +173,7 @@ 3.4 spawn_dt = dt / (float)spawn_count; 3.5 spawn_tm = em->last_update; 3.6 for(i=0; i<spawn_count; i++) { 3.7 - if(em->pcount >= em->attr.max_particles) { 3.8 + if(em->attr.max_particles >= 0 && em->pcount >= em->attr.max_particles) { 3.9 break; 3.10 } 3.11
4.1 --- a/src/rndval.c Tue Sep 27 07:52:01 2011 +0300 4.2 +++ b/src/rndval.c Tue Sep 27 21:47:27 2011 +0300 4.3 @@ -38,6 +38,31 @@ 4.4 } 4.5 4.6 4.7 +void psys_set_rnd(struct psys_rnd *r, float val, float range) 4.8 +{ 4.9 + r->value = val; 4.10 + r->range = range; 4.11 +} 4.12 + 4.13 +void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range) 4.14 +{ 4.15 + r->value = val; 4.16 + r->range = range; 4.17 +} 4.18 + 4.19 +void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range) 4.20 +{ 4.21 + psys_set_value(&r->value, tm, val); 4.22 + psys_set_value(&r->range, tm, range); 4.23 +} 4.24 + 4.25 +void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range) 4.26 +{ 4.27 + psys_set_value3(&r->value, tm, val); 4.28 + psys_set_value3(&r->range, tm, range); 4.29 +} 4.30 + 4.31 + 4.32 float psys_eval_rnd(struct psys_rnd *r) 4.33 { 4.34 return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
5.1 --- a/src/rndval.h Tue Sep 27 07:52:01 2011 +0300 5.2 +++ b/src/rndval.h Tue Sep 27 21:47:27 2011 +0300 5.3 @@ -27,6 +27,12 @@ 5.4 int psys_init_anm_rnd3(struct psys_anm_rnd3 *v); 5.5 void psys_destroy_anm_rnd3(struct psys_anm_rnd3 *v); 5.6 5.7 +void psys_set_rnd(struct psys_rnd *r, float val, float range); 5.8 +void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range); 5.9 + 5.10 +void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range); 5.11 +void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range); 5.12 + 5.13 float psys_eval_rnd(struct psys_rnd *r); 5.14 vec3_t psys_eval_rnd3(struct psys_rnd3 *r); 5.15