Skip to content

Instantly share code, notes, and snippets.

@eyston
Created December 7, 2010 04:50
Show Gist options
  • Save eyston/731468 to your computer and use it in GitHub Desktop.
Save eyston/731468 to your computer and use it in GitHub Desktop.
struct foo {
float *stuff;
int offset;
float operator[](size_t i) const
{
return stuff[i + offset];
}
float &operator[](size_t i)
{
return stuff[i + offset];
}
};
struct Particles
{
float *pos;
foo x, y, z;
Particles(int num)
{
pos = new float[num * 3];
x.stuff = y.stuff = z.stuff = pos;
x.offset = 0;
y.offset = num;
z.offset = num * 2;
for(int i = 0; i < num * 3; i++)
{
pos[i] = (float)i;
}
}
~Particles()
{
delete[] pos;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment