Skip to content

C API: Camera helpers

Pure maths, as the web SDK's camera. Presets: SONA_PRESET_FULL, UPPER, BUST, FACE.

sona_camera_preset

sona_result sona_camera_preset(const sona_avatar *a, sona_preset p,
                               sona_view *view);
Parameter and type Meaning
a
const sona_avatar *
The avatar (required)
p
sona_preset
The framing: full, upper, bust or face
view
sona_view *
Receives the camera, a sona_view (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).

Example (also in The same picture natively and on the web):

sona_quality q;
sona_draw_options o;
sona_quality_defaults(&q);
q.msaa = 1;                      /* one sample */
q.flags = 0;                     /* no mips */
sona_renderer_set_quality(renderer, &q);
memset(&o, 0, sizeof o);
o.flags = SONA_DRAW_NO_CREDIT;   /* no shadow, no badge; bloom stays on */
sona_camera_preset(avatar, SONA_PRESET_FULL, &view);
sona_snapshot(renderer, &view, 512, 512, &o, rgba);

Sets view->eye and view->target to one of the console's framings on one ready avatar.

sona_camera_fit_crowd

void sona_camera_fit_crowd(const sona_ctx *ctx, sona_view *view);
Parameter and type Meaning
ctx
const sona_ctx *
The context (required)
view
sona_view *
Receives the camera, a sona_view (required)

Returns Nothing.

Example:

sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
sona_camera_fit_crowd(ctx, &x_view);

Fits every ready avatar in view (the web's preset "crowd"). Keeps fov, near, far, width and height.

sona_camera_orbit

void sona_camera_orbit(sona_view *view, const double target[3],
                       double yaw_deg, double pitch_deg, double distance);
Parameter and type Meaning
view
sona_view *
Receives the camera, a sona_view (required)
target
const double [3]
The point the eye looks at (required)
yaw_deg
double
Yaw in degrees
pitch_deg
double
Pitch in degrees, up positive
distance
double
How far the eye is from the target, metres

Returns Nothing.

Example:

sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
double x_target2[3];
memset(x_target2, 0, sizeof x_target2);
sona_camera_orbit(&x_view, x_target2, 30.0f, 30.0f, 0);

Places the eye on an orbit around target. Hosts wire their own input to it.

sona_view_matrices

void sona_view_matrices(const sona_view *view, float view_m[16],
                        float proj_m[16]);
Parameter and type Meaning
view
const sona_view *
The camera, a sona_view (required)
view_m
float [16]
Receives the view matrix, row-major (required)
proj_m
float [16]
Receives the projection matrix, row-major (required)

Returns Nothing.

Example:

sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
float x_view_m2[16];
memset(x_view_m2, 0, sizeof x_view_m2);
float x_proj_m3[16];
memset(x_proj_m3, 0, sizeof x_proj_m3);
sona_view_matrices(&x_view, x_view_m2, x_proj_m3);

Row-vector view and projection matrices (D3D depth 0..1), for hosts that draw themselves. Double maths, one float store per element, as the web.

This page as Markdown · All the docs as one file (llms-full.txt)