# Pixelflow lib / getting individual particle positions

**URL:** <https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778>\
**Category:** Libraries\
**Created:** [April 30, 2019, 6:13am UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778 "2019-04-30T06:13:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iliasp](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@iliasp](https://discourse.processing.org/u/iliasp)\
**Post date:** [April 30, 2019, 6:13am UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778/1 "2019-04-30T06:13:39Z")

</div>

Hello,

I am trying to find a way to get the individual particle positions in a pixelflow particle sim.  
Is this even possible considering the texture based physics calcs?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 1, 2019, 9:58pm UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778/2 "2019-05-01T21:58:09Z")

</div>

Pixelflow is a pretty big library. Can you be more concrete about how you are using it, with what kind of example, and what your particles do?

For example, if you are using DwParticle2D, it has `x()` and `y()` methods to retrieve its current position.

> <https://github.com/diwi/PixelFlow/blob/master/src/com/thomasdiewald/pixelflow/java/softbodydynamics/particle/DwParticle2D.java#L195-L203>

---

<div class="post-metadata">

**Author:** ![iliasp](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@iliasp](https://discourse.processing.org/u/iliasp)\
**Post date:** [May 2, 2019, 5:33am UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778/3 "2019-05-02T05:33:27Z")

</div>

Im using DwFlowFieldParticles to sim a large number of grain-like particles.  
Pretty simple movements, collisions obstacles etc.  
I need a way to grab an “instance” of the positions , not on every frame.  
Like pause the sim, store x,y for each particle in an array, continue.

I searched in the javadocs but couldnt find any methods or fields.  
Even looked at decoding some texture into positions but my knowledge of gpu computing  
is kinda limited.

Perhaps I should look into implementing the sim using DwParticle2D?  
I dont really need the existence of flowfield atm but it can be useful in future iterations of the app.

---

<div class="post-metadata">

**Author:** ![iliasp](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@iliasp](https://discourse.processing.org/u/iliasp)\
**Post date:** [August 5, 2019, 2:19pm UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778/4 "2019-08-05T14:19:17Z")

</div>

To make the problem more specific, in the example scene of the Pixelflow library  
FlowFieldParticles\_Basic is there any way to get individual particle positions?  
What im trying to do is be able to save the locations on an array when i hit a button.

With my limited understanding I think the positions are encoded in the  
particles.tex\_particle.src DwGLTexture but i cant find a way to decode them.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 5, 2019, 3:54pm UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778/5 "2019-08-05T15:54:33Z")

</div>

I’m not familiar with it, but possibly relevant:

1. source code in question: [https://github.com/diwi/PixelFlow/blob/master/src/com/thomasdiewald/pixelflow/java/dwgl/DwGLTexture.java](https://github.com/diwi/PixelFlow/blob/master/src/com/thomasdiewald/pixelflow/java/dwgl/DwGLTexture.java)
2. past issue on copying data out of DwGLTexture: [https://github.com/diwi/PixelFlow/issues/11](https://github.com/diwi/PixelFlow/issues/11)

At a certain point if you are stuck you might consider posting an issue asking if it is possible.

---

<div class="post-metadata">

**Author:** ![iliasp](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@iliasp](https://discourse.processing.org/u/iliasp)\
**Post date:** [August 6, 2019, 7:15am UTC](https://discourse.processing.org/t/pixelflow-lib-getting-individual-particle-positions/10778/6 "2019-08-06T07:15:06Z")

</div>

Actually the links you provided helped!  
Ive seen the getFloatTextureData in the reference but I expected it to throw color values.  
For anyone in the future that needs it here is a crude solution:

```auto
DwGLTexture tex_pos_copy;
float[] data_pos;

void foo() {
  if (tex_pos_copy == null) {
    tex_pos_copy = particles.tex_particle.src.createEmtpyCopy();
  }

  DwFilter.get(context).copy.apply(particles.tex_particle.src, tex_pos_copy);

  context.begin();
  data_pos = tex_pos_copy.getFloatTextureData(data_pos);
  context.end();

  for (int i=0; i<particles.getCount()*4; i+=2) {
    float xpos = data_pos[i]*width;
    float ypos = data_pos[i+1]*height * (-1.0) + height;
  }
}

```

thank you very much Jeremy!
