ThreeDee

ThreeDee Module

The ThreeDee Module draws simple flat shapes with perspective, for retro pseudo-3D effects like roads and hallways.

Objects are added to a ThreeDeeScene, which has a Camera, and the scene is drawn with MDog.Draw.threeDeeScene(). Objects are drawn in the order they were added, so add the farthest objects first. Objects can be taken back out with removeObject().

The camera looks forward along z, so objects need a larger z than the camera to be seen. Like the rest of the screen, y goes down. The center of the view is in the middle of the screen horizontally, and a quarter of the way down vertically.

const scene = new MDog.ThreeDee.ThreeDeeScene(new MDog.ThreeDee.Camera(0, 0, 0, 100));
scene.addObject(new MDog.ThreeDee.ThreeDeeFloor(10, 5, 40, "#336633"));
scene.addObject(new MDog.ThreeDee.ThreeDeeRectangle(20, -5, -5, 5, 5, "#aa3333"));

function main() {
    MDog.Draw.clear();
    MDog.Draw.threeDeeScene(scene);
}

The ThreeDee Module's classes can be accessed with new MDog.ThreeDee.ClassName().

ThreeDeeScene

Camera

The camera can be moved by changing its position, which is a Vector3, like camera.position.z += 1.

Objects

Every object has a getScene() method, which gets the scene it was added to.