|
|
发表于 2007-10-15 14:50:00
|
显示全部楼层
Re:火焰的燃烧过程有那些特征啊?
我自已的代码如下.(用jogl写的!)
public class Particle {
private Vector3f pos;
private Vector3f velocity;
private float[] color = { 1.0f, 0.5f, 0.3f, 1.0f };
private float size = 0.75f;
private float angle = 30;
private float delt = 0.08f;
private float life;
public Particle(){
pos = new Vector3f (0f, 0f, 0f);
velocity = new Vector3f(rand(-0.5f, 0.5f), rand(0.5f, 2.0f), 0f);
life = rand(1f, 1.5f);
}
public void calculate () {
pos.x += velocity.x*delt;
pos.y += velocity.y*delt;
pos.y -= 0.98f*delt;
angle += angle*delt;
life -= delt;
if ( life < 0 ) {
pos.x = pos.y = pos.z = 0f;
life = rand (1f, 1.5f);
velocity = new Vector3f(rand(-0.5f, 0.5f), rand(0.5f, 2.0f), 0f);
angle = 30;
}
}
public void renderParticle (GL gl, Texture tex) {
if ( life < 0 )
return;
gl.glDepthMask(false);
tex.bind();
TextureCoords tc = tex.getImageTexCoords();
gl.glPushMatrix();
gl.glTranslatef(pos.x, pos.y, pos.z);
gl.glPushMatrix();
gl.glRotatef(angle/2.0f, 0f, 1f, 0f);
float halfsize = size*0.5f;
gl.glColor4fv(color, 0);
gl.glBegin( GL.GL_QUADS );
gl.glTexCoord2f( tc.left(), tc.bottom() );
gl.glVertex3f(-halfsize, -halfsize, 0f);
gl.glTexCoord2f( tc.right(), tc.bottom() );
gl.glVertex3f(halfsize, -halfsize, 0f);
gl.glTexCoord2f( tc.right(), tc.top() );
gl.glVertex3f(halfsize, halfsize, 0f);
gl.glTexCoord2f( tc.left(), tc.top() );
gl.glVertex3f(-halfsize, halfsize, 0f);
gl.glEnd();
gl.glPopMatrix();
gl.glPopMatrix();
gl.glDepthMask(true);
}
private float rand(float min, float max) {
return (float)(min + (max - min)*Math.random());
}
public class Vector3f {
float x;
float y;
float z;
public Vector3f(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}
关键是参数要选得合适,请指教! |
|