LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_3d_primitives.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
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  */
53 typedef struct {
54  Vertex_rgba vb_array[LINES3D_N_VERTICES_MAX];
55  Vertex_rgba *vb_ptr;
56  uint32_t n_vertices;
57  zboolean dynamic_b;
58 } Lines3D_VB;
59 
60 typedef struct {
61  Vertex_rgba vertex[QUAD_N_VERTICES];
62 } LG_Quad;
63 
64 typedef struct {
65  Vertex_rgba vertex[CUBOID_N_VERTICES];
66 } LG_Cuboid;
67 
68 typedef struct {
69  Vertex_rgba vertex[XYZ_ARROWS_LINES3D_N_VERTICES];
70 } XYZ_Arrows;
71 
73 
75 
77 
79 
80 zboolean lg_shape_is_cuboid(LG_Cuboid *);
81 
83 
85 
87 
89 
91 
93 
94 /* (all Vertex_rgba until here) */
95 
96 /* MOSTLY DEPRECATED - should cleanup/reorganize/rewrite some of following stuff, which is a bit of a mess */
97 
99 
100 const unsigned short *lg_cube_vertex_uv_indices();
101 
103 
105 
107 
108 const unsigned short *lg_wired_cube_vertex_rgba_indices();
109 
111 
113 
114 #endif /* LG_3D_PRIMITIVES_H */
lg_sizeof_cube_normalized_vertices_uv
size_t lg_sizeof_cube_normalized_vertices_uv()
Definition: lg_3d_primitives.c:652
Vertex_uv
Definition: lg_vertex.h:21
LG_Cuboid
Definition: lg_3d_primitives.h:64
XYZ_Arrows
Definition: lg_3d_primitives.h:68
lg_centered_unit_cube
LG_Cuboid lg_centered_unit_cube(LG_Color_u c)
Definition: lg_3d_primitives.c:286
lg_shape_is_cuboid
zboolean lg_shape_is_cuboid(LG_Cuboid *shape)
Definition: lg_3d_primitives.c:207
lg_cuboid_transform
LG_Cuboid lg_cuboid_transform(LG_Cuboid cuboid, mat4_t matrix)
Definition: lg_3d_primitives.c:307
LG_Quad
Definition: lg_3d_primitives.h:60
lg_sizeof_cube_vertex_uv_indices
size_t lg_sizeof_cube_vertex_uv_indices()
Definition: lg_3d_primitives.c:662
lg_cube_vertex_uv_indices
const unsigned short * lg_cube_vertex_uv_indices()
Definition: lg_3d_primitives.c:642
lg_cube_normalized_vertices_uv
const Vertex_uv * lg_cube_normalized_vertices_uv()
Definition: lg_3d_primitives.c:619
Lines3D_VB
Definition: lg_3d_primitives.h:53
vec3_t
Definition: math_3d.h:111
lg_l3d_vb_from_arrows
Lines3D_VB lg_l3d_vb_from_arrows(XYZ_Arrows xyz_arrows)
Definition: lg_3d_primitives.c:551
lg_cuboid
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
LG_Color_u
Definition: lg_vertex.h:91
lg_cube_normalized_vertices_rgba
const Vertex_rgba * lg_cube_normalized_vertices_rgba()
Definition: lg_3d_primitives.c:718
lg_quad
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
lg_sizeof_wired_cube_vertex_rgba_indices
size_t lg_sizeof_wired_cube_vertex_rgba_indices()
Definition: lg_3d_primitives.c:759
lg_quad_transform
LG_Quad lg_quad_transform(LG_Quad quad, mat4_t matrix)
Definition: lg_3d_primitives.c:120
lg_centered_unit_quad
LG_Quad lg_centered_unit_quad(LG_Color_u c)
Definition: lg_3d_primitives.c:103
lg_xyz_arrows
XYZ_Arrows lg_xyz_arrows(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_wired_cube_vertex_rgba_indices
const unsigned short * lg_wired_cube_vertex_rgba_indices()
Definition: lg_3d_primitives.c:739
lg_l3d_vb_from_cuboid
Lines3D_VB lg_l3d_vb_from_cuboid(LG_Cuboid cuboid)
Definition: lg_3d_primitives.c:502
lg_l3d_vb_from_quad
Lines3D_VB lg_l3d_vb_from_quad(LG_Quad quad)
Definition: lg_3d_primitives.c:458
Vertex_rgba
Definition: lg_vertex.h:60
lg_sizeof_cube_normalized_vertices_rgba
size_t lg_sizeof_cube_normalized_vertices_rgba()
Definition: lg_3d_primitives.c:749
mat4_t
Definition: math_3d.h:167