API Docs for: 0.6.1
Show:

File: src/collision/ObjectCollisionMatrix.js

  1. module.exports = ObjectCollisionMatrix;
  2.  
  3. /**
  4. * Records what objects are colliding with each other
  5. * @class ObjectCollisionMatrix
  6. * @constructor
  7. */
  8. function ObjectCollisionMatrix() {
  9.  
  10. /**
  11. * The matrix storage
  12. * @property matrix
  13. * @type {Object}
  14. */
  15. this.matrix = {};
  16. }
  17.  
  18. /**
  19. * @method get
  20. * @param {Number} i
  21. * @param {Number} j
  22. * @return {Number}
  23. */
  24. ObjectCollisionMatrix.prototype.get = function(i, j) {
  25. i = i.id;
  26. j = j.id;
  27. if (j > i) {
  28. var temp = j;
  29. j = i;
  30. i = temp;
  31. }
  32. return i+'-'+j in this.matrix;
  33. };
  34.  
  35. /**
  36. * @method set
  37. * @param {Number} i
  38. * @param {Number} j
  39. * @param {Number} value
  40. */
  41. ObjectCollisionMatrix.prototype.set = function(i, j, value) {
  42. i = i.id;
  43. j = j.id;
  44. if (j > i) {
  45. var temp = j;
  46. j = i;
  47. i = temp;
  48. }
  49. if (value) {
  50. this.matrix[i+'-'+j] = true;
  51. }
  52. else {
  53. delete this.matrix[i+'-'+j];
  54. }
  55. };
  56.  
  57. /**
  58. * Empty the matrix
  59. * @method reset
  60. */
  61. ObjectCollisionMatrix.prototype.reset = function() {
  62. this.matrix = {};
  63. };
  64.  
  65. /**
  66. * Set max number of objects
  67. * @method setNumObjects
  68. * @param {Number} n
  69. */
  70. ObjectCollisionMatrix.prototype.setNumObjects = function(n) {
  71. };
  72.