お世話になっております。
パーティクルをランダム生成しているのですが、このパーティクルが生成される位置をもっと左右に広げたいとおもっておりますが、どのようにするのが的確でしょうか?
画像ですと、四角で囲った部分からパーティクルが生成されますが、◯の位置からも生成したいです。
![イメージ説明]WIDTH:363
何卒よろしくお願いいたします。
lang
1public class ParticleSystem { 2 private Particle[] mParticles; 3 //パーティクルの数 4 private int PARTICLECOUNT = 15; 5 6 // for use to draw the particle 7 private FloatBuffer mVertexBuffer; 8 private ShortBuffer mIndexBuffer; 9 10 public ParticleSystem() { 11 mParticles = new Particle[PARTICLECOUNT]; 12 13 // setup the random number generator 14 Random gen = new Random(System.currentTimeMillis()); 15 // loop through all the particles and create new instances of each one 16 for (int i=0; i < PARTICLECOUNT; i++) { 17 mParticles[i] = new Particle(gen.nextFloat(), gen.nextFloat(), gen.nextFloat()); 18 } 19 20 //三角形のサイズを決定 21 // a simple triangle, kinda like this ^ 22 float[] coords = { 23 -0.4f,0.0f,0.0f, //左 24 0.4f,0.0f,0.0f, //右 25 0.0f,0.0f,0.4f}; //上 26 short[] icoords = {0,1,2}; 27 28 mVertexBuffer = makeFloatBuffer(coords); 29 mIndexBuffer = makeShortBuffer(icoords); 30 } 31 32 // used to make native order float buffers 33 private FloatBuffer makeFloatBuffer(float[] arr) { 34 ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4); 35 bb.order(ByteOrder.nativeOrder()); 36 FloatBuffer fb = bb.asFloatBuffer(); 37 fb.put(arr); 38 fb.position(0); 39 return fb; 40 } 41 42 // used to make native order short buffers 43 private ShortBuffer makeShortBuffer(short[] arr) { 44 ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4); 45 bb.order(ByteOrder.nativeOrder()); 46 ShortBuffer ib = bb.asShortBuffer(); 47 ib.put(arr); 48 ib.position(0); 49 return ib; 50 } 51 52 public void draw(GL10 gl) { 53 //頂点配列を定義。3は3次元。 54 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); 55 //パーティクルの色の指定。背景ではない。 56 gl.glColor4f(1f, 1f, 1f, 1f); 57 for (int i = 0; i < PARTICLECOUNT; i++) { 58 gl.glPushMatrix(); 59 gl.glTranslatef(mParticles[i].x, mParticles[i].y, mParticles[i].z); 60 //GL_TRIANGLES3角形と指定してる。?? 61 gl.glDrawElements(GL10.GL_TRIANGLES, 3, GL10.GL_UNSIGNED_SHORT, mIndexBuffer); 62 gl.glPopMatrix(); 63 } 64 } 65 66 // simply have the particles fall at a hard coded gravity rate 67 // and when they hit zero, bump them back up to a z of 1.0f 68 public void update() { 69 for (int i = 0; i < PARTICLECOUNT; i++) { 70 mParticles[i].z = mParticles[i].z - 0.01f; //落下速度 71 if (mParticles[i].z < -6.0f) { //落下位置。下位 72 mParticles[i].z = 1.5f; //落下の最初の位置 73 } 74 } 75 } 76}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。