diff options
-rw-r--r-- | gfx/include/gfx/scene/model.h | 4 | ||||
-rw-r--r-- | gfx/include/gfx/scene/node.h | 26 | ||||
-rw-r--r-- | gfx/src/renderer/renderer.c | 6 | ||||
-rw-r--r-- | gfx/src/scene/model.c | 2 | ||||
-rw-r--r-- | gfx/src/scene/node.c | 35 |
5 files changed, 48 insertions, 25 deletions
diff --git a/gfx/include/gfx/scene/model.h b/gfx/include/gfx/scene/model.h index c55fc8c..42f85d4 100644 --- a/gfx/include/gfx/scene/model.h +++ b/gfx/include/gfx/scene/model.h | |||
@@ -9,6 +9,4 @@ Anima* gfx_get_model_anima(Model*); | |||
9 | 9 | ||
10 | /// Return the model's root node. | 10 | /// Return the model's root node. |
11 | const SceneNode* gfx_get_model_root(const Model*); | 11 | const SceneNode* gfx_get_model_root(const Model*); |
12 | 12 | SceneNode* gfx_get_model_root_mut(Model*); | |
13 | /// Return the model's root node. | ||
14 | SceneNode* gfx_get_model_root_mut(Model*); | ||
diff --git a/gfx/include/gfx/scene/node.h b/gfx/include/gfx/scene/node.h index 77db85c..a2c2836 100644 --- a/gfx/include/gfx/scene/node.h +++ b/gfx/include/gfx/scene/node.h | |||
@@ -80,50 +80,50 @@ void gfx_destroy_node(SceneNode**); | |||
80 | // Getters. | 80 | // Getters. |
81 | // ----------------------------------------------------------------------------- | 81 | // ----------------------------------------------------------------------------- |
82 | 82 | ||
83 | // TODO: Review constness of getters here. | ||
84 | |||
85 | /// Get the node's type. | 83 | /// Get the node's type. |
86 | NodeType gfx_get_node_type(const SceneNode*); | 84 | NodeType gfx_get_node_type(const SceneNode*); |
87 | 85 | ||
88 | /// Get the node's anima. | 86 | /// Get the node's anima. |
89 | /// | 87 | /// |
90 | /// The node must be of type AnimaNode. | 88 | /// The node must be of type AnimaNode. |
91 | Anima* gfx_get_node_anima(const SceneNode*); | 89 | const Anima* gfx_get_node_anima(const SceneNode*); |
90 | Anima* gfx_get_node_anima_mut(SceneNode*); | ||
92 | 91 | ||
93 | /// Get the node's camera. | 92 | /// Get the node's camera. |
94 | /// | 93 | /// |
95 | /// The node must be of type CameraNode. | 94 | /// The node must be of type CameraNode. |
96 | SceneCamera* gfx_get_node_camera(const SceneNode* node); | 95 | const SceneCamera* gfx_get_node_camera(const SceneNode* node); |
96 | SceneCamera* gfx_get_node_camera_mut(SceneNode* node); | ||
97 | 97 | ||
98 | /// Get the node's light. | 98 | /// Get the node's light. |
99 | /// | 99 | /// |
100 | /// The node must be of type LightNode. | 100 | /// The node must be of type LightNode. |
101 | Light* gfx_get_node_light(const SceneNode*); | 101 | const Light* gfx_get_node_light(const SceneNode*); |
102 | Light* gfx_get_node_light_mut(SceneNode*); | ||
102 | 103 | ||
103 | /// Get the node's model. | 104 | /// Get the node's model. |
104 | /// | 105 | /// |
105 | /// The node must be of type ModelNode. | 106 | /// The node must be of type ModelNode. |
106 | Model* gfx_get_node_model(const SceneNode*); | 107 | const Model* gfx_get_node_model(const SceneNode*); |
108 | Model* gfx_get_node_model_mut(SceneNode*); | ||
107 | 109 | ||
108 | /// Get the node's scene object. | 110 | /// Get the node's scene object. |
109 | /// | 111 | /// |
110 | /// The node must be of type ObjectNode. | 112 | /// The node must be of type ObjectNode. |
111 | SceneObject* gfx_get_node_object(const SceneNode*); | 113 | const SceneObject* gfx_get_node_object(const SceneNode*); |
114 | SceneObject* gfx_get_node_object_mut(SceneNode*); | ||
112 | 115 | ||
113 | /// Get the node's parent. | 116 | /// Get the node's parent. |
114 | const SceneNode* gfx_get_node_parent(const SceneNode*); | 117 | const SceneNode* gfx_get_node_parent(const SceneNode*); |
118 | SceneNode* gfx_get_node_parent_mut(SceneNode*); | ||
115 | 119 | ||
116 | /// Get the node's first child. | 120 | /// Get the node's first child. |
117 | const SceneNode* gfx_get_node_child(const SceneNode*); | 121 | const SceneNode* gfx_get_node_child(const SceneNode*); |
118 | 122 | SceneNode* gfx_get_node_child_mut(SceneNode*); | |
119 | /// Get the node's first child. | ||
120 | SceneNode* gfx_get_node_child_mut(SceneNode*); | ||
121 | 123 | ||
122 | /// Get the node's immediate sibling. | 124 | /// Get the node's immediate sibling. |
123 | const SceneNode* gfx_get_node_sibling(const SceneNode*); | 125 | const SceneNode* gfx_get_node_sibling(const SceneNode*); |
124 | 126 | SceneNode* gfx_get_node_sibling_mut(SceneNode*); | |
125 | /// Get the node's immediate sibling. | ||
126 | SceneNode* gfx_get_node_sibling_mut(SceneNode*); | ||
127 | 127 | ||
128 | /// Get the node's (local) transform. | 128 | /// Get the node's (local) transform. |
129 | mat4 gfx_get_node_transform(const SceneNode*); | 129 | mat4 gfx_get_node_transform(const SceneNode*); |
diff --git a/gfx/src/renderer/renderer.c b/gfx/src/renderer/renderer.c index c72f719..dbfc62b 100644 --- a/gfx/src/renderer/renderer.c +++ b/gfx/src/renderer/renderer.c | |||
@@ -180,7 +180,7 @@ typedef struct RenderState { | |||
180 | const float fovy; | 180 | const float fovy; |
181 | const float aspect; | 181 | const float aspect; |
182 | Light* environment_light; | 182 | Light* environment_light; |
183 | Anima* anima; | 183 | const Anima* anima; |
184 | size_t num_joints; | 184 | size_t num_joints; |
185 | mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; | 185 | mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; |
186 | } RenderState; | 186 | } RenderState; |
@@ -373,10 +373,10 @@ static void update_rec(SceneNode* node, const SceneCamera* camera, R t) { | |||
373 | // TODO: Models do not need to be animated if they are not visible to the | 373 | // TODO: Models do not need to be animated if they are not visible to the |
374 | // camera. | 374 | // camera. |
375 | if (node_type == AnimaNode) { | 375 | if (node_type == AnimaNode) { |
376 | Anima* anima = gfx_get_node_anima(node); | 376 | Anima* anima = gfx_get_node_anima_mut(node); |
377 | gfx_update_animation(anima, (R)t); | 377 | gfx_update_animation(anima, (R)t); |
378 | } else if (node_type == ModelNode) { | 378 | } else if (node_type == ModelNode) { |
379 | Model* model = gfx_get_node_model(node); | 379 | Model* model = gfx_get_node_model_mut(node); |
380 | SceneNode* root = gfx_get_model_root_mut(model); | 380 | SceneNode* root = gfx_get_model_root_mut(model); |
381 | update_rec(root, camera, t); | 381 | update_rec(root, camera, t); |
382 | } | 382 | } |
diff --git a/gfx/src/scene/model.c b/gfx/src/scene/model.c index 507c478..cc41a9a 100644 --- a/gfx/src/scene/model.c +++ b/gfx/src/scene/model.c | |||
@@ -29,7 +29,7 @@ Anima* gfx_get_model_anima(Model* model) { | |||
29 | 29 | ||
30 | SceneNode* root = mem_get_node(model->root); | 30 | SceneNode* root = mem_get_node(model->root); |
31 | if (gfx_get_node_type(root) == AnimaNode) { | 31 | if (gfx_get_node_type(root) == AnimaNode) { |
32 | return gfx_get_node_anima(root); | 32 | return gfx_get_node_anima_mut(root); |
33 | } else { | 33 | } else { |
34 | return 0; | 34 | return 0; |
35 | } | 35 | } |
diff --git a/gfx/src/scene/node.c b/gfx/src/scene/node.c index 05f6428..67ce93c 100644 --- a/gfx/src/scene/node.c +++ b/gfx/src/scene/node.c | |||
@@ -209,23 +209,43 @@ NodeType gfx_get_node_type(const SceneNode* node) { | |||
209 | return mem_get_##field(node->field); \ | 209 | return mem_get_##field(node->field); \ |
210 | } | 210 | } |
211 | 211 | ||
212 | Anima* gfx_get_node_anima(const SceneNode* node) { | 212 | const Anima* gfx_get_node_anima(const SceneNode* node) { |
213 | NODE_GET(node, anima, AnimaNode); | 213 | NODE_GET(node, anima, AnimaNode); |
214 | } | 214 | } |
215 | 215 | ||
216 | SceneCamera* gfx_get_node_camera(const SceneNode* node) { | 216 | Anima* gfx_get_node_anima_mut(SceneNode* node) { |
217 | NODE_GET(node, anima, AnimaNode); | ||
218 | } | ||
219 | |||
220 | const SceneCamera* gfx_get_node_camera(const SceneNode* node) { | ||
221 | NODE_GET(node, camera, CameraNode); | ||
222 | } | ||
223 | |||
224 | SceneCamera* gfx_get_node_camera_mut(SceneNode* node) { | ||
217 | NODE_GET(node, camera, CameraNode); | 225 | NODE_GET(node, camera, CameraNode); |
218 | } | 226 | } |
219 | 227 | ||
220 | Light* gfx_get_node_light(const SceneNode* node) { | 228 | const Light* gfx_get_node_light(const SceneNode* node) { |
221 | NODE_GET(node, light, LightNode); | 229 | NODE_GET(node, light, LightNode); |
222 | } | 230 | } |
223 | 231 | ||
224 | Model* gfx_get_node_model(const SceneNode* node) { | 232 | Light* gfx_get_node_light_mut(SceneNode* node) { |
233 | NODE_GET(node, light, LightNode); | ||
234 | } | ||
235 | |||
236 | const Model* gfx_get_node_model(const SceneNode* node) { | ||
225 | NODE_GET(node, model, ModelNode); | 237 | NODE_GET(node, model, ModelNode); |
226 | } | 238 | } |
227 | 239 | ||
228 | SceneObject* gfx_get_node_object(const SceneNode* node) { | 240 | Model* gfx_get_node_model_mut(SceneNode* node) { |
241 | NODE_GET(node, model, ModelNode); | ||
242 | } | ||
243 | |||
244 | const SceneObject* gfx_get_node_object(const SceneNode* node) { | ||
245 | NODE_GET(node, object, ObjectNode); | ||
246 | } | ||
247 | |||
248 | SceneObject* gfx_get_node_object_mut(SceneNode* node) { | ||
229 | NODE_GET(node, object, ObjectNode); | 249 | NODE_GET(node, object, ObjectNode); |
230 | } | 250 | } |
231 | 251 | ||
@@ -234,6 +254,11 @@ const SceneNode* gfx_get_node_parent(const SceneNode* node) { | |||
234 | return mem_get_node(node->parent); | 254 | return mem_get_node(node->parent); |
235 | } | 255 | } |
236 | 256 | ||
257 | SceneNode* gfx_get_node_parent_mut(SceneNode* node) { | ||
258 | assert(node); | ||
259 | return mem_get_node(node->parent); | ||
260 | } | ||
261 | |||
237 | const SceneNode* gfx_get_node_child(const SceneNode* node) { | 262 | const SceneNode* gfx_get_node_child(const SceneNode* node) { |
238 | assert(node); | 263 | assert(node); |
239 | if (node->child.val) { | 264 | if (node->child.val) { |