daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. intersect(ray : THREE.Ray) : intersectionResult
  2.     {
  3.         let intersectedBuilding : codeMapBuilding | null = null;
  4.         let leastIntersectedDistance : number = Infinity;
  5.  
  6.         let boxTranslation = new THREE.Vector3(-this.mapSize * this.scales.x * 0.5, 0.0, -this.mapSize * this.scales.z * 0.5);
  7.  
  8.         for (let building of this.buildings)
  9.         {
  10.             let box : THREE.Box3 = building.boundingBox.clone();
  11.  
  12.             box.min.x *= this.scales.x;
  13.             box.min.y *= this.scales.y;
  14.             box.min.z *= this.scales.z;
  15.  
  16.             box.max.x *= this.scales.x;
  17.             box.max.y *= this.scales.y;
  18.             box.max.z *= this.scales.z;
  19.  
  20.             box.translate(boxTranslation);
  21.  
  22.             let intersectionPoint : THREE.Vector3 = ray.intersectBox(box);
  23.  
  24.             if (intersectionPoint)
  25.             {
  26.                 let intersectionDistance : number = intersectionPoint.distanceTo(ray.origin);
  27.  
  28.                 if (intersectionDistance < leastIntersectedDistance)
  29.                 {
  30.                     leastIntersectedDistance = intersectionDistance;
  31.                     intersectedBuilding = building;
  32.                 }
  33.             }
  34.         }
  35.  
  36.         if (intersectedBuilding)
  37.         {
  38.             return {
  39.                 intersectionFound : true,
  40.                 building : intersectedBuilding
  41.             }
  42.         }
  43.         else
  44.         {
  45.             return {
  46.                 intersectionFound : false
  47.             }
  48.         }
  49.     }
RAW Paste Data
Top