Guest User

Untitled

a guest
Jul 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. struct foo {
  2. float *stuff;
  3. int offset;
  4.  
  5. float operator[](size_t i) const
  6. {
  7. return stuff[i + offset];
  8. }
  9.  
  10. float &operator[](size_t i)
  11. {
  12. return stuff[i + offset];
  13. }
  14. };
  15.  
  16. struct Particles
  17. {
  18. float *pos;
  19.  
  20. foo x, y, z;
  21.  
  22. Particles(int num)
  23. {
  24. pos = new float[num * 3];
  25. x.stuff = y.stuff = z.stuff = pos;
  26. x.offset = 0;
  27. y.offset = num;
  28. z.offset = num * 2;
  29.  
  30. for(int i = 0; i < num * 3; i++)
  31. {
  32. pos[i] = (float)i;
  33. }
  34. }
  35.  
  36. ~Particles()
  37. {
  38. delete[] pos;
  39. }
  40.  
  41. };
Add Comment
Please, Sign In to add comment