Skip to content

Commit

Permalink
hide landing pad when too far away
Browse files Browse the repository at this point in the history
  • Loading branch information
BarthPaleologue committed Sep 15, 2024
1 parent ba6bda7 commit 5370389
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/ts/assets/procedural/landingPad/landingPad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ export class LandingPad implements Transformable, TypedObject, BoundingSphere {

this.deckMaterial = new LandingPadMaterial(padNumber, scene);

this.deck = MeshBuilder.CreateBox(`Landing Pad ${padNumber}`, { width: width, depth: depth, height: 0.5 }, scene);
this.deck = MeshBuilder.CreateBox(
`Landing Pad ${padNumber}`,
{
width: width,
depth: depth,
height: 0.5
},
scene
);
this.deck.material = this.deckMaterial;

this.deckAggregate = new PhysicsAggregate(this.deck, PhysicsShapeType.BOX, { mass: 0, friction: 10 }, scene);
Expand Down Expand Up @@ -83,8 +91,13 @@ export class LandingPad implements Transformable, TypedObject, BoundingSphere {
}
}

update(stellarObjects: Transformable[]): void {
update(stellarObjects: Transformable[], cameraWorldPosition: Vector3): void {
this.deckMaterial.update(stellarObjects);

const padCameraDistance2 = Vector3.DistanceSquared(cameraWorldPosition, this.deck.getAbsolutePosition());
const distanceThreshold = 12e3;
const isEnabled = padCameraDistance2 < distanceThreshold * distanceThreshold;
this.getTransform().setEnabled(isEnabled);
}

getTransform(): TransformNode {
Expand Down
2 changes: 1 addition & 1 deletion src/ts/assets/procedural/spaceStation/landingBay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class LandingBay {
this.getTransform().rotate(Axis.Y, deltaSeconds / computeRingRotationPeriod(this.radius, Settings.G_EARTH * 0.1));
this.landingBayMaterial.update(stellarObjects);
this.metalSectionMaterial.update(stellarObjects);
this.landingPads.forEach((landingPad) => landingPad.update(stellarObjects));
this.landingPads.forEach((landingPad) => landingPad.update(stellarObjects, cameraWorldPosition));

const distanceToCamera = Vector3.Distance(cameraWorldPosition, this.getTransform().getAbsolutePosition());

Expand Down

0 comments on commit 5370389

Please sign in to comment.