# `Cauldron2D.Sectors.View`
[🔗](https://github.com/jaman/cauldron/blob/v0.2.2/cauldron_2d/lib/cauldron_2d/sectors/view.ex#L1)

Draws a sector map from a point inside it: walls, floors, ceilings and sky, and the
things standing in it, nearest in front, into a `Cauldron2D.Sectors.Frame`.

    %{frame: frame, seen: lines} =
      Cauldron2D.Sectors.View.render(frame, pictures, map, %{
        x: 1056.0, y: -3616.0, z: 41.0, angle: :math.pi() / 2,
        sectors: sectors, sides: sides, things: things
      }, sky: %{picture: sky, flat: sky_flat, columns: 1024 / (2 * :math.pi()), mid: 100.0, step: 1.0})

`map` is a `Cauldron2D.Sectors.Map` with its BSP. The view gives the eye's `x`, `y` and
height `z`, its heading `angle` in radians (`0` along `+x`), and the `sectors` and
`sides` as they are now — a door's ceiling moves and a switch's picture changes, so the
game passes its own copies rather than the map's. `pitch` moves the horizon up (`> 0`)
or down by that many pixels. `things` are what stand in the sectors:

    %{x:, y:, z:, sector:, picture:, offset: {left, top}, flip: false, bright: false, shimmer: false}

where `z` is the height of the thing's feet, `offset` where the picture's origin is —
`left` texels from its left edge, `top` texels above its bottom row at the feet — and
`bright` draws it unlit. A `shimmer` thing is drawn as a blur of what is behind it.

The result's `seen` is the set of line indexes some of which was drawn, for an automap.

## Options

  * `:sky` — `%{picture:, flat:, columns:, mid:, step:}`: a ceiling whose picture is
    `flat` shows picture `picture` wrapped around the view, `columns` picture columns
    per radian, its row `mid` at the horizon and `step` rows a pixel; default none
  * `:stretch` — how many times taller than wide a world unit is drawn. Default `1.0`
  * `:contrast` — light added to walls running along `y` and taken from walls running
    along `x`, so corners read. Default `0`
  * `:extra_light` — light added everywhere. Default `0`
  * `:fixed` — a light table to draw everything through instead of lighting it. Default `nil`
  * `:light` — options for `Cauldron2D.Sectors.Light`
  * `:fov` — the horizontal field of view in radians. Default `π/2`

# `eye`

```elixir
@type eye() :: %{
  :x =&gt; number(),
  :y =&gt; number(),
  :z =&gt; number(),
  :angle =&gt; number(),
  :sectors =&gt; tuple(),
  :sides =&gt; tuple(),
  optional(:things) =&gt; [thing()],
  optional(:pitch) =&gt; number()
}
```

# `thing`

```elixir
@type thing() :: %{
  :x =&gt; number(),
  :y =&gt; number(),
  :z =&gt; number(),
  :sector =&gt; non_neg_integer(),
  :picture =&gt; non_neg_integer(),
  optional(:offset) =&gt; {number(), number()},
  optional(:flip) =&gt; boolean(),
  optional(:bright) =&gt; boolean(),
  optional(:shimmer) =&gt; boolean()
}
```

# `render`

```elixir
@spec render(
  Cauldron2D.Sectors.Frame.t(),
  Cauldron2D.Sectors.Pictures.t(),
  Cauldron2D.Sectors.Map.t(),
  eye(),
  keyword()
) :: %{frame: Cauldron2D.Sectors.Frame.t(), seen: MapSet.t(non_neg_integer())}
```

Draw `map` as seen by `eye` onto `frame`. See the moduledoc.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
