added scr_lvled, a bunch of libraries, and improved framework code
[raydungeon] / libs / goat3d / src / g3danm.c
diff --git a/libs/goat3d/src/g3danm.c b/libs/goat3d/src/g3danm.c
new file mode 100644 (file)
index 0000000..8fdc41a
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+goat3d - 3D scene, and animation file format library.
+Copyright (C) 2013-2023  John Tsiombikas <nuclear@member.fsf.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <stdlib.h>
+#include "g3danm.h"
+#include "dynarr.h"
+#include "log.h"
+
+int g3dimpl_anim_init(struct goat3d_anim *anim)
+{
+       anim->name = 0;
+       if(!(anim->tracks = dynarr_alloc(0, sizeof *anim->tracks))) {
+               goat3d_logmsg(LOG_ERROR, "g3dimpl_anim_init: failed to allocate tracks array\n");
+               return -1;
+       }
+       return 0;
+}
+
+void g3dimpl_anim_destroy(struct goat3d_anim *anim)
+{
+       int i, num;
+
+       if(!anim) return;
+
+       free(anim->name);
+       num = dynarr_size(anim->tracks);
+       for(i=0; i<num; i++) {
+               goat3d_destroy_track(anim->tracks[i]);
+       }
+       dynarr_free(anim->tracks);
+}
+
+
+const char *g3dimpl_trktypestr(enum goat3d_track_type type)
+{
+       switch(type) {
+       case GOAT3D_TRACK_VAL:
+               return "val";
+       case GOAT3D_TRACK_VEC3:
+               return "vec3";
+       case GOAT3D_TRACK_VEC4:
+               return "vec4";
+       case GOAT3D_TRACK_QUAT:
+               return "quat";
+       case GOAT3D_TRACK_POS:
+               return "pos";
+       case GOAT3D_TRACK_ROT:
+               return "rot";
+       case GOAT3D_TRACK_SCALE:
+               return "scale";
+       }
+       return 0;
+}
+