goat3d
diff src/goat3d.cc @ 47:498ca7ac7047
- placed all the implementation stuff in the g3dimpl namespace
- added animation stuff to the public API
- started writing animation saving/loading
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 28 Dec 2013 06:47:39 +0200 |
parents | 8da36540e2e9 |
children | 0be413ac2e0a fa5c52ea9d59 |
line diff
1.1 --- a/src/goat3d.cc Sun Dec 08 03:00:25 2013 +0200 1.2 +++ b/src/goat3d.cc Sat Dec 28 06:47:39 2013 +0200 1.3 @@ -12,6 +12,8 @@ 1.4 #include <malloc.h> 1.5 #endif 1.6 1.7 +using namespace g3dimpl; 1.8 + 1.9 struct goat3d { 1.10 Scene *scn; 1.11 unsigned int flags; 1.12 @@ -147,6 +149,72 @@ 1.13 return g->scn->save(io) ? 0 : -1; 1.14 } 1.15 1.16 +/* save/load animations */ 1.17 +GOAT3DAPI int goat3d_load_anim(struct goat3d *g, const char *fname) 1.18 +{ 1.19 + FILE *fp = fopen(fname, "rb"); 1.20 + if(!fp) { 1.21 + return -1; 1.22 + } 1.23 + 1.24 + int res = goat3d_load_anim_file(g, fp); 1.25 + fclose(fp); 1.26 + return res; 1.27 +} 1.28 + 1.29 +GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const struct goat3d_node *root, const char *fname) 1.30 +{ 1.31 + FILE *fp = fopen(fname, "wb"); 1.32 + if(!fp) { 1.33 + return -1; 1.34 + } 1.35 + 1.36 + int res = goat3d_save_anim_file(g, root, fp); 1.37 + fclose(fp); 1.38 + return res; 1.39 +} 1.40 + 1.41 +GOAT3DAPI int goat3d_load_anim_file(struct goat3d *g, FILE *fp) 1.42 +{ 1.43 + goat3d_io io; 1.44 + io.cls = fp; 1.45 + io.read = read_file; 1.46 + io.write = write_file; 1.47 + io.seek = seek_file; 1.48 + 1.49 + return goat3d_load_anim_io(g, &io); 1.50 +} 1.51 + 1.52 +GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, const struct goat3d_node *root, FILE *fp) 1.53 +{ 1.54 + goat3d_io io; 1.55 + io.cls = fp; 1.56 + io.read = read_file; 1.57 + io.write = write_file; 1.58 + io.seek = seek_file; 1.59 + 1.60 + return goat3d_save_anim_io(g, root, &io); 1.61 +} 1.62 + 1.63 +GOAT3DAPI int goat3d_load_anim_io(struct goat3d *g, struct goat3d_io *io) 1.64 +{ 1.65 + if(!g->scn->load_anim(io)) { 1.66 + if(!g->scn->load_anim_xml(io)) { 1.67 + return -1; 1.68 + } 1.69 + } 1.70 + return 0; 1.71 +} 1.72 + 1.73 +GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, const struct goat3d_node *root, struct goat3d_io *io) 1.74 +{ 1.75 + if(goat3d_getopt(g, GOAT3D_OPT_SAVEXML)) { 1.76 + return g->scn->save_anim_xml(root, io) ? 0 : -1; 1.77 + } 1.78 + return g->scn->save_anim(root, io) ? 0 : -1; 1.79 +} 1.80 + 1.81 + 1.82 GOAT3DAPI int goat3d_set_name(struct goat3d *g, const char *name) 1.83 { 1.84 g->scn->set_name(name); 1.85 @@ -704,6 +772,61 @@ 1.86 return (goat3d_node*)node->get_child(idx); 1.87 } 1.88 1.89 +GOAT3DAPI struct goat3d_node *goat3d_get_node_parent(const struct goat3d_node *node) 1.90 +{ 1.91 + return (goat3d_node*)node->get_parent(); 1.92 +} 1.93 + 1.94 +GOAT3DAPI void goat3d_use_anim(struct goat3d_node *node, int idx) 1.95 +{ 1.96 + node->use_animation(idx); 1.97 +} 1.98 + 1.99 +GOAT3DAPI void goat3d_use_anims(struct goat3d_node *node, int aidx, int bidx, float t) 1.100 +{ 1.101 + node->use_animation(aidx, bidx, t); 1.102 +} 1.103 + 1.104 +GOAT3DAPI void goat3d_use_anim_by_name(struct goat3d_node *node, const char *name) 1.105 +{ 1.106 + node->use_animation(name); 1.107 +} 1.108 + 1.109 +GOAT3DAPI void goat3d_use_anims_by_name(struct goat3d_node *node, const char *aname, const char *bname, float t) 1.110 +{ 1.111 + node->use_animation(aname, bname, t); 1.112 +} 1.113 + 1.114 +GOAT3DAPI int goat3d_get_active_anim(struct goat3d_node *node, int which) 1.115 +{ 1.116 + return node->get_active_animation_index(which); 1.117 +} 1.118 + 1.119 +GOAT3DAPI float goat3d_get_active_anim_mix(struct goat3d_node *node) 1.120 +{ 1.121 + return node->get_active_animation_mix(); 1.122 +} 1.123 + 1.124 +GOAT3DAPI int goat3d_get_anim_count(struct goat3d_node *node) 1.125 +{ 1.126 + return node->get_animation_count(); 1.127 +} 1.128 + 1.129 +GOAT3DAPI void goat3d_add_anim(struct goat3d_node *root) 1.130 +{ 1.131 + root->add_animation(); 1.132 +} 1.133 + 1.134 +GOAT3DAPI void goat3d_set_anim_name(struct goat3d_node *root, const char *name) 1.135 +{ 1.136 + root->set_animation_name(name); 1.137 +} 1.138 + 1.139 +GOAT3DAPI const char *goat3d_get_anim_name(struct goat3d_node *node) 1.140 +{ 1.141 + return node->get_animation_name(); 1.142 +} 1.143 + 1.144 GOAT3DAPI void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec) 1.145 { 1.146 node->set_position(Vector3(x, y, z), tmsec);