Add skeleton struct

master
Jeremy Hu 2017-02-01 21:48:16 +09:30
parent a4569fbe1e
commit 0d7e873045
2 changed files with 90 additions and 0 deletions

68
src/skeleton.c Normal file
View File

@ -0,0 +1,68 @@
#include "skeleton.h"
#include "dmemory.h"
#include "osutil.h"
struct skeleton {
skeletonNode *root;
};
skeleton *skeletonCreate(void) {
return dcalloc(1, sizeof(skeleton));
}
void skeletonDestroy(skeleton *skl) {
dfree(skl);
}
skeletonNode *skeletonNewNode(skeleton *skl) {
unsued(skl);
return dcalloc(1, sizeof(skeletonNode));
}
void skeletonRemoveNode(skeleton *skl, skeletonNode *node) {
skeletonNode *parent = node->parent;
skeletonNode *pre = 0;
skeletonNode *loop;
skeletonNode *next;
if (parent) {
for (loop = parent->firstChild; loop; pre = loop, loop = loop->nextSib) {
if (loop == node) {
break;
}
}
if (pre) {
pre->nextSib = node->nextSib;
} else {
parent->firstChild = 0;
}
}
for (loop = node->firstChild; loop; loop = next) {
next = loop->nextSib;
skeletonRemoveNode(skl, loop);
}
if (skl->root == node) {
skl->root = 0;
}
dfree(node);
}
void skeletonConnectNodes(skeleton *skl, skeletonNode *first,
skeletonNode *second) {
if (first->firstChild) {
skeletonNode *loop;
for (loop = first->firstChild; loop->nextSib; loop = loop->nextSib) {
// void
}
loop->nextSib = second;
} else {
first->firstChild = second;
}
second->parent = first;
if (!skl->root) {
skl->root = first;
}
}
skeletonNode *skeletonGetRoot(skeleton *skl) {
return skl->root;
}

22
src/skeleton.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SKELETON_H
#define SKELETON_H
#include "3dstruct.h"
typedef struct skeleton skeleton;
typedef struct skeletonNode {
vec3 position;
float radius;
struct skeletonNode *parent;
struct skeletonNode *firstChild;
struct skeletonNode *nextSib;
} skeletonNode;
skeleton *skeletonCreate(void);
void skeletonDestroy(skeleton *skl);
skeletonNode *skeletonNewNode(skeleton *skl);
void skeletonRemoveNode(skeleton *skl, skeletonNode *node);
void skeletonConnectNodes(skeleton *skl, skeletonNode *first,
skeletonNode *second);
skeletonNode *skeletonGetRoot(skeleton *skl);
#endif