Talos docs

ViewSize

Since 0.6

ctx.camera.viewSize: an orthographic view's extent in world units, and the viewport in pixels.

Plain text

Signature

export interface ViewSize {
  /** The view centre to its left or right edge, world units: `halfHeight` times the viewport's aspect. */
  readonly halfWidth: number
  /** The view centre to its top or bottom edge, world units: `orthoSize`, else pixel height / (2 × `pixelsPerUnit`), else 5. */
  readonly halfHeight: number
  /** The viewport's size, pixels: the window's (or the headless frame's). */
  readonly pixelWidth: number
  readonly pixelHeight: number
}

Import: import type { ViewSize } from "@argus/api"

Members

MemberSignatureDescription
halfWidthreadonly halfWidth: numberThe view centre to its left or right edge, world units: halfHeight times the viewport's aspect.
halfHeightreadonly halfHeight: numberThe view centre to its top or bottom edge, world units: orthoSize, else pixel height / (2 × pixelsPerUnit), else 5.
pixelWidthreadonly pixelWidth: numberThe viewport's size, pixels: the window's (or the headless frame's).
pixelHeightreadonly pixelHeight: number

Example

The tested fixture fixtures/host/road-edges.ts.

// A behavior that keeps a car inside the road's wall: what `ctx.world.road(id).edge(s)` is for.
import type { Behavior } from "@argus/api"

export default {
  update(ctx) {
    const road = ctx.world.road("track")
    if (road === null) return
    const here = road.closest(ctx.entity.position)
    const edge = road.edge(here.s)
    // Keep the car's centre a radius inside the wall's inner face, or the kerb's edge when there is no wall.
    const limit = (edge.barrier?.inner ?? edge.kerbOuter) - 0.8
    const over: number = Math.abs(here.offset) - limit
    const wallHeight: number | undefined = road.barrier?.heightM
    const sides: "left" | "right" | "both" | undefined = road.barrier?.sides
    const kerb: number = road.kerbWidth + road.kerbHeight
    ctx.state.over = [over, wallHeight, sides, kerb, edge.halfWidth, edge.barrier?.left, edge.barrier?.right, edge.barrier?.outer, edge.barrier?.height]
  },
} satisfies Behavior