Split overworldscene.js's player/plane/camera into their own classes
Extracts Player (extends Entity), TestPlane, and PlayerCamera into their own files; the camera now tracks the player's live position at a fixed offset instead of orbiting the world origin over time. Updates test_overworldscene.c to match the new entity order and to build an in-memory zip fixture, since overworldscene.js now require()s these sibling files and require() always resolves through ASSET.zip.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
var CAMERA_OFFSET_ANGLE = 0.0;
|
||||
var CAMERA_OFFSET_RADIUS = 18.0;
|
||||
var CAMERA_OFFSET_HEIGHT = 10.0;
|
||||
|
||||
class PlayerCamera {
|
||||
constructor(target) {
|
||||
this.target = target;
|
||||
|
||||
this.entity = new Entity();
|
||||
this.position = this.entity.add(POSITION);
|
||||
this.entity.add(CAMERA);
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
update() {
|
||||
var targetPosition = this.target.position.getLocalPosition();
|
||||
|
||||
var eyeX = targetPosition.x + Math.cos(CAMERA_OFFSET_ANGLE) *
|
||||
CAMERA_OFFSET_RADIUS;
|
||||
var eyeY = targetPosition.y + CAMERA_OFFSET_HEIGHT;
|
||||
var eyeZ = targetPosition.z + Math.sin(CAMERA_OFFSET_ANGLE) *
|
||||
CAMERA_OFFSET_RADIUS;
|
||||
|
||||
this.position.lookAt(
|
||||
eyeX, eyeY, eyeZ,
|
||||
targetPosition.x, targetPosition.y, targetPosition.z,
|
||||
0.0, 1.0, 0.0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PlayerCamera;
|
||||
Reference in New Issue
Block a user