#include "bones/Skeleton.h" #include #include #include Skeleton * Skeleton_create() { Skeleton * self; self = malloc(sizeof(Skeleton)); Skeleton_init(self); return self; } void Skeleton_init(Skeleton * self) { self->numberOfBones = 0; self->bones = NULL; self->dispose = Skeleton_dispose; self->createCopy = Skeleton_createCopy; self->boneIndexForID = Skeleton_boneIndexForID; } void Skeleton_initCopy(Skeleton * self, Skeleton * original) { unsigned int boneIndex; self->numberOfBones = original->numberOfBones; self->bones = malloc(sizeof(struct Skeleton_bone) * self->numberOfBones); for (boneIndex = 0; boneIndex < self->numberOfBones; boneIndex++) { self->bones[boneIndex].boneID = original->bones[boneIndex].boneID; self->bones[boneIndex].parentIndex = original->bones[boneIndex].parentIndex; self->bones[boneIndex].position = original->bones[boneIndex].position; } } void Skeleton_dispose(void * selfPtr) { Skeleton * self = selfPtr; free(self->bones); free(self); } void * Skeleton_createCopy(void * selfPtr) { Skeleton * copy; copy = Skeleton_create(); Skeleton_initCopy(copy, selfPtr); return copy; } unsigned int Skeleton_boneIndexForID(void * selfPtr, Atom boneID) { Skeleton * self = selfPtr; unsigned int boneIndex; for (boneIndex = 0; boneIndex < self->numberOfBones; boneIndex++) { if (self->bones[boneIndex].boneID == boneID) { return boneIndex; } } return -1; }