LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_3d_primitives.h
1/*
2 * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2026
3 * All rights reserved
4 */
5
6#ifndef LG_3D_PRIMITIVES_H
7#define LG_3D_PRIMITIVES_H
8
9/*
10 * All vertices are Vertex_rgba
11 * Could/should we implemenet the same with other vertex formats ?
12 *
13 * Check with:
14 * INFO_OUT("MAX(MAX(QUAD_LINES3D_N_VERTICES, CUBOID_LINES3D_N_VERTICES), XYZ_ARROWS_LINES3D_N_VERTICES) = %d\n",
15 * MAX(MAX(QUAD_LINES3D_N_VERTICES, CUBOID_LINES3D_N_VERTICES), XYZ_ARROWS_LINES3D_N_VERTICES))
16 * INFO_OUT("LINES3D_N_VERTICES_MAX = %d\n", LINES3D_N_VERTICES_MAX)
17 */
18
19#define QUAD_N_VERTICES 4 /* Num of vertices of a quad */
20#define QUAD_LINES3D_N_VERTICES 8 /* Num of vertices for all lines to draw a quad */
21
22#define CUBOID_N_VERTICES 8 /* Num of vertices of a cuboid */
23#define CUBOID_LINES3D_N_VERTICES 24 /* Num of vertices for all lines to draw a cuboid */
24
25#define XYZ_ARROWS_LINES3D_N_VERTICES 18 /* Num of vertices for all lines to draw an xyz_arrows */
26
27#define LINES3D_N_VERTICES_MAX 24 /* === Must be big enough, adjust as necessary === */
28
29#if QUAD_LINES3D_N_VERTICES > LINES3D_N_VERTICES_MAX
30 #error Sth is wrong with STH_LINES3D_N_VERTICES stuff
31#elif CUBOID_LINES3D_N_VERTICES > LINES3D_N_VERTICES_MAX
32 #error Sth is wrong with STH_LINES3D_N_VERTICES stuff
33#elif XYZ_ARROWS_LINES3D_N_VERTICES > LINES3D_N_VERTICES_MAX
34 #error Sth is wrong with STH_LINES3D_N_VERTICES stuff
35#endif
36
37/*
38 * Generic 3D line set vertex buffer (Vertex_rgba)
39 *
40 * Useful for generating VBO from shapes - can have:
41 * - an array of Vertex_rgba with array max size = LINES3D_N_VERTICES_MAX
42 * or:
43 * - a pointer to a bigger array (dynamically generated) of Vertex_rgba
44 *
45 * Draw with glDrawArrays(GL_LINE, 0, n_vertices)
46 *
47 * Max num of lines = LINES3D_N_VERTICES_MAX / 2
48 *
49 * The vertex buffer is either a *static* one (static array) or a *dynamic* one (malloc3() generated)
50 * You can/should access it using sth like:
51 * buffer = dynamic_b ? vb_ptr : vb_array
52 */
53typedef struct {
54 Vertex_rgba vb_array[LINES3D_N_VERTICES_MAX];
55 union {
56 Vertex_rgba *vb_ptr;
57 uint64_t unused; /* To fix serialization bug on 32-bit arch */
58 };
59 uint32_t n_vertices;
60 zboolean dynamic_b;
62
63typedef struct {
64 Vertex_rgba vertex[QUAD_N_VERTICES];
65} LG_Quad;
66
67typedef struct {
68 Vertex_rgba vertex[CUBOID_N_VERTICES];
69} LG_Cuboid;
70
71typedef struct {
72 Vertex_rgba vertex[XYZ_ARROWS_LINES3D_N_VERTICES];
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
103/* (all Vertex_rgba until here) */
104
105/* MOSTLY DEPRECATED - should cleanup/reorganize/rewrite some of following stuff, which is a bit of a mess */
106
108
109const unsigned short *lg_cube_vertex_uv_indices();
110
112
114
116
117const unsigned short *lg_wired_cube_vertex_rgba_indices();
118
120
122
123#endif /* LG_3D_PRIMITIVES_H */
LG_Cuboid lg_cuboid(vec3_t v0, vec3_t v1, vec3_t v2, vec3_t v3, vec3_t v4, vec3_t v5, vec3_t v6, vec3_t v7, LG_Color_u c)
Definition lg_3d_primitives.c:171
size_t lg_sizeof_cube_normalized_vertices_rgba()
Definition lg_3d_primitives.c:791
size_t lg_sizeof_cube_vertex_uv_indices()
Definition lg_3d_primitives.c:704
size_t lg_sizeof_wired_cube_vertex_rgba_indices()
Definition lg_3d_primitives.c:801
XYZ_Arrows lg_xyz_arrows_RH(float k, LG_Color_u x_axis_color, LG_Color_u y_axis_color, LG_Color_u z_axis_color)
Definition lg_3d_primitives.c:439
XYZ_Arrows lg_xyz_arrows_LH(float k, LG_Color_u x_axis_color, LG_Color_u y_axis_color, LG_Color_u z_axis_color)
Definition lg_3d_primitives.c:398
LG_Cuboid lg_centered_unit_cube(LG_Color_u c)
Definition lg_3d_primitives.c:286
LG_Quad lg_centered_unit_quad(LG_Color_u c)
Definition lg_3d_primitives.c:103
vec3_t vec3_RH_to_LH(vec3_t v)
Definition lg_3d_primitives.c:600
LG_Cuboid lg_cuboid_transform(LG_Cuboid cuboid, mat4_t matrix)
Definition lg_3d_primitives.c:307
Lines3D_VB lg_l3d_vb_from_quad(LG_Quad quad)
Definition lg_3d_primitives.c:477
zboolean lg_shape_is_cuboid(LG_Cuboid *shape)
Definition lg_3d_primitives.c:207
const Vertex_rgba * lg_cube_normalized_vertices_rgba()
Definition lg_3d_primitives.c:760
Lines3D_VB lg_l3d_vb_from_cuboid(LG_Cuboid cuboid)
Definition lg_3d_primitives.c:521
LG_Quad lg_quad(vec3_t v0, vec3_t v1, vec3_t v2, vec3_t v3, LG_Color_u c)
Definition lg_3d_primitives.c:68
const unsigned short * lg_cube_vertex_uv_indices()
Definition lg_3d_primitives.c:684
vec3_t vec3_LH_to_RH(vec3_t v)
Definition lg_3d_primitives.c:592
Lines3D_VB lg_l3d_vb_from_arrows(XYZ_Arrows xyz_arrows)
Definition lg_3d_primitives.c:570
LG_Quad lg_quad_transform(LG_Quad quad, mat4_t matrix)
Definition lg_3d_primitives.c:120
const unsigned short * lg_wired_cube_vertex_rgba_indices()
Definition lg_3d_primitives.c:781
const Vertex_uv * lg_cube_normalized_vertices_uv()
Definition lg_3d_primitives.c:661
size_t lg_sizeof_cube_normalized_vertices_uv()
Definition lg_3d_primitives.c:694
Definition lg_vertex.h:111
Definition lg_3d_primitives.h:67
Definition lg_3d_primitives.h:63
Definition lg_3d_primitives.h:53
Definition lg_vertex.h:80
Definition lg_vertex.h:23
Definition lg_3d_primitives.h:71
Definition math_3d.h:123
Definition math_3d.h:179