Gama C Library
Gama C API Documentation
light.h
Go to the documentation of this file.
1#pragma once
2
3#include "../color.h"
4#include "position.h"
5
6/**
7 * @brief Represents a single light source in a 3D scene.
8 *
9 * This struct defines the properties of a light, including its position,
10 * direction, color, and intensity, which are used in lighting calculations
11 * by the 3D renderer.
12 */
13typedef struct {
14 gm3Pos position; /**< World-space position of the light source. */
15 gm3Pos direction; /**< Direction of the light (e.g., for directional lights). */
16 gmColor color; /**< The color of the light. */
17 double intensity; /**< The brightness of the light (e.g., 0.0 to 1.0). */
18 double ambient; /**< The ambient light contribution (0.0 to 1.0). */
19} gm3Light;
20
21/**
22 * @brief A default `gm3Light` instance.
23 *
24 * Initializes a light source at `{0, 1, 0}` pointing towards `{0, -1, 1}`,
25 * with a white color, medium intensity, and some ambient light.
26 */
28 .position = {0, 1, 0},
29 .direction = {0, -1, 1},
30 .color = 0xCCCCCCFF,
31 .intensity = 0.5,
32 .ambient = 0.5,
33};
34
35/**
36 * @brief Initializes a `gm3Light` struct with default values.
37 * @param l A pointer to the `gm3Light` struct to initialize.
38 * @return 0 on success, -1 if `l` is NULL.
39 */
41 if (!l)
42 return -1;
44 // The original code had memset(l, 0, sizeof(gm3Light)) here after assigning
45 // the default. This would zero out all the default values.
46 // Assuming the intention is to use the default values, I'm removing memset.
47 // If the intention was to zero it out, then the default values would be useless.
48 // If a zero-initialized light is desired, it should be done explicitly.
49
50 return 0;
51}
uint32_t gmColor
Type definition for color values, stored as a 32-bit unsigned integer. The color components are packe...
Definition color.h:13
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
Represents a single light source in a 3D scene.
Definition light.h:13
double intensity
Definition light.h:17
gm3Pos position
Definition light.h:14
gm3Pos direction
Definition light.h:15
gmColor color
Definition light.h:16
double ambient
Definition light.h:18
Represents a 3D position or vector.
Definition position.h:11