LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
|
=== A few 3D structs and funcs for line set vertex buffers === All vertices are Vertex_rgba (so far) So far: - Lines3D_VB - line set vertex buffer and num of vertices, max num of lines = LINES3D_N_VERTICES_MAX / 2 - LG_Quad - LG_Cuboid - XYZ_Arrows About Lines3D_VB: typedef struct { Vertex_rgba vb_array[LINES3D_N_VERTICES_MAX]; Vertex_rgba *vb_ptr; uint32_t n_vertices; zboolean dynamic_b; } Lines3D_VB; Useful for generating VBO from shapes - can have: - an array of Vertex_rgba with array max num of elements = LINES3D_N_VERTICES_MAX or: - a pointer to a bigger, dynamically generated, array of Vertex_rgba So the vertex buffer is either a *static* one (static array) or a *dynamic* one (malloc3() generated) You can/should access it using sth like: buffer = dynamic_b ? vb_ptr : vb_array
Return a new quad from 4 (QUAD_N_VERTICES) vec3_t vertices and a LG_Color_u
Vertex order is:
v0 | Vertex v[0] spatial coords as a vec3_t |
v1 | Vertex v[1] spatial coords as a vec3_t |
v2 | Vertex v[2] spatial coords as a vec3_t |
v3 | Vertex v[3] spatial coords as a vec3_t |
c | Color as a LG_Color_u |
LG_Quad lg_centered_unit_quad | ( | LG_Color_u | c | ) |
Return a new centered colored unit quad
Quad side length = 1.0
Quad is centered on origin (0.0, 0.0, 0.0)
Vertex order is:
c | A LG_Color_u |
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 | ||
) |
Return a new cuboid from 8 (CUBOID_N_VERTICES) vec3_t vertices and a LG_Color_u
Actually may return a non-cuboid 8 vertices shape - a bit strange
So, if necessary, you may test the new cuboid with lg_shape_is_cuboid()
Note: A cuboid with all square faces is a cube
Vertex order is:
v0 | Vertex v[0] spatial coords as a vec3_t |
v1 | Vertex v[1] spatial coords as a vec3_t |
v2 | Vertex v[2] spatial coords as a vec3_t |
v3 | Vertex v[3] spatial coords as a vec3_t |
v4 | Vertex v[4] spatial coords as a vec3_t |
v5 | Vertex v[5] spatial coords as a vec3_t |
v6 | Vertex v[6] spatial coords as a vec3_t |
v7 | Vertex v[7] spatial coords as a vec3_t |
color | Color as a LG_Color_u |
zboolean lg_shape_is_cuboid | ( | LG_Cuboid * | shape | ) |
Test if an 8 vertices shape is a cuboid
Only compute dot products at v[0] and v[6], not sure it's enough so need more testing
Vertex order is:
LG_Cuboid lg_centered_unit_cube | ( | LG_Color_u | c | ) |
Return a new centered axis-aligned colored unit cube
Cube side length = 1.0
Cube is centered on origin (0.0, 0.0, 0.0)
Vertex order is:
c | A LG_Color_u |
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 | ||
) |
Return a new XYZ_Arrows
Colored XYZ arrows in OpenGL coord sys
VB = all lines, with 2 vertices per line, so like: line0 = v0, v1, line1 = v1, v2, line2 = v2, v3, ... -> v0, v1, v1, v2, v2, v3, ... XYZ_ARROWS_LINES3D_N_VERTICES = 18 (in 3d_primitives.h)
Use default colors (red, green, blue) if all axis colors components set to 0 (r == 0 && g == 0 && b == 0 && a == 0)
k | Scaling factor |
x_axis_color | |
y_axis_color | |
z_axis_color |
Lines3D_VB lg_l3d_vb_from_quad | ( | LG_Quad | quad | ) |
Create and fill a Lines3D_VB (line set vertex buffer and num of vertices) from a quad
Draw with glDrawArrays(GL_LINE, 0, QUAD_LINES3D_N_VERTICES or n_vertices) (if n_vertices > 0)
The vertex buffer is a static one (static array)
quad | A LG_Quad |
Lines3D_VB lg_l3d_vb_from_cuboid | ( | LG_Cuboid | cuboid | ) |
Create and fill a Lines3D_VB (line set vertex buffer and num of vertices) from a cuboid
Draw with glDrawArrays(GL_LINE, 0, CUBOID_LINES3D_N_VERTICES or n_vertices) (if n_vertices > 0)
The vertex buffer is a static one (static array)
Then 0-4, 1-5, 2-6, 3-7
cuboid | A LG_Cuboid |
Lines3D_VB lg_l3d_vb_from_arrows | ( | XYZ_Arrows | xyz_arrows | ) |
Create and fill a Lines3D_VB (line set vertex buffer and num of vertices) from a XYZ_Arrows
Draw with glDrawArrays(GL_LINE, 0, XYZ_ARROWS_LINES3D_N_VERTICES or n_vertices) (if n_vertices > 0)
The vertex buffer is a static one (static array)
xyz_arrows | A XYZ_Arrows |
const Vertex_uv* lg_cube_normalized_vertices_uv | ( | ) |
=== From here on, MOSTLY DEPRECATED stuff - should cleanup/reorganize/rewrite some of following stuff, which is a bit of a mess ===
Get a static 3D cube's normalized vertices with uv texture coords
const unsigned short* lg_cube_vertex_uv_indices | ( | ) |
Get a static 3D cube's indices
size_t lg_sizeof_cube_normalized_vertices_uv | ( | ) |
Get size of 3D cube vertices
size_t lg_sizeof_cube_vertex_uv_indices | ( | ) |
Get size of 3D cube indices
const Vertex_rgba* lg_cube_normalized_vertices_rgba | ( | ) |
Get a static 3D cube's normalized vertices with RGBA colors
const unsigned short* lg_wired_cube_vertex_rgba_indices | ( | ) |
Get a static 3D cube's indices
size_t lg_sizeof_cube_normalized_vertices_rgba | ( | ) |
Get size of 3D cube vertices
size_t lg_sizeof_wired_cube_vertex_rgba_indices | ( | ) |
Get size of 3D cube indices