/TheElements/jni/points.c

http://thelements.googlecode.com/ · C · 101 lines · 73 code · 16 blank · 12 comment · 9 complexity · 9962ee515ebc79e6288f4a127565a42c MD5 · raw file

  1. /*
  2. * points.c
  3. * ----------------------------
  4. * Defines functions for manipulating data
  5. * for individual points, such as adding and
  6. * deleting points.
  7. */
  8. #include "points.h"
  9. void CreatePoint(int k, int l, int e)
  10. {
  11. int i;
  12. if (loq > 0)
  13. {
  14. loq--;
  15. i = avail[loq];
  16. avail[loq] = -1;
  17. x[i] = k;
  18. y[i] = l;
  19. allcoords[k][l] = i;
  20. // Set the element of the point
  21. element[i] = e;
  22. //velocity setting part - all start at 0
  23. xvel[i] = 0;
  24. yvel[i] = 0;
  25. frozen[i] = 0;
  26. setBitmapColor(k, l, e);
  27. set[i] = 1;
  28. unFreezeParticles(k, l);
  29. }
  30. }
  31. void DeletePoint(int partnum)
  32. {
  33. int tempx = x[partnum];
  34. int tempy = y[partnum];
  35. unFreezeParticles(tempx, tempy);
  36. setBitmapColor((int) x[partnum], (int) y[partnum], 3);
  37. allcoords[(int) x[partnum]][(int) y[partnum]] = -1;
  38. //cleaning up
  39. x[partnum] = 0;
  40. y[partnum] = 0;
  41. frozen[partnum] = 0;
  42. element[partnum] = 0;
  43. xvel[partnum] = 0;
  44. yvel[partnum] = 0;
  45. set[partnum] = 0;
  46. avail[loq] = partnum;
  47. loq++;
  48. }
  49. void setElement(int particle, int newelement)
  50. {
  51. element[particle] = newelement;
  52. setBitmapColor(x[particle], y[particle], newelement);
  53. }
  54. void setBitmapColor(int xpos, int ypos, int newelement)
  55. {
  56. colors[3 * (xpos + ypos * 512)] = red[newelement];
  57. colors[3 * (xpos + ypos * 512) + 1] = green[newelement];
  58. colors[3 * (xpos + ypos * 512) + 2] = blue[newelement];
  59. }
  60. void createBitmapFromPoints(void)
  61. {
  62. //Not implemented yet
  63. }
  64. //this function unfreezes particles around a point
  65. void unFreezeParticles(int xcentre, int ycentre)
  66. {
  67. int ix;
  68. int jy;
  69. for (ix = -1; ix <= 1; ix++)
  70. {
  71. for (jy = -1; jy <= 1; jy++)
  72. {
  73. int tempx = xcentre + ix;
  74. int tempy = ycentre + jy;
  75. if (tempx < maxx && tempx > 0 && tempy < maxy && tempy > 0)
  76. {
  77. int atemp = allcoords[tempx][tempy];
  78. if (atemp != -1)
  79. {
  80. frozen[atemp] = 0; //reset the freeze counter
  81. }
  82. }
  83. }
  84. }
  85. }