src/scene_node.c

changeset 207
4d184a8706b1
parent 206
26726b7a89a7
child 210
3021616e5772
equal deleted inserted replaced
206:26726b7a89a7 207:4d184a8706b1
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "ascension/scene_node.h" 28 #include "ascension/scene_node.h"
29 #include "ascension/context.h" 29 #include "ascension/context.h"
30 #include "ascension/error.h"
30 31
31 #include <cx/tree.h> 32 #include <cx/tree.h>
32 #include <cx/linked_list.h> 33 #include <cx/linked_list.h>
33 #include <cx/printf.h> 34 #include <cx/printf.h>
34 35
35 #include "ascension/error.h" 36 #include <assert.h>
36 37
37 static CxTreeIterator asc_scene_node_iterator( 38 static CxTreeIterator asc_scene_node_iterator(
38 AscSceneNode *node, 39 AscSceneNode *node,
39 bool visit_on_exit 40 bool visit_on_exit
40 ) { 41 ) {
78 cx_foreach(AscSceneNode*, child, iter) { 79 cx_foreach(AscSceneNode*, child, iter) {
79 if (!iter.exiting) continue; 80 if (!iter.exiting) continue;
80 asc_scene_node_destroy(child); 81 asc_scene_node_destroy(child);
81 cxFreeDefault(child); 82 cxFreeDefault(child);
82 } 83 }
84 }
85
86 void asc_scene_node_init_(AscSceneNode *node, struct asc_scene_node_init_args args) {
87 if (args.name != NULL) {
88 asc_scene_node_name(node, args.name);
89 }
90 node->render_group = args.render_group;
91 assert(args.update_func != NULL);
92 assert(args.draw_func != NULL);
93 assert(args.destroy_func != NULL);
94 node->update_func = args.update_func;
95 node->destroy_func = args.destroy_func;
96 node->draw_func = args.draw_func;
97
98 if (args.pos2d.x != 0 || args.pos2d.y != 0) {
99 node->position = ASC_VEC3F(args.pos2d.x, args.pos2d.y, ASC_SCENE_2D_DEPTH_OFFSET);
100 } else if (args.pos3d.x != 0 || args.pos3d.y != 0 || args.pos3d.z != 0) {
101 node->position = args.pos3d;
102 }
103
104 if (args.origin2d.x != 0 || args.origin2d.y != 0) {
105 node->origin = ASC_VEC3F(args.origin2d.x, args.origin2d.y, 0.f);
106 } else if (args.origin3d.x != 0 || args.origin3d.y != 0 || args.origin3d.z != 0) {
107 node->origin = args.origin3d;
108 }
109
110 if (args.scale2d.width != 0 && args.scale2d.height != 0) {
111 node->scale = ASC_VEC3F(args.scale2d.width, args.scale2d.height, 1.f);
112 } else if (args.scale3d.x != 0 && args.scale3d.height != 0 && args.scale3d.depth != 0) {
113 node->scale = args.scale3d;
114 } else {
115 node->scale = ASC_VEC3F_1;
116 }
117
118 if (asc_memcmpz(args.rotation, ASC_TRANSFORM_SIZE)) {
119 asc_mat4f_unit(node->rotation);
120 } else {
121 asc_transform_copy(node->rotation, args.rotation);
122 }
123
124 asc_scene_node_update(node);
83 } 125 }
84 126
85 void asc_scene_node_calculate_transform(AscSceneNode *node) { 127 void asc_scene_node_calculate_transform(AscSceneNode *node) {
86 asc_transform temp, temp2; 128 asc_transform temp, temp2;
87 129

mercurial