70 lines
1.3 KiB
C++
70 lines
1.3 KiB
C++
#include <types/bone.h>
|
|
|
|
const Matrix4x4& Bone::getMatrix() {
|
|
return matrix;
|
|
}
|
|
|
|
void Bone::setMatrix(const Matrix4x4& m) {
|
|
matrix = m;
|
|
}
|
|
|
|
void Bone::appendChild(const Bone& bone) {
|
|
Bone* b = new(Bone); *b = bone;
|
|
b->parent = this;
|
|
children.push_back(b);
|
|
}
|
|
|
|
bool Bone::isRootBone() {
|
|
if (parent == nullptr)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
Bone* Bone::getFirstChild() {
|
|
if (children.empty())
|
|
return nullptr;
|
|
return children[0];
|
|
}
|
|
|
|
Bone* Bone::getChildByName(const std::string& bName) {
|
|
if (children.empty())
|
|
return nullptr;
|
|
|
|
for (auto& bone : children)
|
|
if (bone->name == bName)
|
|
return bone;
|
|
}
|
|
|
|
Bone *Bone::getChildByNameRecursive(const std::string &bName) {
|
|
if (children.empty())
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bool Bone::hasChildren() {
|
|
if (children.empty())
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
Bone* Bone::getParent() {
|
|
//If we're trying to get the parent of the root bone just return the root bone.
|
|
if (parent == nullptr)
|
|
return this;
|
|
return parent;
|
|
}
|
|
|
|
uint Bone::getDepth() {
|
|
if (isRootBone())
|
|
return 0;
|
|
|
|
Bone* b = parent;
|
|
uint depth = 1;
|
|
while (b != nullptr && !b->isRootBone()) {
|
|
b = b->getParent();
|
|
depth++;
|
|
}
|
|
return depth;
|
|
}
|
|
|