Camera
Back to the reference

Camera

The 3D camera and the 2D one, picking through them, and aiming one.

27 symbols

cameraLookAtfunctionnacatamalon

cameraLookAt(camera: TCamera3d, target: { x, y, z }) => TCamera3d

Turns a camera to look at a point, from wherever it is standing.

It writes the camera's rotationY (left and right) and rotationX (up and down), and leaves its roll alone. Call it in useUpdate to keep a moving thing in the middle of the view. A camera turned by a quaternion is switched back to angles, since a quaternion would be read instead of them and the camera would not move.

Straight up or straight down has no left or right to speak of, so there the camera keeps the rotationY it had.

Parameters

cameraTCamera3d

The camera to turn.

target{ x, y, z }

Where to look: anything with x, y and z, such as another object's placement.

Example

declare const player: TTransform3d;

const camera = useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 3, z: 6 } });
useUpdate(() => cameraLookAt(camera, player));
View source · camera/camera_look_at.ts:30

castRayfunctionnacatamalon

castRay(ray: TRay, where: TBox | typeOperator, options: TCastRayOptions) => TRayHit[]

What a ray meets among the models of a scene, nearest first: what is under the pointer, with no physics. A ray from screenToRay and the scene (sceneOf(self)) answer "what was clicked"; a ray down from a piece, "what is it standing on".

It looks at the models inside where (a box, or several), the boxes themselves and everything in them, as they are drawn: what is hidden is not met, nor what is pinned to the screen, nor the side of a triangle its material throws away (cull, the back unless it says otherwise), so what is met is what is seen. Each instance of createMeshInstances is met where it is, and says which one.

Met as its shape is built and placed, which is how most models are drawn. Not so for a model that bends around its bones, met by its corners as its file gives them, before the bones move them; one whose material moves its corners in its shader (a flag, grass in the wind, vertexSnap), met where they were; and under a camera that follows a 2D world (follow2d), which draws every model stood upright, met by its placement as it is, not as it is drawn. What is inside a picture drawn in the game is not met from the scene: look in the picture's own box for that. A game with physics casts its rays there instead (usePhysicsWorld3d().raycast), against its colliders and their layers.

Each model is tried against the box it fits in before any of its triangles, so a scene of ordinary size is quick enough to ask every time the pointer moves.

Parameters

rayTRay

Where it starts and which way it goes: from screenToRay, or made by hand.

whereTBox | typeOperator

What to look in: the scene, sceneOf(self), or the objects that can be met.

optionsTCastRayOptions

How far it reaches.

Example

declare const Chip: (props: { x: number; y: number; z: number }) => void;

const Table = () => {
    const camera = useCamera3d({ projection: 'perspective', transform: { y: 4, z: 6, rotationX: -0.6 } });
    const game = useGame();
    const scene = useSelf();
    createMesh({ geometry: useCubeGeometry({ width: 6, height: 0.2, depth: 4 }), tint: '#1d6b3a' });

    usePointer().onDown((info) => {
        const ray = screenToRay(camera, game.getWidth(), game.getHeight(), info.screenX, info.screenY);
        const hit = castRay(ray, scene)[0];
        if (hit !== undefined) {
            // A chip put down where the table was clicked.
            useSpawn(Chip)({ x: hit.point.x, y: hit.point.y, z: hit.point.z });
        }
    });

    return createScene();
};
View source · camera/cast_ray.ts:390

rayOnPlanefunctionnacatamalon

rayOnPlane(ray: TRay, plane: TPlane) => { point, distance } | null

Where a ray meets a flat plane, a floor or a table top that goes on for ever, and how far along it: the point of the floor under the pointer, with nothing built to be met. null when the ray runs alongside the plane or away from it.

Met from either side. Left out, the plane is the floor, y = 0; one at another height is { point: { x: 0, y: 0.8, z: 0 } }, and a wall { normal: { x: 0, y: 0, z: 1 } }. To know which model is under the pointer rather than where a plane is, castRay.

Parameters

rayTRay

Where it starts and which way it goes: from screenToRay, or made by hand.

planeTPlane

A point on the plane and the way it faces. Left out, the floor.

Example

const camera = useCamera3d({ projection: 'perspective', transform: { y: 6, z: 6, rotationX: -0.8 } });
const game = useGame();
declare const marker: TTransform3d;

usePointer().onMove((info) => {
    const ray = screenToRay(camera, game.getWidth(), game.getHeight(), info.screenX, info.screenY);
    // The table's top, 0.8 up.
    const at = rayOnPlane(ray, { point: { x: 0, y: 0.8, z: 0 } });
    if (at !== null) {
        marker.x = at.point.x;
        marker.z = at.point.z;
    }
});
View source · camera/ray_on_plane.ts:55

screenToRayfunctionnacatamalon

screenToRay(camera: TCamera3d | null, width: number, height: number, x: number, y: number) => TRay

The ray that goes into the world through a point of the screen: what is under the pointer.

It is worked out from the very view and projection the scene is drawn with, so the ray passes through exactly what is drawn at that pixel. Test it against what can be picked (a sphere around each object, a box, a plane) and the nearest hit is what was clicked; against the floor's plane, it gives the point of the floor under the pointer, which is what dragging something across it needs.

x and y are in the game's pixels, the pointer's screenX and screenY, and width and height are the game's size (useGame().getWidth(), getHeight()). With no camera it uses the view the scene falls back to when it has none.

Parameters

cameraTCamera3d | null

The scene's camera, or null.

widthnumber

The game's width, in pixels.

heightnumber

The game's height, in pixels.

xnumber

The point, from the left.

ynumber

The point, from the top.

Example

const camera = useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 3, z: 6 } });
const game = useGame();
declare const marker: TTransform3d;

const pointer = usePointer();
pointer.onDown((info) => {
    const ray = screenToRay(camera, game.getWidth(), game.getHeight(), info.screenX, info.screenY);
    // How far along the ray the floor (y = 0) is, and the point there.
    const t = -ray.origin.y / ray.direction.y;
    marker.x = ray.origin.x + ray.direction.x * t;
    marker.z = ray.origin.z + ray.direction.z * t;
});
View source · camera/screen_to_ray.ts:73

useCamera2dfunctionhooknacatamalon

useCamera2d(options?: TCamera2dOptions) => TCamera2d

Gives the scene a camera, so its world can be bigger than the screen and scroll, turn and zoom.

Without one, everything is drawn where its x and y say on the screen, which is what a menu or a single-screen game wants. With one, those same numbers become a place in a world, and the camera decides which part of that world is on screen.

You get the camera back and move it by changing its numbers, usually every frame:

  • transform.x/transform.y: the world point on the top-left corner of the screen. To keep something in the middle, subtract half the screen from its position.
  • transform.rotation: turns the view, in radians.
  • zoom: 2 shows everything twice as big, 0.5 half as big.

The camera belongs to the whole scene, so it does not matter which part of the scene asks for it. Asking twice replaces the first one. Inside a picture made by createSpriteTexture it belongs to that picture instead, and the scene keeps its own.

Something that must stay still on screen while the world moves, a score or a health bar, has two ways to do it: put it in its own scene started with useScene().launch(), or mark it with useScreenSpace().

Parameters

optionsoptionalTCamera2dOptions

Where the camera starts: x, y, rotation and zoom, all optional.

Example

export const Level: TSceneFn = () => {
    const camera = useCamera2d();
    const hero = createSprite({ key: 'hero', transform: { x: 900, y: 600 } });

    useUpdate(() => {
        // The screen is 480x320: half of it keeps the hero in the middle
        camera.transform.x = hero.transform.x - 240;
        camera.transform.y = hero.transform.y - 160;
    });

    return createScene();
};
View source · hooks/camera/use_camera_2d.ts:53

useCamera3dfunctionhooknacatamalon

useCamera3d(options: TCamera3dOptions) => TCamera3d

Gives the scene a camera to look at its models through, and returns it.

Without one, models are drawn straight in the game's pixels, flat on, exactly the way sprites are drawn without a 2D camera. With one, the scene is seen from wherever the camera is.

There are two ways of seeing and the choice is what the game looks like. 'orthographic', the default, has no vanishing point and measures in the same pixels a sprite does: a model one unit wide is one pixel wide, so a 3D piece can stand on a 2D board and pan and zoom with it. 'perspective' is the usual one, where things shrink with distance.

What comes back is the camera itself, so moving it is changing a number and it takes effect on the next frame drawn. A scene has one, as it has one 2D camera; asking again gives back the one it already has, and says so, rather than quietly replacing it. Inside a picture made by createSpriteTexture it belongs to that picture instead, and the scene keeps its own.

Parameters

optionsTCamera3dOptions

Where it starts, how it sees, and how far it can see.

Example

const Level = () => {
    const camera = useCamera3d({ projection: 'perspective', transform: { z: 6 } });

    useUpdate((delta) => {
        camera.transform.rotationY += delta * 0.5;
    });

    return createScene();
};
View source · hooks/camera/use_camera_3d.ts:44

useCameraFollowfunctionhooknacatamalon

useCameraFollow(target: TCameraTarget | null, options: TCameraFollowOptions) => TCameraFollow

Makes the scene's camera follow something, the way a platformer's does: a box in the middle the character moves inside freely (deadzone), never past the edges of the level (bounds), a little ahead of where it goes (lead), and a shake for when something hits hard.

It moves the camera once every useUpdate and every body's move is over, in useLateUpdate, so it reads where the character ended up and the two never shake against each other. It follows at once and on whole pixels by default, as the consoles did; smooth makes it glide. It works at any zoom; a camera turned with rotation is not one it can keep a level's edges out of.

With rooms the level is cut into rooms, as the action games of the consoles did: the camera stays in the target's room and scrolls across when the target walks into the next. The scroll is the bounds moving from one room to the other, so the dead zone and the rest keep working through it.

It uses the scene's camera from useCamera2d, or makes it. Everything it was told can be changed on what it returns, at any time: another target for a cutscene, other bounds for another room.

Parameters

targetTCameraTarget | null

What to follow: an object, a sprite it draws, or a point the game moves. null to start still.

Example

declare const Hero: () => void;

export const Level: TSceneFn = () => {
    const map = createTilemap({ src: '/maps/level.tilemap' });
    const hero = useSpawn(Hero)();
    const follow = useCameraFollow(hero, { deadzone: { width: 32, height: 48 }, bounds: map });
    const keys = useKeyboard();

    useUpdate(() => {
        if (keys.justPressed('x')) follow.shake(4, 0.3);
    });
    return createScene();
};

Example

declare const Hero: () => void;

// Screen by screen, 256 by 224 each, scrolling across in half a second.
export const Castle: TSceneFn = () => {
    const hero = useSpawn(Hero)();
    const follow = useCameraFollow(hero, { rooms: { width: 256, height: 224 }, scroll: 0.5 });

    useUpdate(() => {
        if (follow.scrolling) return; // the hero waits for the screen
    });
    return createScene();
};
View source · hooks/camera/use_camera_follow.ts:283

useFogfunctionhooknacatamalon

useFog(options: TFogOptions) => TFog

Puts the scene in fog: its models fade into color between near and far from the camera.

The fog belongs to the scene, like its camera, so one is enough and a second is ignored with a warning. It covers every model the scene draws, a material of your own included, and leaves the 2D alone. Set the game's background to the same colour and the far end of the world melts into it instead of stopping at a wall, which is the whole trick.

Parameters

optionsTFogOptions

What it fades into and over what distance.

Example

export const Level: TSceneFn = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 8 } });
    const fog = useFog({ color: '#1a1426', near: 6, far: 40 });

    useUpdate((delta, time) => {
        // Breathing: the fog comes in and goes out
        fog.far = 40 + Math.sin(time) * 10;
    });

    return createScene();
};
View source · hooks/fog/use_fog.ts:38

useParallaxfunctionhooknacatamalon

useParallax(factor: { x, y }) => void

Makes this object, and everything it draws and holds, move with the camera only so much: 1 as everything else, 0 not at all, as if pinned to the screen, and in between further away. A far range of mountains is { x: 0.3, y: 0 }: it slides slowly by and keeps its height.

Only how it is drawn and where the pointer touches it change; its placement stays what it says. Something it draws with a parallax of its own keeps that. It moves in whole pixels, as the layers of the old consoles did.

Parameters

factor{ x, y }

How much it moves with the camera, across and down.

Example

const Mountains = () => {
    useParallax({ x: 0.3, y: 0 });
    createSprite({ key: 'mountains', transform: { x: 240, y: 120 } });
};
View source · hooks/camera/use_parallax.ts:28

useScreenSpacefunctionhooknacatamalon

useScreenSpace(on: boolean) => void

Keeps what is created here fixed on the screen, even while the scene's camera moves.

It is how a health bar, a score or a pause button stays in its corner over a world that scrolls. It covers everything this part of the scene creates and everything created under it, however deep, so a whole HUD is marked once.

Positions inside it are screen pixels, measured from the top-left corner, whatever the camera is doing. Called in the body of a scene, the whole scene ignores its camera.

The other way to get the same thing is a separate scene for the HUD, started with useScene().launch(): a scene without a camera is always fixed to the screen, and it is drawn over the scene that launched it.

Parameters

onboolean

false undoes it. Default true.

Example

const Hud = () => {
    useScreenSpace();
    createSprite({ tint: '#4ade80', width: 120, height: 8, transform: { x: 70, y: 16 } });
};

export const Level: TSceneFn = () => {
    useCamera2d();
    useSpawn(Hud)();
    return createScene();
};
View source · hooks/camera/use_screen_space.ts:39

useWorldOffScreenfunctionhooknacatamalon

useWorldOffScreen(on: boolean) => void

Has the screen draw only what this scene pins to it (useScreenSpace): its world is seen through views of it alone (createSpriteTexture({ sees: 'world' })).

For a split screen, where two views cover the whole screen and the world drawn underneath them would never be seen and would cost a third time over. The scene runs as ever: everything in it moves, sounds and is seen by its views, its particles included. Only what the screen draws of it changes, and only while the game looks through its own cameras: a capture of the game is a picture of the screen, its views and its HUD, while the editor's edit mode, a camera's preview and a capture through another camera still show the world. A capture that names a camera, the scene's own included, is through another one; one that names none, or null, is the game's. It is the scene's, wherever in it it is called.

Parameters

onboolean

false undoes it, for a game that leaves a split screen. Default true.

Example

declare const Half: (player: TSprite) => void;
declare const Screens: (left: TTexture, right: TTexture) => void;

export const Level: TSceneFn = () => {
    useWorldOffScreen();
    const p1 = createSprite({ key: 'red' });
    const p2 = createSprite({ key: 'blue' });
    const left = createSpriteTexture({ width: 240, height: 270, sees: 'world' }, Half, p1);
    const right = createSpriteTexture({ width: 240, height: 270, sees: 'world' }, Half, p2);
    // The two halves, pinned to the screen in a part of their own.
    useSpawn(Screens)(left, right);
    return createScene();
};
View source · hooks/camera/use_world_off_screen.ts:42

worldToScreenfunctionnacatamalon

worldToScreen(camera: TCamera3d | null, width: number, height: number, point: { x, y, z }) => TScreenPoint

Where a point of the world is drawn on the screen: the other way round from screenToRay.

What puts a name over a character's head, a marker on something off in the distance, or a health bar that follows a model: a sprite placed at the answer sits exactly over the point, because the answer comes from the same view and projection the scene is drawn with.

Parameters

cameraTCamera3d | null

The scene's camera, or null.

widthnumber

The game's width, in pixels.

heightnumber

The game's height, in pixels.

point{ x, y, z }

The point in the world.

Example

```ts
const camera = useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 3, z: 6 } });
const game = useGame();
declare const enemy: TMesh;
declare const label: TText;

useUpdate(() => {
    const at = worldToScreen(camera, game.getWidth(), game.getHeight(), enemy.transform);
    label.visible = !at.behind;
    label.transform.x = at.x;
    label.transform.y = at.y - 20;
});
```

A camera that follows the 2D one (`follow2d`) puts a model where a sprite at the same place is:
ask the 2D camera instead.
View source · camera/world_to_screen.ts:58

TCamera2dtypenacatamalon

The camera a scene looks at its 2D world through. Plain data: the renderer reads it every frame, so changing a field is all it takes to move, turn or zoom the view.

transform.x/y is the world point that lands on the top-left corner of the screen, in pixels, not its centre: following something means subtracting half the screen. Rotation and zoom pivot on that same corner.

zoom magnifies: 2 shows everything twice as big, 0.5 half as big.

type exists for the compiler as much as for anyone reading the data: without it, any record with a transform and a zoom would fit here by shape.

Properties

type'camera-2d'
idstring
transform{ x, y, rotation }

Where the camera is and how it is turned. No scale: a camera does not stretch, and a field nothing reads is a field someone will set and wonder why nothing happened.

zoomnumber

Magnification. 1 is none, 2 twice as big.

cullingCameraoptionalTCamera2d | null

For finding out what a camera leaves out: another camera, which then decides what this one draws. A sprite, a text or a panel wholly outside what that one sees is skipped here, so a camera looking from further out shows the world as the other leaves it. That one is measured over the game's screen, which is where a scene's camera draws. null or absent, the usual: this camera's own.

View source · camera/types/t_camera_2d.ts:18

TCamera2dOptionstypenacatamalon

What a camera can start with. Everything is optional.

Properties

transformoptionalPartial<{ x, y, rotation }>

Where it is, as it is read afterwards (camera.transform): x and y are the world point on the top-left corner of the screen, in pixels, and rotation turns it, in radians. All 0 by default.

zoomoptionalnumber

Magnification. Default 1.

View source · camera/types/t_camera_2d.ts:55

TCamera3dtypenacatamalon

The camera a scene looks at its 3D world through. Plain data, like the 2D one: the renderer reads it every frame, so changing a field is all it takes to move, turn or zoom the view.

Two ways of seeing, and the choice is what the game is:

  • 'perspective' is the usual one: things get smaller with distance, and fov says how much is in view.
  • 'orthographic' has no vanishing point and measures in the same pixels a sprite does: a model one unit wide is one pixel wide. That is what lets a 3D piece stand on a 2D board and pan and zoom with it, which is how the consoles of the era mixed the two.

Y points up here, the opposite of the 2D camera, because every model is built that way and mirroring the axis would turn each one inside out. Unless it follows the 2D camera (follow2d): then the 3D pieces live in the 2D world, y down, among the sprites.

Properties

type'camera-3d'
idstring
projection'perspective' | 'orthographic'
transformTTransform3d

Where the camera is and how it is turned. No scale: a camera does not stretch.

fovnumber

How wide the view is, in degrees. Perspective only.

nearnumber

Nothing closer than this is drawn, and nothing further than far.

An orthographic camera reads only far, and sees that far behind it as well as in front, so whatever sits around its z is drawn, as a sprite would be.

farnumber
zoomnumber

Magnification. Orthographic only: 2 shows everything twice as big.

follow2doptionalboolean

Orthographic only: the 3D pieces are placed in the 2D world, as sprites are, and seen through the scene's 2D camera. A model at (x, y) is drawn where a sprite at (x, y) is, y going down; the 2D camera's pan, turn and zoom move both alike, and this camera's own x, y and zoom are not read (its z and far still are). For a 2D game with pieces drawn in 3D: a cell's membrane that wobbles, a coin that turns in depth. The models stay upright and lit as they were built: only where they are is measured the 2D way. Default false.

cullingCameraoptionalTCamera3d | null

For finding out what a camera leaves out: another camera, which then decides what this one draws. A model is skipped when it is wholly outside what the camera drawing it sees, and with this set it is skipped here when it is outside what that one sees, so a camera looking from above shows the world as the other leaves it. That one is measured as if it drew into what this one draws into. Both follow the 2D camera (follow2d) or neither does: one in the 2D world and one in a world of its own do not look at the same places, and that is said once and this one skips by its own. null or absent, the usual: this camera's own.

mirroroptionalTMirrorPlane | null

Sees the world in a mirror: everything reflected across this plane, as a mirror lying on it shows it, and nothing behind the plane. The plane is the points where `x * px + y * py + z * pz

  • d = 0, its normal (x, y, z, length one) towards the side the mirror is seen from. Its picture comes out turned left to right, which is how a mirror's material reads it back. useMirrorsets it on the camera of the picture it makes, every frame;null` or absent, none.
View source · camera/types/t_camera_3d.ts:23

TCamera3dOptionstypenacatamalon

What a 3D camera can start with. Everything is optional.

Properties

projectionoptional'perspective' | 'orthographic'

Default 'orthographic', which measures in pixels and lines up with the 2D.

transformoptionalPartial<Pick<TTransform3d, 'x' | 'y' | 'z' | 'rotation' | 'rotationX' | 'rotationY'>>

Where it is and where it looks, as it is read afterwards (camera.transform): x, y, z (default the origin, looking along -Z), rotationX and rotationY to look up and down and turn, rotation to roll, in radians.

fovoptionalnumber

In degrees. Default 60. Perspective only.

follow2doptionalboolean

Orthographic only: the models placed in the 2D world and seen through the 2D camera. See TCamera3d.follow2d. Default false.

nearoptionalnumber

Default 0.1 and 1000. An orthographic camera reads only far, and sees that far either side of it.

faroptionalnumber
zoomoptionalnumber

Default 1. Orthographic only.

View source · camera/types/t_camera_3d.ts:101

TCameraFollowtypenacatamalon

A camera following something: everything it was told, changeable at any time, and its tremor.

Properties

cameraTCamera2d

The scene's camera, which this moves: the one it has now, so a useCamera2d before or after this in the body is the one followed.

targetTCameraTarget | null

What it follows. null holds the camera where it is.

deadzone{ width, height }
boundsTTilemap | TRect | null
lead{ x, y }
smoothnumber
roundboolean
roomsTRect[] | { width, height } | null
scrollnumber
roomTRect | null

The room the camera is in, or scrolling into. null without rooms, or before the target has been in one.

scrollingboolean

true while the camera scrolls from one room to the next. Many games stop their characters while it does, as the consoles did: that is for the game to do, reading this.

shake(strength: number, seconds: number) => void

Shakes the view, up to strength pixels either way, dying away over seconds: a hit, an explosion, a boss landing. A stronger shake replaces a weaker one still going.

snap() => void

Puts the camera on its target at once, smoothing or not: after a respawn, a door, a cut.

View source · hooks/camera/use_camera_follow.ts:90

TCameraFollowOptionstypenacatamalon

How a camera follows.

Properties

deadzoneoptional{ width, height }

A box in the middle of the screen, in pixels, that the target moves inside without the camera moving: the camera only follows once the target pushes against one of its edges. Nothing by default: the target stays in the very middle.

boundsoptionalTTilemap | TRect | null

Where the camera may look, so it never shows past the edges of the level: a map, which is its own rectangle, or a rectangle of the world. Nothing by default.

leadoptional{ x, y }

How far ahead of the target it looks, in pixels: { x: 24, y: 0 } shows more of what is to the right. Turned round by the game when the character turns.

smoothoptionalnumber

How long it takes to catch up, in seconds, rather than following at once: 0.2 glides. 0, the default, follows at once, as the consoles did.

roundoptionalboolean

Whether the camera stays on whole pixels, so pixel art does not shimmer between two. true by default.

roomsoptionalTRect[] | { width, height } | null

The level cut into rooms, as the action games of the consoles did: the camera keeps inside the room the target is in, and when the target walks into another it scrolls across to it. A list of rectangles of the world (rooms of any size, which may leave gaps), or one size for a grid of equal rooms laid from the corner of bounds (or of the world, without it), screen by screen; the last of a row that does not fit bounds is cut to it. Nothing by default.

scrolloptionalnumber

How long the scroll from one room to the next takes, in seconds. 0 cuts straight to it. 0.6 by default.

onRoomoptional(room: TRect, from: TRect | null) => void

Called when the target walks into another room, as the scroll starts: to bring back the enemies of a room, to change the music. from is null for the first room.

View source · hooks/camera/use_camera_follow.ts:35

TFogtypenacatamalon

The fog a scene is seen through: things fade into color as they get further from the camera.

It is what the Nintendo 64 is remembered by, and the way every game of the era hid how near it stopped drawing. Worked out per corner and smeared across each triangle, like the light, which is how that hardware did it too. Everything here is read every frame, so changing a field fades the fog in, thickens it or turns it to dusk with nothing set up again.

Properties

type'fog'
idstring
colorTColor

What things fade into. Usually the background, or the fog shows as a wall.

nearnumber

How far from the camera the fog begins. Nearer than this is clear.

farnumber

How far from the camera it is complete. Further than this is all fog.

distanceboolean

Whether things fade by how far they are from the camera (near to far). false leaves only the fog by height, for a valley full of mist that is clear across.

height{ enabled, top, bottom }

Fog by height: below top things start to fade, and at bottom they are gone, however near. The mist at the foot of a cliff, a pit with no bottom to see. With top under bottom it runs upwards instead, for a cloud the top of a tower disappears into. enabled is false unless it was asked for, so the record always has it and a tween can fade it in.

enabledboolean

Whether it is drawn. Switching it off keeps the rest, so it can be switched back on.

View source · fog/types/t_fog.ts:15

TFogOptionstypenacatamalon

What useFog is asked for. Everything has a default, so useFog({ color }) is a fog.

Properties

coloroptionalTColorOption

What things fade into. Default black.

nearoptionalnumber

How far from the camera the fog begins. Default 10.

faroptionalnumber

How far from the camera it is complete. Default 100.

distanceoptionalboolean

Whether things fade by how far they are from the camera. Default true.

heightoptional{ top, bottom, enabled }

Fog by height: it begins at top and is complete at bottom (default -10 under top). Given, it is on unless enabled: false; left out, there is none.

enabledoptionalboolean

Whether it is drawn. Default true.

View source · fog/types/t_fog.ts:55

TMirrorPlanetypenacatamalon

A plane a camera sees the world reflected in (TCamera3d.mirror): its normal, towards the side it is seen from, and how far along it the plane is from the origin, x * px + y * py + z * pz + d = 0.

Properties

xnumber
ynumber
znumber
dnumber
View source · camera/types/t_camera_3d.ts:92

TPlanetypenacatamalon

A flat plane without end, by a point on it and the way it faces.

Properties

pointoptional{ x, y, z }

A point on it. Default the origin.

normaloptional{ x, y, z }

Which way it faces; any length but 0. Default up, { x: 0, y: 1, z: 0 }: a floor.

View source · camera/ray_on_plane.ts:10

TRayHittypenacatamalon

What a ray met: which model of which object, where, which way the surface faces there, and how far along the ray.

Properties

boxTGameObject

The object the model belongs to, the one to move, light up or take away.

meshTMesh

The model that was met.

point{ x, y, z }

Where, in the world.

normal{ x, y, z }

Which way the triangle met faces, one unit long, on the side the ray came from: what to stand a thing on, or to bounce a ball off.

distancenumber

How far along the ray, in the world's units.

trianglenumber

Which triangle of the shape, from 0, in the order of its corners.

instancenumber | null

Which instance, from 0, for a model made by createMeshInstances; null for any other.

View source · camera/cast_ray.ts:16

TScreenPointtypenacatamalon

Where a point of the world lands on the screen.

x and y are in the game's pixels, from the top-left corner, the same ones a sprite is placed in. depth goes from 0 at the camera's near plane to 1 at its far one. behind says the point is behind the camera, where x and y mean nothing and whatever was going to be drawn there should not be.

Properties

xnumber
ynumber
depthnumber
behindboolean
View source · camera/world_to_screen.ts:16