babylon.collisionPlane.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.CollisionPlane = function (origin, normal) {
  4. this.normal = normal;
  5. this.origin = origin;
  6. normal.normalize();
  7. this.equation = [];
  8. this.equation[0] = normal.x;
  9. this.equation[1] = normal.y;
  10. this.equation[2] = normal.z;
  11. this.equation[3] = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);
  12. };
  13. // Methods
  14. BABYLON.CollisionPlane.prototype.isFrontFacingTo = function (direction, epsilon) {
  15. var dot = BABYLON.Vector3.Dot(this.normal, direction);
  16. return (dot <= epsilon);
  17. };
  18. BABYLON.CollisionPlane.prototype.signedDistanceTo = function (point) {
  19. return BABYLON.Vector3.Dot(point, this.normal) + this.equation[3];
  20. };
  21. // Statics
  22. BABYLON.CollisionPlane.CreateFromPoints = function (p1, p2, p3) {
  23. var normal = BABYLON.Vector3.Cross(p2.subtract(p1), p3.subtract(p1));
  24. return new BABYLON.CollisionPlane(p1, normal);
  25. };
  26. })();