Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- intersect(ray : THREE.Ray) : intersectionResult
- {
- let intersectedBuilding : codeMapBuilding | null = null;
- let leastIntersectedDistance : number = Infinity;
- let boxTranslation = new THREE.Vector3(-this.mapSize * this.scales.x * 0.5, 0.0, -this.mapSize * this.scales.z * 0.5);
- for (let building of this.buildings)
- {
- let box : THREE.Box3 = building.boundingBox.clone();
- box.min.x *= this.scales.x;
- box.min.y *= this.scales.y;
- box.min.z *= this.scales.z;
- box.max.x *= this.scales.x;
- box.max.y *= this.scales.y;
- box.max.z *= this.scales.z;
- box.translate(boxTranslation);
- let intersectionPoint : THREE.Vector3 = ray.intersectBox(box);
- if (intersectionPoint)
- {
- let intersectionDistance : number = intersectionPoint.distanceTo(ray.origin);
- if (intersectionDistance < leastIntersectedDistance)
- {
- leastIntersectedDistance = intersectionDistance;
- intersectedBuilding = building;
- }
- }
- }
- if (intersectedBuilding)
- {
- return {
- intersectionFound : true,
- building : intersectedBuilding
- }
- }
- else
- {
- return {
- intersectionFound : false
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement