setViewOffset method

void setViewOffset(
  1. double fullWidth,
  2. double fullHeight,
  3. double x,
  4. double y,
  5. double width,
  6. double height,
)

fullWidth — full width of multiview setup

fullHeight — full height of multiview setup

x — horizontal offset of subcamera

y — vertical offset of subcamera

width — width of subcamera

height — height of subcamera

Sets an offset in a larger frustum. This is useful for multi-window or multi-monitor/multi-machine setups.

For example, if you have 3x2 monitors and each monitor is 1920x1080 and the monitors are in grid like this:

+---+---+---+
| A | B | C |
+---+---+---+
| D | E | F |
+---+---+---+

then for each monitor you would call it like this:

const w = 1920;
const h = 1080;
final fullWidth = w * 3;
final fullHeight = h * 2;

// A
camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
// B
camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
// C
camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
// D
camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
// E
camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
// F
camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );

Implementation

/// then for each monitor you would call it like this:
///
	/// ```
/// const w = 1920;
/// const h = 1080;
/// final fullWidth = w * 3;
/// final fullHeight = h * 2;
///
/// // A
/// camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
/// // B
/// camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
/// // C
/// camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
/// // D
/// camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
/// // E
/// camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
/// // F
/// camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
/// ```
void setViewOffset(double fullWidth, double fullHeight, double x, double y, double width, double height) {
  aspect = fullWidth / fullHeight;

  view ??= CameraView();

  view!.enabled = true;
  view!.fullWidth = fullWidth;
  view!.fullHeight = fullHeight;
  view!.offsetX = x;
  view!.offsetY = y;
  view!.width = width;
  view!.height = height;

  updateProjectionMatrix();
}