libpsys

changeset 20:0a53b22f7caf tip

the billboarding was wrong ...
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 18 Sep 2012 09:38:48 +0300
parents fbccc3c0d43e
children
files src/psys.c src/psys.h src/psys_gl.c
diffstat 3 files changed, 40 insertions(+), 23 deletions(-) [+]
line diff
     1.1 --- a/src/psys.c	Mon Sep 17 08:21:39 2012 +0300
     1.2 +++ b/src/psys.c	Tue Sep 18 09:38:48 2012 +0300
     1.3 @@ -88,6 +88,21 @@
     1.4  	anm_set_pivot(&em->prs, pivot);
     1.5  }
     1.6  
     1.7 +vec3_t psys_get_pos(struct psys_emitter *em, float tm)
     1.8 +{
     1.9 +	return anm_get_node_position(&em->prs, ANM_SEC2TM(tm));
    1.10 +}
    1.11 +
    1.12 +quat_t psys_get_rot(struct psys_emitter *em, float tm)
    1.13 +{
    1.14 +	return anm_get_node_rotation(&em->prs, ANM_SEC2TM(tm));
    1.15 +}
    1.16 +
    1.17 +vec3_t psys_get_pivot(struct psys_emitter *em)
    1.18 +{
    1.19 +	return anm_get_pivot(&em->prs);
    1.20 +}
    1.21 +
    1.22  void psys_clear_collision_planes(struct psys_emitter *em)
    1.23  {
    1.24  	struct psys_plane *plane;
     2.1 --- a/src/psys.h	Mon Sep 17 08:21:39 2012 +0300
     2.2 +++ b/src/psys.h	Tue Sep 18 09:38:48 2012 +0300
     2.3 @@ -85,6 +85,10 @@
     2.4  void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm);
     2.5  void psys_set_pivot(struct psys_emitter *em, vec3_t pivot);
     2.6  
     2.7 +vec3_t psys_get_pos(struct psys_emitter *em, float tm);
     2.8 +quat_t psys_get_rot(struct psys_emitter *em, float tm);
     2.9 +vec3_t psys_get_pivot(struct psys_emitter *em);
    2.10 +
    2.11  void psys_clear_collision_planes(struct psys_emitter *em);
    2.12  int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast);
    2.13  
     3.1 --- a/src/psys_gl.c	Mon Sep 17 08:21:39 2012 +0300
     3.2 +++ b/src/psys_gl.c	Tue Sep 18 09:38:48 2012 +0300
     3.3 @@ -18,17 +18,6 @@
     3.4  
     3.5  void psys_gl_draw_start(struct psys_emitter *em, void *cls)
     3.6  {
     3.7 -	float xform[16];
     3.8 -
     3.9 -	glMatrixMode(GL_MODELVIEW);
    3.10 -	glPushMatrix();
    3.11 -
    3.12 -	glGetFloatv(GL_MODELVIEW_MATRIX, xform);
    3.13 -	xform[0] = xform[5] = xform[10] = 1.0;
    3.14 -	xform[1] = xform[2] = xform[4] = xform[6] = xform[8] = xform[9] = 0.0;
    3.15 -
    3.16 -	glLoadMatrixf(xform);
    3.17 -
    3.18  	glPushAttrib(GL_ENABLE_BIT);
    3.19  	glDisable(GL_LIGHTING);
    3.20  
    3.21 @@ -41,39 +30,48 @@
    3.22  	}
    3.23  
    3.24  	glDepthMask(0);
    3.25 -
    3.26 -	glBegin(GL_QUADS);
    3.27 -	glColor3f(1, 1, 1);
    3.28  }
    3.29  
    3.30  void psys_gl_draw(struct psys_emitter *em, struct psys_particle *p, void *cls)
    3.31  {
    3.32  	float hsz = p->size / 2.0;
    3.33  
    3.34 +	float xform[16];
    3.35 +
    3.36 +	glMatrixMode(GL_MODELVIEW);
    3.37 +	glPushMatrix();
    3.38 +
    3.39 +	glTranslatef(p->pos.x, p->pos.y, p->pos.z);
    3.40 +
    3.41 +	glGetFloatv(GL_MODELVIEW_MATRIX, xform);
    3.42 +	xform[0] = xform[5] = xform[10] = 1.0;
    3.43 +	xform[1] = xform[2] = xform[4] = xform[6] = xform[8] = xform[9] = 0.0;
    3.44 +	glLoadMatrixf(xform);
    3.45 +
    3.46 +	glBegin(GL_QUADS);
    3.47  	glColor4f(p->color.x, p->color.y, p->color.z, p->alpha);
    3.48  
    3.49  	glTexCoord2f(0, 0);
    3.50 -	glVertex3f(p->pos.x - hsz, p->pos.y - hsz, p->pos.z);
    3.51 +	glVertex2f(-hsz, -hsz);
    3.52  
    3.53  	glTexCoord2f(1, 0);
    3.54 -	glVertex3f(p->pos.x + hsz, p->pos.y - hsz, p->pos.z);
    3.55 +	glVertex2f(hsz, -hsz);
    3.56  
    3.57  	glTexCoord2f(1, 1);
    3.58 -	glVertex3f(p->pos.x + hsz, p->pos.y + hsz, p->pos.z);
    3.59 +	glVertex2f(hsz, hsz);
    3.60  
    3.61  	glTexCoord2f(0, 1);
    3.62 -	glVertex3f(p->pos.x - hsz, p->pos.y + hsz, p->pos.z);
    3.63 +	glVertex2f(-hsz, hsz);
    3.64 +	glEnd();
    3.65 +
    3.66 +	glMatrixMode(GL_MODELVIEW);
    3.67 +	glPopMatrix();
    3.68  }
    3.69  
    3.70  void psys_gl_draw_end(struct psys_emitter *em, void *cls)
    3.71  {
    3.72 -	glEnd();
    3.73 -
    3.74  	glDepthMask(1);
    3.75  	glPopAttrib();
    3.76 -
    3.77 -	glMatrixMode(GL_MODELVIEW);
    3.78 -	glPopMatrix();
    3.79  }
    3.80  
    3.81