# C API: Two-avatar interactions and seats

High fives, handshakes, hugs, holding hands and sitting, with the avatars placed and their hands and hips meeting: [Two-avatar interactions](../../guides/interactions.md).

## sona_seat_defaults

```c
void sona_seat_defaults(sona_seat *s, uint32_t kind);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_seat *` | The [`sona_seat`](../fields.md#sona_seat) to fill with the defaults | required |
| `kind` | `uint32_t` | Which kind, one of the header's constants for it | - |

**Returns** Nothing.

**Example** (also in [Two-avatar interactions and seats](../../guides/interactions.md)):

```c
sona_interaction_defaults(&d, SONA_INTERACT_SIT);
d.a = adult; d.b = child;          /* b NULL: one sitter */
d.flags = SONA_INTERACT_HANDS;     /* two sitters: the near hands hold */
sona_seat_defaults(&d.seat, SONA_SEAT_BENCH);
d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f;   /* the front edge's middle, on top */
d.seat.turn_deg = 0;               /* the way they face */
sona_interaction_start(ctx, &d, &it);
```

`size` set and a seat of that kind: `height` 0.45 (0 for GROUND), `depth` 0.45 (unlimited for GROUND), `width` 0.5 for a chair, 1.4 for a bench and unlimited on the ground.

## sona_interaction_defaults

```c
void sona_interaction_defaults(sona_interaction_desc *d, uint32_t kind);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `sona_interaction_desc *` | The [`sona_interaction_desc`](../fields.md#sona_interaction_desc) to fill with the defaults | required |
| `kind` | `uint32_t` | Which kind, one of the header's constants for it | - |

**Returns** Nothing.

**Example** (also in [Two-avatar interactions and seats](../../guides/interactions.md)):

```c
sona_interaction_defaults(&d, SONA_INTERACT_SIT);
d.a = adult; d.b = child;          /* b NULL: one sitter */
d.flags = SONA_INTERACT_HANDS;     /* two sitters: the near hands hold */
sona_seat_defaults(&d.seat, SONA_SEAT_BENCH);
d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f;   /* the front edge's middle, on top */
d.seat.turn_deg = 0;               /* the way they face */
sona_interaction_start(ctx, &d, &it);
```

Sets size, kind, the kind's default timings in seconds (high five 0.8, 0.15, 0.7; handshake 0.9, 1.6, 0.8; hug 1.1, 2.5, 1.0; hold hands 0.8, 0, 0.6; sit 1.3, 0, 1.4) and a default seat.

## sona_interaction_layout

```c
sona_result sona_interaction_layout(const sona_interaction_desc *d, sona_interaction_plan *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `const sona_interaction_desc *` | The options, a [`sona_interaction_desc`](../fields.md#sona_interaction_desc) | required |
| `out` | `sona_interaction_plan *` | Receives the [`sona_interaction_plan`](../fields.md#sona_interaction_plan) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_interaction_desc x_interaction_desc;
memset(&x_interaction_desc, 0, sizeof x_interaction_desc);
x_interaction_desc.size = sizeof x_interaction_desc;
sona_interaction_plan x_interaction_plan2;
memset(&x_interaction_plan2, 0, sizeof x_interaction_plan2);
x_interaction_plan2.size = sizeof x_interaction_plan2;
sona_result result = sona_interaction_layout(&x_interaction_desc, &x_interaction_plan2);
if (result != SONA_OK) printf("sona_interaction_layout: %s\n", sona_result_name(result));
```

`SONA_E_ARGUMENT` for a bad desc (sizes, kind, flags, timings, a missing or repeated avatar, a seat too narrow for two), `SONA_E_NOT_READY` until both avatars are READY, and for SIT `SONA_PENDING` until the stock sit clip has been read (the call asks the sources for it; call again). Owner thread only, like `sona_interaction_start`: it measures both bodies (a few milliseconds) and may read the clip into the ctx.

## sona_interaction_start

```c
sona_result sona_interaction_start(sona_ctx *ctx, const sona_interaction_desc *d, sona_interaction **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `d` | `const sona_interaction_desc *` | The options, a [`sona_interaction_desc`](../fields.md#sona_interaction_desc) | required |
| `out` | `sona_interaction **` | Receives the new interaction | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [Two-avatar interactions and seats](../../guides/interactions.md)):

```c
sona_interaction_defaults(&d, SONA_INTERACT_SIT);
d.a = adult; d.b = child;          /* b NULL: one sitter */
d.flags = SONA_INTERACT_HANDS;     /* two sitters: the near hands hold */
sona_seat_defaults(&d.seat, SONA_SEAT_BENCH);
d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f;   /* the front edge's middle, on top */
d.seat.turn_deg = 0;               /* the way they face */
sona_interaction_start(ctx, &d, &it);
```

Starts it: the avatars are placed (eased over the first part of the start phase when they are near), their clips started together and their IK targets driven from now on. An avatar in another running interaction is refused (`SONA_E_ARGUMENT`); `SONA_E_LIMIT` when the ctx holds 64, finished ones included: an interaction is freed only by `sona_interaction_remove` (or `sona_close`), so a handle stays valid until the host removes it.

## sona_interaction_end

```c
sona_result sona_interaction_end(sona_interaction *it);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](../../troubleshooting.md#error-codes)).

Begins the end phase now (a hold of 0 waits for this). No effect once ending.

## sona_interaction_move

```c
sona_result sona_interaction_move(sona_interaction *it, const float position[3], float turn_deg);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |
| `position` | `const float [3]` | Where to move it, world space | required |
| `turn_deg` | `float` | Which way it faces, degrees | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](../../troubleshooting.md#error-codes)).

Moves the place (and the seat with it) while it runs, for a pair walking hand in hand; contacts follow.

## sona_interaction_remove

```c
void sona_interaction_remove(sona_interaction *it);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |

**Returns** Nothing.

**Example** (also in [Cookbook: recipes for game moments](../../cookbook.md)):

```c
sona_interaction_desc d;
sona_interaction *it;
sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE);
d.a = avatar;
d.b = other;
if (sona_interaction_start(ctx, &d, &it) == SONA_OK) {
  /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */
}
```

Stops at once and frees it: its IK targets go, the avatars stay where they are and keep their clip.

## sona_interaction_status_get

```c
sona_result sona_interaction_status_get(const sona_interaction *it, sona_interaction_status *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `const sona_interaction *` | The interaction | required |
| `out` | `sona_interaction_status *` | Receives the [`sona_interaction_status`](../fields.md#sona_interaction_status) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

Where an interaction is: its kind and phase, the time in the phase and how far through it, whether the contacts are together, the widest gap at a contact, the clearance between the two bodies (negative: into each other), the contact points now and the IK hit bits of both avatars' limbs.

## sona_interaction_events

```c
uint32_t sona_interaction_events(sona_interaction *it, sona_interaction_event *out, uint32_t max);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |
| `out` | `sona_interaction_event *` | Receives the [`sona_interaction_event`](../fields.md#sona_interaction_event) | required |
| `max` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example** (also in [Cookbook: recipes for game moments](../../cookbook.md)):

```c
sona_interaction_desc d;
sona_interaction *it;
sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE);
d.a = avatar;
d.b = other;
if (sona_interaction_start(ctx, &d, &it) == SONA_OK) {
  /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */
}
```

Moves up to `max` events since the last call into `out` (`SONA_INTERACT_EV_*`: contact, a handshake pump, release, end, cancel) and returns how many.
