API Docs for: 0.6.1
Show:

File: src/collision/RaycastResult.js

  1. var Vec3 = require('../math/Vec3');
  2.  
  3. module.exports = RaycastResult;
  4.  
  5. /**
  6. * Storage for Ray casting data.
  7. * @class RaycastResult
  8. * @constructor
  9. */
  10. function RaycastResult(){
  11.  
  12. /**
  13. * @property {Vec3} rayFromWorld
  14. */
  15. this.rayFromWorld = new Vec3();
  16.  
  17. /**
  18. * @property {Vec3} rayToWorld
  19. */
  20. this.rayToWorld = new Vec3();
  21.  
  22. /**
  23. * @property {Vec3} hitNormalWorld
  24. */
  25. this.hitNormalWorld = new Vec3();
  26.  
  27. /**
  28. * @property {Vec3} hitPointWorld
  29. */
  30. this.hitPointWorld = new Vec3();
  31.  
  32. /**
  33. * @property {boolean} hasHit
  34. */
  35. this.hasHit = false;
  36.  
  37. /**
  38. * The hit shape, or null.
  39. * @property {Shape} shape
  40. */
  41. this.shape = null;
  42.  
  43. /**
  44. * The hit body, or null.
  45. * @property {Body} body
  46. */
  47. this.body = null;
  48.  
  49. /**
  50. * The index of the hit triangle, if the hit shape was a trimesh.
  51. * @property {number} hitFaceIndex
  52. * @default -1
  53. */
  54. this.hitFaceIndex = -1;
  55.  
  56. /**
  57. * Distance to the hit. Will be set to -1 if there was no hit.
  58. * @property {number} distance
  59. * @default -1
  60. */
  61. this.distance = -1;
  62.  
  63. /**
  64. * If the ray should stop traversing the bodies.
  65. * @private
  66. * @property {Boolean} _shouldStop
  67. * @default false
  68. */
  69. this._shouldStop = false;
  70. }
  71.  
  72. /**
  73. * Reset all result data.
  74. * @method reset
  75. */
  76. RaycastResult.prototype.reset = function () {
  77. this.rayFromWorld.setZero();
  78. this.rayToWorld.setZero();
  79. this.hitNormalWorld.setZero();
  80. this.hitPointWorld.setZero();
  81. this.hasHit = false;
  82. this.shape = null;
  83. this.body = null;
  84. this.hitFaceIndex = -1;
  85. this.distance = -1;
  86. this._shouldStop = false;
  87. };
  88.  
  89. /**
  90. * @method abort
  91. */
  92. RaycastResult.prototype.abort = function(){
  93. this._shouldStop = true;
  94. };
  95.  
  96. /**
  97. * @method set
  98. * @param {Vec3} rayFromWorld
  99. * @param {Vec3} rayToWorld
  100. * @param {Vec3} hitNormalWorld
  101. * @param {Vec3} hitPointWorld
  102. * @param {Shape} shape
  103. * @param {Body} body
  104. * @param {number} distance
  105. */
  106. RaycastResult.prototype.set = function(
  107. rayFromWorld,
  108. rayToWorld,
  109. hitNormalWorld,
  110. hitPointWorld,
  111. shape,
  112. body,
  113. distance
  114. ){
  115. this.rayFromWorld.copy(rayFromWorld);
  116. this.rayToWorld.copy(rayToWorld);
  117. this.hitNormalWorld.copy(hitNormalWorld);
  118. this.hitPointWorld.copy(hitPointWorld);
  119. this.shape = shape;
  120. this.body = body;
  121. this.distance = distance;
  122. };