-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2d1377
commit 5b7a0c1
Showing
11 changed files
with
47 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import { Vector3 } from "@babylonjs/core/Maths/math"; | ||
import { BaseObject } from "../view/common"; | ||
import { Settings } from "../settings"; | ||
import { BoundingSphere, ITransformable } from "../view/common"; | ||
import { Camera } from "@babylonjs/core/Cameras/camera"; | ||
|
||
/** | ||
* Computes the angular size in radians of an object viewed by a camera | ||
* @param objectPosition | ||
* @param objectRadius | ||
* @param cameraPosition The position of the observer camera | ||
* @see https://en.wikipedia.org/wiki/Angular_diameter | ||
*/ | ||
export function getAngularSize(objectPosition: Vector3, objectRadius: number, cameraPosition: Vector3) { | ||
const distance = Vector3.Distance(cameraPosition, objectPosition); | ||
return 2 * Math.atan(objectRadius / distance); | ||
} | ||
|
||
/** | ||
* Checks if the size of the object on the screen is bigger than the threshold | ||
* @param object The object to check | ||
* @param cameraPosition The position of the camera | ||
* @param camera The camera looking at the object | ||
* @param threshold The size threshold | ||
* @returns Whether the object is bigger than the threshold | ||
*/ | ||
export function isSizeOnScreenEnough(object: BaseObject, cameraPosition: Vector3, threshold = 0.002) { | ||
const distance = Vector3.Distance(cameraPosition, object.transform.getAbsolutePosition()); | ||
const angularSize = (object.getBoundingRadius() * 2) / distance; | ||
export function isSizeOnScreenEnough(object: BoundingSphere & ITransformable, camera: Camera, threshold = 0.002) { | ||
const angularSize = getAngularSize(object.transform.getAbsolutePosition(), object.getBoundingRadius(), camera.globalPosition); | ||
|
||
return angularSize / Settings.FOV > threshold; | ||
return angularSize / camera.fov > threshold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Vector3 } from "@babylonjs/core/Maths/math"; | ||
import { Camera } from "@babylonjs/core/Cameras/camera"; | ||
|
||
export interface Cullable { | ||
computeCulling(cameraPosition: Vector3): void; | ||
computeCulling(camera: Camera): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters