diff options
-rw-r--r-- | gfx/include/gfx/scene/animation.h | 6 | ||||
-rw-r--r-- | gfx/include/gfx/scene/node.h | 5 | ||||
-rw-r--r-- | gfx/include/gfx/scene/scene.h | 4 | ||||
-rw-r--r-- | gfx/src/scene/node.c | 4 | ||||
-rw-r--r-- | gfx/src/scene/scene.c | 19 | ||||
-rw-r--r-- | gltfview/src/game.c | 5 |
6 files changed, 36 insertions, 7 deletions
diff --git a/gfx/include/gfx/scene/animation.h b/gfx/include/gfx/scene/animation.h index ce5d73d..eeb21fd 100644 --- a/gfx/include/gfx/scene/animation.h +++ b/gfx/include/gfx/scene/animation.h | |||
@@ -121,7 +121,7 @@ void gfx_update_animation(Anima*, R t); | |||
121 | void gfx_stop_animation(Anima*); | 121 | void gfx_stop_animation(Anima*); |
122 | 122 | ||
123 | // TODO: Remove this, it's ugly. Things would be much simpler if scene nodes | 123 | // TODO: Remove this, it's ugly. Things would be much simpler if scene nodes |
124 | // are allocated in arrays. Then our descs can take indices instead of pointers, | 124 | // were allocated in arrays. Then our descs can take indices instead of |
125 | // and locating a node is simply a matter of indexing the array. The same is | 125 | // pointers, and locating a node is simply a matter of indexing the array. The |
126 | // true for skeletons here and other objects. | 126 | // same is true for skeletons here and other objects. |
127 | const Skeleton* gfx_get_anima_skeleton(const Anima* anima, size_t i); | 127 | const Skeleton* gfx_get_anima_skeleton(const Anima* anima, size_t i); |
diff --git a/gfx/include/gfx/scene/node.h b/gfx/include/gfx/scene/node.h index 5d168c9..9507392 100644 --- a/gfx/include/gfx/scene/node.h +++ b/gfx/include/gfx/scene/node.h | |||
@@ -117,9 +117,14 @@ NodeIter gfx_get_node_child(const SceneNode*); | |||
117 | /// Get the iterator's next sibling node. | 117 | /// Get the iterator's next sibling node. |
118 | NodeIter gfx_get_next_child(NodeIter); | 118 | NodeIter gfx_get_next_child(NodeIter); |
119 | 119 | ||
120 | // TODO: Think about NodeIter and NodeIterMut for const safety. | ||
121 | |||
120 | /// Get a scene node from the iterator. | 122 | /// Get a scene node from the iterator. |
121 | const SceneNode* gfx_get_iter_node(NodeIter); | 123 | const SceneNode* gfx_get_iter_node(NodeIter); |
122 | 124 | ||
125 | /// Get a scene node from the iterator. | ||
126 | SceneNode* gfx_get_iter_node_mut(NodeIter); | ||
127 | |||
123 | /// Get the node's (local) transform. | 128 | /// Get the node's (local) transform. |
124 | mat4 gfx_get_node_transform(const SceneNode*); | 129 | mat4 gfx_get_node_transform(const SceneNode*); |
125 | 130 | ||
diff --git a/gfx/include/gfx/scene/scene.h b/gfx/include/gfx/scene/scene.h index 0de0f3c..5a1d823 100644 --- a/gfx/include/gfx/scene/scene.h +++ b/gfx/include/gfx/scene/scene.h | |||
@@ -1,5 +1,6 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <math/defs.h> | ||
3 | #include <math/fwd.h> | 4 | #include <math/fwd.h> |
4 | 5 | ||
5 | typedef struct SceneNode SceneNode; | 6 | typedef struct SceneNode SceneNode; |
@@ -8,3 +9,6 @@ typedef struct Scene Scene; | |||
8 | 9 | ||
9 | /// Get the scene's root node. | 10 | /// Get the scene's root node. |
10 | SceneNode* gfx_get_scene_root(Scene*); | 11 | SceneNode* gfx_get_scene_root(Scene*); |
12 | |||
13 | /// Update the scene's animations. | ||
14 | void gfx_animate_scene(Scene*, R t); | ||
diff --git a/gfx/src/scene/node.c b/gfx/src/scene/node.c index ea0f19d..2670680 100644 --- a/gfx/src/scene/node.c +++ b/gfx/src/scene/node.c | |||
@@ -275,6 +275,10 @@ const SceneNode* gfx_get_iter_node(NodeIter it) { | |||
275 | return mem_get_node((node_idx){.val = it}); | 275 | return mem_get_node((node_idx){.val = it}); |
276 | } | 276 | } |
277 | 277 | ||
278 | SceneNode* gfx_get_iter_node_mut(NodeIter it) { | ||
279 | return (SceneNode*)gfx_get_iter_node(it); | ||
280 | } | ||
281 | |||
278 | mat4 gfx_get_node_transform(const SceneNode* node) { | 282 | mat4 gfx_get_node_transform(const SceneNode* node) { |
279 | assert(node); | 283 | assert(node); |
280 | return node->transform; | 284 | return node->transform; |
diff --git a/gfx/src/scene/scene.c b/gfx/src/scene/scene.c index d0d5e82..19b9379 100644 --- a/gfx/src/scene/scene.c +++ b/gfx/src/scene/scene.c | |||
@@ -19,3 +19,22 @@ SceneNode* gfx_get_scene_root(Scene* scene) { | |||
19 | assert(scene); | 19 | assert(scene); |
20 | return scene->root; | 20 | return scene->root; |
21 | } | 21 | } |
22 | |||
23 | static void gfx_animate_node(SceneNode* node, R t) { | ||
24 | assert(node); | ||
25 | |||
26 | if (gfx_get_node_type(node) == AnimaNode) { | ||
27 | gfx_update_animation(gfx_get_node_anima(node), t); | ||
28 | } | ||
29 | |||
30 | for (NodeIter it = gfx_get_node_child(node); it; | ||
31 | it = gfx_get_next_child(it)) { | ||
32 | gfx_animate_node(gfx_get_iter_node_mut(it), t); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | void gfx_animate_scene(Scene* scene, R t) { | ||
37 | assert(scene); | ||
38 | SceneNode* node = gfx_get_scene_root(scene); | ||
39 | gfx_animate_node(node, t); | ||
40 | } | ||
diff --git a/gltfview/src/game.c b/gltfview/src/game.c index 662272c..698267e 100644 --- a/gltfview/src/game.c +++ b/gltfview/src/game.c | |||
@@ -262,10 +262,7 @@ void game_end(Game* game) { gfx_destroy(&game->gfx); } | |||
262 | void game_update(Game* game, double t, double dt) { | 262 | void game_update(Game* game, double t, double dt) { |
263 | // LOGD("Tick"); | 263 | // LOGD("Tick"); |
264 | 264 | ||
265 | // TODO: Animation should be handled by Gfx instead. Descend through the scene | 265 | gfx_animate_scene(game->scene, (R)t); |
266 | // looking for animas and animate them. gfx_animate(t). | ||
267 | Anima* anima = gfx_get_node_anima(game->root_node); | ||
268 | gfx_update_animation(anima, t); | ||
269 | 266 | ||
270 | // TODO: Compute bounding boxes to then find a good orbit point and radius | 267 | // TODO: Compute bounding boxes to then find a good orbit point and radius |
271 | // for each scene. | 268 | // for each scene. |