64 asc_scene_node_destroy_func destroy_func; |
64 asc_scene_node_destroy_func destroy_func; |
65 asc_scene_node_update_func update_func; |
65 asc_scene_node_update_func update_func; |
66 asc_scene_node_draw_func draw_func; |
66 asc_scene_node_draw_func draw_func; |
67 asc_transform transform; |
67 asc_transform transform; |
68 asc_transform world_transform; |
68 asc_transform world_transform; |
|
69 asc_vec3f position; |
|
70 asc_vec3f scale; |
|
71 asc_vec3f origin; |
|
72 asc_transform rotation; |
69 enum AscRenderGroup render_group; |
73 enum AscRenderGroup render_group; |
70 /** |
74 /** |
71 * Custom flags for this node. |
75 * Custom flags for this node. |
72 * The #ASC_SCENE_NODE_FLAGS_MASK bits are reserved for general flags. |
76 * The #ASC_SCENE_NODE_FLAGS_MASK bits are reserved for general flags. |
73 */ |
77 */ |
119 * with the leaf nodes and terminating with \p node. |
124 * with the leaf nodes and terminating with \p node. |
120 * |
125 * |
121 * @param node the node to unlink |
126 * @param node the node to unlink |
122 */ |
127 */ |
123 void asc_scene_node_free(AscSceneNode *node); |
128 void asc_scene_node_free(AscSceneNode *node); |
|
129 |
|
130 /** |
|
131 * Calculates the transformation matrix from components. |
|
132 * |
|
133 * Used internally, usually you never need to call this. |
|
134 * Use asc_node_update_transform() to trigger a recalculation. |
|
135 * |
|
136 * @param node the node |
|
137 * @see asc_node_update_transform() |
|
138 */ |
|
139 void asc_scene_node_calculate_transform(AscSceneNode *node); |
124 |
140 |
125 /** |
141 /** |
126 * Sets the name of a node. |
142 * Sets the name of a node. |
127 * |
143 * |
128 * @param node the node |
144 * @param node the node |
170 * This is the z-position a simple 2D element should have to allow |
186 * This is the z-position a simple 2D element should have to allow |
171 * stacking 2D elements with depth-test. |
187 * stacking 2D elements with depth-test. |
172 */ |
188 */ |
173 #define ASC_SCENE_2D_DEPTH_OFFSET 0.0078125f |
189 #define ASC_SCENE_2D_DEPTH_OFFSET 0.0078125f |
174 |
190 |
175 /** |
191 static inline void asc_node_set_position(AscSceneNode *node, asc_vec3f position) { |
176 * Applies an affine transformation to a scene node. |
192 node->position = position; |
177 * |
193 asc_node_update_transform(node); |
178 * @param node the node to modify |
194 } |
179 * @param matrix the matrix to multiply with the current transformation matrix |
195 |
180 */ |
196 static inline void asc_node_set_scale(AscSceneNode *node, asc_vec3f scale) { |
181 ASC_TRANFORM_FUNC void asc_node_transform_apply(AscSceneNode *node, const asc_transform matrix) { |
197 node->scale = scale; |
182 asc_mat4f_mul(node->transform, node->transform, matrix); |
198 asc_node_update_transform(node); |
183 asc_node_update_transform(node); |
199 } |
184 } |
200 |
185 |
201 static inline void asc_node_set_origin(AscSceneNode *node, asc_vec3f origin) { |
186 /** |
202 node->origin = origin; |
187 * Overwrites the current local transformation matrix. |
203 asc_node_update_transform(node); |
188 * |
204 } |
189 * @param node the node to modify |
205 |
190 * @param matrix the matrix to set as the new local transformation matrix |
206 static inline void asc_node_set_position2f(AscSceneNode *node, asc_vec2f position) { |
191 */ |
207 node->position.x = position.x; |
192 ASC_TRANFORM_FUNC void asc_node_transform_set(AscSceneNode *node, const asc_transform matrix) { |
208 node->position.y = position.y; |
193 asc_transform_copy(node->transform, matrix); |
209 asc_node_update_transform(node); |
194 asc_node_update_transform(node); |
210 } |
195 } |
211 |
196 |
212 static inline void asc_node_set_scale2f(AscSceneNode *node, asc_vec2f scale) { |
197 /** |
213 node->scale.width = scale.width; |
198 * Resets the node to use an identity transformation matrix. |
214 node->scale.height = scale.height; |
199 * |
215 asc_node_update_transform(node); |
200 * This is, for example, useful when you want to recalculate a chain of transformations from scratch. |
216 } |
201 * |
217 |
202 * @param node the node for which to reset the local transformation |
218 static inline void asc_node_set_origin2f(AscSceneNode *node, asc_vec2f origin) { |
203 */ |
219 node->origin.x = origin.x; |
204 ASC_TRANFORM_FUNC void asc_node_transform_reset(AscSceneNode *node) { |
220 node->origin.y = origin.y; |
205 asc_transform_identity(node->transform); |
221 asc_node_update_transform(node); |
206 asc_node_update_transform(node); |
222 } |
207 } |
223 |
208 |
224 static inline void asc_node_set_rotation(AscSceneNode *node, asc_transform rotation) { |
|
225 memcpy(node->rotation, rotation, ASC_TRANSFORM_SIZE); |
|
226 asc_node_update_transform(node); |
|
227 } |
|
228 |
|
229 static inline void asc_node_roll_deg(AscSceneNode *node, float angle) { |
|
230 asc_transform r, d; |
|
231 asc_transform_roll(r, asc_rad(angle)); |
|
232 asc_transform_apply(d, r, node->rotation); |
|
233 asc_transform_copy(node->rotation, d); |
|
234 asc_node_update_transform(node); |
|
235 } |
209 |
236 |
210 #endif |
237 #endif |