Talos docs

ViewSize

Since 0.6Changed in 0.7

ctx.camera.viewSize: the box an orthographic lens frames in the reference view, world units and pixels.

Plain text

Signature

export interface ViewSize {
  /** The box's centre to its left or right edge, world units: `halfHeight` × 16/9. */
  readonly halfWidth: number
  /** The box's centre to its top or bottom edge, world units: `orthoSize`, else 1080 / (2 × `pixelsPerUnit`), else 5. */
  readonly halfHeight: number
  /** The reference view the box is measured in: 1920 and 1080, whatever the window. */
  readonly pixelWidth: number
  readonly pixelHeight: number
}

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

Members

MemberSignatureDescription
halfWidthreadonly halfWidth: numberThe box's centre to its left or right edge, world units: halfHeight × 16/9.
halfHeightreadonly halfHeight: numberThe box's centre to its top or bottom edge, world units: orthoSize, else 1080 / (2 × pixelsPerUnit), else 5.
pixelWidthreadonly pixelWidth: numberThe reference view the box is measured in: 1920 and 1080, whatever the window.
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