goat3d
changeset 26:1c601bf07b86
added the node API glue
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 28 Sep 2013 20:36:55 +0300 |
parents | d0260d80ae09 |
children | 4deb0b12fe14 |
files | src/goat3d.cc src/goat3d.h src/object.h |
diffstat | 3 files changed, 61 insertions(+), 26 deletions(-) [+] |
line diff
1.1 --- a/src/goat3d.cc Sat Sep 28 19:12:50 2013 +0300 1.2 +++ b/src/goat3d.cc Sat Sep 28 20:36:55 2013 +0300 1.3 @@ -487,7 +487,7 @@ 1.4 node->set_name(name); 1.5 } 1.6 1.7 -const char *goat3d_get_node_name(struct goat3d_node *node) 1.8 +const char *goat3d_get_node_name(const struct goat3d_node *node) 1.9 { 1.10 return node->get_name(); 1.11 } 1.12 @@ -497,68 +497,100 @@ 1.13 node->set_object((Object*)obj); 1.14 } 1.15 1.16 -// TODO cont. 1.17 - 1.18 -void *goat3d_get_node_object(struct goat3d_node *node) 1.19 +void *goat3d_get_node_object(const struct goat3d_node *node) 1.20 { 1.21 - return 0; 1.22 + return (void*)node->get_object(); 1.23 } 1.24 1.25 -enum goat3d_node_type goat3d_get_node_type(struct goat3d_node *node) 1.26 +enum goat3d_node_type goat3d_get_node_type(const struct goat3d_node *node) 1.27 { 1.28 - return GOAT3D_NODE_MESH; // TODO 1.29 + const Object *obj = node->get_object(); 1.30 + if(dynamic_cast<const Mesh*>(obj)) { 1.31 + return GOAT3D_NODE_MESH; 1.32 + } 1.33 + if(dynamic_cast<const Light*>(obj)) { 1.34 + return GOAT3D_NODE_LIGHT; 1.35 + } 1.36 + if(dynamic_cast<const Camera*>(obj)) { 1.37 + return GOAT3D_NODE_CAMERA; 1.38 + } 1.39 + 1.40 + return GOAT3D_NODE_NULL; 1.41 } 1.42 1.43 void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child) 1.44 { 1.45 + node->add_child(node); 1.46 } 1.47 1.48 -int goat3d_get_node_child_count(struct goat3d_node *node) 1.49 +int goat3d_get_node_child_count(const struct goat3d_node *node) 1.50 { 1.51 - return 0; 1.52 + return node->get_children_count(); 1.53 } 1.54 1.55 -struct goat3d_node *goat3d_get_node_child(struct goat3d_node *node, int idx) 1.56 +struct goat3d_node *goat3d_get_node_child(const struct goat3d_node *node, int idx) 1.57 { 1.58 - return 0; 1.59 + return (goat3d_node*)node->get_child(idx); 1.60 } 1.61 1.62 void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec) 1.63 { 1.64 + node->set_position(Vector3(x, y, z), tmsec); 1.65 } 1.66 1.67 void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec) 1.68 { 1.69 + node->set_rotation(Quaternion(qw, qx, qy, qz), tmsec); 1.70 } 1.71 1.72 void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec) 1.73 { 1.74 + node->set_scaling(Vector3(sx, sy, sz), tmsec); 1.75 } 1.76 1.77 void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz) 1.78 { 1.79 + node->set_pivot(Vector3(px, py, pz)); 1.80 } 1.81 1.82 1.83 -void goat3d_get_node_position(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec) 1.84 +void goat3d_get_node_position(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec) 1.85 { 1.86 + Vector3 pos = node->get_position(tmsec); 1.87 + *xptr = pos.x; 1.88 + *yptr = pos.y; 1.89 + *zptr = pos.z; 1.90 } 1.91 1.92 -void goat3d_get_node_rotation(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec) 1.93 +void goat3d_get_node_rotation(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec) 1.94 { 1.95 + Quaternion q = node->get_rotation(tmsec); 1.96 + *xptr = q.v.x; 1.97 + *yptr = q.v.y; 1.98 + *zptr = q.v.z; 1.99 + *wptr = q.s; 1.100 } 1.101 1.102 -void goat3d_get_node_scaling(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec) 1.103 +void goat3d_get_node_scaling(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec) 1.104 { 1.105 + Vector3 scale = node->get_scaling(tmsec); 1.106 + *xptr = scale.x; 1.107 + *yptr = scale.y; 1.108 + *zptr = scale.z; 1.109 } 1.110 1.111 -void goat3d_get_node_pivot(struct goat3d_node *node, float *xptr, float *yptr, float *zptr) 1.112 +void goat3d_get_node_pivot(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr) 1.113 { 1.114 + Vector3 pivot = node->get_pivot(); 1.115 + *xptr = pivot.x; 1.116 + *yptr = pivot.y; 1.117 + *zptr = pivot.z; 1.118 } 1.119 1.120 1.121 -void goat3d_get_node_matrix(struct goat3d_node *node, float *matrix, long tmsec) 1.122 +void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec) 1.123 { 1.124 + node->get_xform(tmsec, (Matrix4x4*)matrix); 1.125 } 1.126 1.127
2.1 --- a/src/goat3d.h Sat Sep 28 19:12:50 2013 +0300 2.2 +++ b/src/goat3d.h Sat Sep 28 20:36:55 2013 +0300 2.3 @@ -26,6 +26,7 @@ 2.4 }; 2.5 2.6 enum goat3d_node_type { 2.7 + GOAT3D_NODE_NULL, 2.8 GOAT3D_NODE_MESH, 2.9 GOAT3D_NODE_LIGHT, 2.10 GOAT3D_NODE_CAMERA 2.11 @@ -168,27 +169,27 @@ 2.12 struct goat3d_node *goat3d_create_node(void); 2.13 2.14 void goat3d_set_node_name(struct goat3d_node *node, const char *name); 2.15 -const char *goat3d_get_node_name(struct goat3d_node *node); 2.16 +const char *goat3d_get_node_name(const struct goat3d_node *node); 2.17 2.18 void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj); 2.19 -void *goat3d_get_node_object(struct goat3d_node *node); 2.20 -enum goat3d_node_type goat3d_get_node_type(struct goat3d_node *node); 2.21 +void *goat3d_get_node_object(const struct goat3d_node *node); 2.22 +enum goat3d_node_type goat3d_get_node_type(const struct goat3d_node *node); 2.23 2.24 void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child); 2.25 -int goat3d_get_node_child_count(struct goat3d_node *node); 2.26 -struct goat3d_node *goat3d_get_node_child(struct goat3d_node *node, int idx); 2.27 +int goat3d_get_node_child_count(const struct goat3d_node *node); 2.28 +struct goat3d_node *goat3d_get_node_child(const struct goat3d_node *node, int idx); 2.29 2.30 void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec); 2.31 void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec); 2.32 void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec); 2.33 void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz); 2.34 2.35 -void goat3d_get_node_position(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); 2.36 -void goat3d_get_node_rotation(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec); 2.37 -void goat3d_get_node_scaling(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); 2.38 -void goat3d_get_node_pivot(struct goat3d_node *node, float *xptr, float *yptr, float *zptr); 2.39 +void goat3d_get_node_position(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); 2.40 +void goat3d_get_node_rotation(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec); 2.41 +void goat3d_get_node_scaling(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); 2.42 +void goat3d_get_node_pivot(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr); 2.43 2.44 -void goat3d_get_node_matrix(struct goat3d_node *node, float *matrix, long tmsec); 2.45 +void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec); 2.46 2.47 #ifdef __cplusplus 2.48 }