Gama C Library
Gama C API Documentation
scene.h
Go to the documentation of this file.
1/**
2 * @file scene.h
3 * @brief Defines the 3D scene structure, encompassing lights, cameras, and viewport settings.
4 *
5 * This file provides the `gm3Scene` structure to manage global properties
6 * of a 3D rendering environment, making it easier to pass scene context
7 * to projection and rendering functions.
8 */
9#pragma once
10
11#include "../position.h"
12#include "camera.h"
13#include "light.h"
14
15/**
16 * @brief Represents a complete 3D scene, including its camera, lights, and viewport.
17 */
18typedef struct {
19 gmPos viewport; /**< The viewport dimensions (width, height) for rendering. */
20
21 gm3Light light; /**< The primary light source in the scene. */
22 gm3Camera camera; /**< The camera used for viewing the scene. */
23} gm3Scene;
24
25/**
26 * @brief A default `gm3Scene` instance.
27 *
28 * Initializes a scene with a default viewport (2,2), a default light, and a default camera.
29 */
31 .viewport = {2, 2},
32 .light = gm3_default_light,
33 .camera = gm3_default_camera,
34};
35
36/**
37 * @brief Initializes a `gm3Scene` struct with default values and a specified viewport.
38 * @param s A pointer to the `gm3Scene` struct to initialize.
39 * @param w The width of the viewport.
40 * @param h The height of the viewport.
41 * @return 0 on success, -1 if `s` is NULL.
42 */
43int gm3_scene_create(gm3Scene *s, double w, double h) {
44 if (s == NULL)
45 return -1;
47 s->viewport.x = w;
48 s->viewport.y = h;
49
52 return 0;
53}
54
55/**
56 * @brief Creates and returns a new `gm3Scene` struct initialized with default values.
57 * @return A new `gm3Scene` instance.
58 */
60
61/**
62 * @brief Frees any dynamically allocated memory associated with a `gm3Scene`.
63 *
64 * Currently, the `gm3Scene` struct does not directly manage any dynamically
65 * allocated pointers that require explicit freeing, so this function is a
66 * placeholder.
67 *
68 * @param s A pointer to the `gm3Scene` to free.
69 * @return 0 on success.
70 */
71int gm3_scene_free(gm3Scene *s) { (void)s; return 0; }
Defines the 3D camera structure for scene projection.
const gm3Camera gm3_default_camera
A default gm3Camera instance.
Definition camera.h:21
int gm3_camera_create(gm3Camera *c)
Initializes a gm3Camera struct with default values.
Definition camera.h:32
const gm3Light gm3_default_light
A default gm3Light instance.
Definition light.h:27
int gm3_light_create(gm3Light *l)
Initializes a gm3Light struct with default values.
Definition light.h:40
int gm3_scene_create(gm3Scene *s, double w, double h)
Initializes a gm3Scene struct with default values and a specified viewport.
Definition scene.h:43
gm3Scene gm3_scene()
Creates and returns a new gm3Scene struct initialized with default values.
Definition scene.h:59
const gm3Scene gm3_default_scene
A default gm3Scene instance.
Definition scene.h:30
int gm3_scene_free(gm3Scene *s)
Frees any dynamically allocated memory associated with a gm3Scene.
Definition scene.h:71
Represents a camera in a 3D scene, used for projection.
Definition camera.h:10
Represents a single light source in a 3D scene.
Definition light.h:13
Represents a complete 3D scene, including its camera, lights, and viewport.
Definition scene.h:18
gm3Camera camera
Definition scene.h:22
gmPos viewport
Definition scene.h:19
gm3Light light
Definition scene.h:21
Represents a 2D position or vector.
Definition position.h:8
double x
Definition position.h:9
double y
Definition position.h:9