LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_scene.c File Reference

Functions

LG_Scene lg_scene_new (int id, LG_Camera *cam1, LG_Light light1, Rec2Df landscape_rec, uint16_t grid_width)
 
void lg_scene_free (LG_Scene *scene)
 
LG_SceneNodelg_scenenode_new_and_set (int id, LG_SceneNode *parent, const char *mesh_file, LG_LoadMesh_Flags flags, vec3_t transl, LG_Quat orientation, vec3_t scaling)
 

Detailed Description

 === Higher level scene/frame stuff ===

 The starting point for scenes

Function Documentation

◆ lg_scene_new()

LG_Scene lg_scene_new ( int  id,
LG_Camera cam1,
LG_Light  light1,
Rec2Df  landscape_rec,
uint16_t  grid_width 
)

Create and init a new scene

LG_Scene is defined in lg_scene_graph.h

typedef struct {
int id;
LG_Camera *cam1;
LG_Light light1;
Rec2Df landscape_rec;
LG_SceneNode *root;
LG_SceneNode *grid;
LG_SceneNode *xyz_arrows;

Generated nodes:

  • root -> parent of grid and xyz_arrows, id = 0, type = ROOT
  • grid -> with an initialized Lines3D_VB horizontal grid, id = 1, type = GRID
  • xyz_arrows -> with an initialized Lines3D_VB xyz_arrows, id = 2, type = LINES3D
Parameters
idScene's id, set to -1 on error
cam1A pointer to a LG_Camera
light1A LG_Light
landscape_recA Rec2Df, should be centered
grid_widthGrid width, ie number of units along one row or one column, should be even - if odd, we substract one
Returns
An initialized LG_Scene if OK, id set to -1 on error

◆ lg_scene_free()

void lg_scene_free ( LG_Scene scene)

Free scene resources

Parameters
sceneA LG_Scene

◆ lg_scenenode_new_and_set()

LG_SceneNode* lg_scenenode_new_and_set ( int  id,
LG_SceneNode parent,
const char *  mesh_file,
LG_LoadMesh_Flags  flags,
vec3_t  transl,
LG_Quat  orientation,
vec3_t  scaling 
)

Helper func to create and set a new LG_SceneNode instance

Create node, add node to scene graph, load node's mesh, and set node's local matrix

Helper macros for less confusion:

#define transl_v3(x, y, z) vec3(x, y, z)
#define scaling_v3(x, y, z) vec3(x, y, z)

Mesh must be freed when done with the scene

Parameters
idNode's id
parentA pointer to a scene graph node
mesh_fileRelative path to mesh file to load, inside the mesh folder
flagsApply to mesh: force_reload, invert_z, normalize_xyz, horiz_center, vert_center, vert_bottom
translTranslation/position vec3
orientationOrientation quat
scalingScaling vec3
Returns
A pointer to a LG_SceneNode if OK, NULL on error - must be freed afterwards
Rec2Df
Definition: lg_gr_func.h:56
LG_SceneNode
Definition: lg_scene_graph.h:29
LG_Scene
Definition: lg_scene_graph.h:48
LG_Light
Definition: lg_light.h:26
LG_Camera
Definition: lg_camera.h:22