# C API: Body tracking module (sona_body.h)

An optional library, `sona_body`, beside the core: webcam full-body pose to the avatar. Include `sona_body.h` and link `sona_body`. The guide: [Body tracking (sona_body)](../../guides/body-tracking.md).

## sona_body_defaults

```c
void sona_body_defaults(sona_body_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_body_options *` | The [`sona_body_options`](../fields.md#sona_body_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_body_options x_body_options;
memset(&x_body_options, 0, sizeof x_body_options);
x_body_options.size = sizeof x_body_options;
sona_body_defaults(&x_body_options);
```

`size` set; `min_cutoff` 1.5, `beta` 0.8, `min_visibility` 0.5, `lost_seconds` 0.5, `return_seconds` 0.4.

## sona_body_create

```c
sona_result sona_body_create(const sona_body_options *o, sona_body_tracker **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_body_options *` | The options, a [`sona_body_options`](../fields.md#sona_body_options) | `NULL`: the defaults |
| `out` | `sona_body_tracker **` | Receives the new body tracker | required |

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

NULL options: the defaults. `SONA_E_ARGUMENT` for a wrong size or a value out of range.

## sona_body_destroy

```c
void sona_body_destroy(sona_body_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |

**Returns** Nothing.

Frees the tracker.

## sona_body_reset

```c
void sona_body_reset(sona_body_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |

**Returns** Nothing.

Forgets the filters and the tracking state; keeps the options.

## sona_body_input_defaults

```c
void sona_body_input_defaults(sona_body_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `in` | `sona_body_input *` | The [`sona_body_input`](../fields.md#sona_body_input) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_body_input x_body_input;
sona_body_input_defaults(&x_body_input);
sona_body_input_defaults(&x_body_input);
```

`size` set, the MediaPipe layout and no points.

## sona_body_feed

```c
sona_result sona_body_feed(sona_body_tracker *t, const sona_body_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |
| `in` | `const sona_body_input *` | A [`sona_body_input`](../fields.md#sona_body_input) | required |

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

One frame of what the body tracker saw (`sona_body_input`). `SONA_E_ARGUMENT` for a wrong size, a time that is not finite, or a found body without 33 points in the MediaPipe layout.

## sona_body_apply

```c
sona_result sona_body_apply(sona_body_tracker *t, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |
| `a` | `sona_avatar *` | The avatar | required |

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

Puts the pose on an avatar through overrides below the neck, after the clip and before the IK. One tracker drives one avatar at a time. `SONA_E_NOT_READY` until the avatar is READY and posed.

## sona_body_release

```c
void sona_body_release(sona_body_tracker *t, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

Hands the joints back to the clip; nothing when a is not the avatar it drives.

## sona_body_struct_size

```c
uint32_t sona_body_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_body_struct_size("sona_config");
printf("sona_body_struct_size: %lld\n", (long long)x_got);
```

sizeof a public struct of this header by name ("sona_body_options"), for the bindings' layout checks; 0 when unknown.

## sona_body_struct_offset

```c
uint32_t sona_body_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_body_struct_offset("example");
printf("sona_body_struct_offset: %lld\n", (long long)x_got);
```

offsetof a field by "struct.field" ("sona_body_input.points"); `UINT32_MAX` when unknown.
