diff options
Diffstat (limited to 'gltfview/src/game.c')
-rw-r--r-- | gltfview/src/game.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/gltfview/src/game.c b/gltfview/src/game.c index f822b08..662272c 100644 --- a/gltfview/src/game.c +++ b/gltfview/src/game.c | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | #include <gfx/error.h> | 3 | #include <gfx/error.h> |
4 | #include <gfx/render_backend.h> | 4 | #include <gfx/render_backend.h> |
5 | #include <gfx/scene/camera.h> | ||
5 | #include <gfx/scene/light.h> | 6 | #include <gfx/scene/light.h> |
6 | #include <gfx/scene/material.h> | 7 | #include <gfx/scene/material.h> |
7 | #include <gfx/scene/mesh.h> | 8 | #include <gfx/scene/mesh.h> |
@@ -32,8 +33,10 @@ static const char* FLIGHT_HELMET = | |||
32 | "/assets/glTF-Sample-Models/2.0/FlightHelmet/glTF/FlightHelmet.gltf"; | 33 | "/assets/glTF-Sample-Models/2.0/FlightHelmet/glTF/FlightHelmet.gltf"; |
33 | static const char* DAMAGED_HELMET = | 34 | static const char* DAMAGED_HELMET = |
34 | "/assets/glTF-Sample-Models/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf"; | 35 | "/assets/glTF-Sample-Models/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf"; |
36 | static const char* GIRL = | ||
37 | "/home/jeanne/Nextcloud/assets/models/girl/girl-with-ground.gltf"; | ||
35 | 38 | ||
36 | #define DEFAULT_SCENE_FILE DAMAGED_HELMET | 39 | #define DEFAULT_SCENE_FILE GIRL |
37 | 40 | ||
38 | static const char* CLOUDS1_TEXTURE = "/assets/skybox/clouds1/clouds1_west.bmp"; | 41 | static const char* CLOUDS1_TEXTURE = "/assets/skybox/clouds1/clouds1_west.bmp"; |
39 | 42 | ||
@@ -189,6 +192,26 @@ static bool load_texture_debugger_scene(Game* game) { | |||
189 | return true; | 192 | return true; |
190 | } | 193 | } |
191 | 194 | ||
195 | /// Render the bounding boxes of all scene objects. | ||
196 | static void render_bounding_boxes(ImmRenderer* imm, const SceneNode* node) { | ||
197 | if (gfx_get_node_type(node) == ObjectNode) { | ||
198 | // TODO: Look at the scene log. The JointNodes are detached from the | ||
199 | // ObjectNodes. This is why the boxes are not being transformed as expected | ||
200 | // here. Anima needs to animate boxes? Use OOBB in addition to AABB? | ||
201 | const mat4 model = gfx_get_node_global_transform(node); | ||
202 | const SceneObject* obj = gfx_get_node_object(node); | ||
203 | const aabb3 box = gfx_calc_object_aabb(obj); | ||
204 | gfx_imm_set_model_matrix(imm, &model); | ||
205 | gfx_imm_draw_aabb(imm, box); | ||
206 | } | ||
207 | |||
208 | // Render children's boxes. | ||
209 | for (NodeIter it = gfx_get_node_child(node); it; | ||
210 | it = gfx_get_next_child(it)) { | ||
211 | render_bounding_boxes(imm, gfx_get_iter_node(it)); | ||
212 | } | ||
213 | } | ||
214 | |||
192 | bool game_new(Game* game, int argc, const char** argv) { | 215 | bool game_new(Game* game, int argc, const char** argv) { |
193 | // TODO: getopt() to implement proper argument parsing. | 216 | // TODO: getopt() to implement proper argument parsing. |
194 | const char* scene_filepath = argc > 1 ? argv[1] : DEFAULT_SCENE_FILE; | 217 | const char* scene_filepath = argc > 1 ? argv[1] : DEFAULT_SCENE_FILE; |
@@ -239,6 +262,8 @@ void game_end(Game* game) { gfx_destroy(&game->gfx); } | |||
239 | void game_update(Game* game, double t, double dt) { | 262 | void game_update(Game* game, double t, double dt) { |
240 | // LOGD("Tick"); | 263 | // LOGD("Tick"); |
241 | 264 | ||
265 | // TODO: Animation should be handled by Gfx instead. Descend through the scene | ||
266 | // looking for animas and animate them. gfx_animate(t). | ||
242 | Anima* anima = gfx_get_node_anima(game->root_node); | 267 | Anima* anima = gfx_get_node_anima(game->root_node); |
243 | gfx_update_animation(anima, t); | 268 | gfx_update_animation(anima, t); |
244 | 269 | ||
@@ -263,8 +288,18 @@ void game_update(Game* game, double t, double dt) { | |||
263 | } | 288 | } |
264 | 289 | ||
265 | void game_render(const Game* game) { | 290 | void game_render(const Game* game) { |
266 | gfx_render_scene( | 291 | gfx_render_scene(game->renderer, game->scene, game->camera); |
267 | game->renderer, game->render_backend, game->scene, game->camera); | 292 | |
293 | ImmRenderer* imm = gfx_get_imm_renderer(game->gfx); | ||
294 | assert(imm); | ||
295 | gfx_imm_start(imm); | ||
296 | gfx_imm_set_camera(imm, gfx_get_camera_camera(game->camera)); | ||
297 | gfx_imm_set_colour(imm, vec4_make(0.2, 0.2, 1.0, 0.3)); | ||
298 | // DEBUG | ||
299 | // const aabb3 box = aabb3_make(vec3_make(0, 0, 0), vec3_make(1, 1, 1)); | ||
300 | // gfx_imm_draw_aabb(imm, box); | ||
301 | render_bounding_boxes(imm, gfx_get_scene_root(game->scene)); | ||
302 | gfx_imm_end(imm); | ||
268 | } | 303 | } |
269 | 304 | ||
270 | void game_set_viewport(Game* game, int width, int height) { | 305 | void game_set_viewport(Game* game, int width, int height) { |