本文整理汇总了C++中Bone::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ Bone::addChild方法的具体用法?C++ Bone::addChild怎么用?C++ Bone::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bone
的用法示例。
在下文中一共展示了Bone::addChild方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addBone
int Skeleton::addBone(int i,Bone* parent)
{
// Check that this line in the file describes a joint.
if (items[i]!="JOINT") DIE("Bad file format");
// Make a new bone
Bone* newBone = new Bone(items[i+1].c_str(),numberOfBones);
numberOfBones++;
// Add it to its parent
parent->addChild(newBone);
// Skip three entries
i+=3;
if (items[i]!="OFFSET")DIE("Bad file format");
newBone->offset = glm::vec3(atof(items[i+1].c_str()),atof(items[i+3].c_str()),atof(items[i+2].c_str()));
newBone->origTotOffset= parent->origTotOffset+ newBone->offset;
newBone->origOffset = newBone->offset;
i+=4;
// Check that this specifies the channels and get the number of them
if (items[i]!="CHANNELS") DIE("Bad file format");
int nc = atoi(items[i+1].c_str());
i+=2;
// Now for each channel, check its type and put the relevant pointer in the correct place.
for (int k = 0;k<nc;k++)
{
if (items[i+k]=="Xposition")
placesForAnimation.push_back(&(newBone->offset.x));
else if (items[i+k]=="Yposition")
placesForAnimation.push_back(&(newBone->offset.z));
else if (items[i+k]=="Zposition")
placesForAnimation.push_back(&(newBone->offset.y));
else if (items[i+k]=="Zrotation")
placesForAnimation.push_back(&(newBone->yRot));
else if (items[i+k]=="Yrotation")
placesForAnimation.push_back(&(newBone->zRot));
else if (items[i+k]=="Xrotation")
placesForAnimation.push_back(&(newBone->xRot));
else
placesForAnimation.push_back(&dummy);
}
i+=nc;
while (1)
{
if (items[i]=="End")
{
Bone* nnb = new Bone("end",numberOfBones);numberOfBones++;
newBone->addChild(nnb);
nnb->offset= glm::vec3(atof(items[i+4].c_str()),atof(items[i+6].c_str()),atof(items[i+5].c_str()));
i+=8;
}
if (items[i]=="JOINT")
i = addBone(i,newBone);
else
return i+1;
}
return i;
}
示例2: loadSkeleton
void Mesh::loadSkeleton(std::string filename) {
std::istream *file = getFile(filename, _lab);
int numBones = readInt(*file);
string boneName;
string parentName;
Bone *bone;
Bone *parent;
float angle = 0.0f;
// Bones are listed in the same order as in the meshb.
Vector3d *vec = 0;
for(int i = 0;i < numBones; i++) {
boneName = readCString(*file,32);
parentName = readCString(*file,32);
bone = _boneMap[boneName];
/* for (int j = 0; j < _numBones; j++) {
if (_bones[j].getName() == boneName) {
bone = _bones + j;
break;
}
}*/
if (parentName != "no_parent") {
/* for (int j = 0; j < _numBones; j++) {
if (_bones[j].getName() == parentName) {
parent = _bones + j;
break;
}
}*/
parent = _boneMap[parentName];
assert(parent != 0);
assert(bone != 0);
if (!parent->hasChild(bone))
parent->addChild(bone);
}
bone->setPos(readVector3d(*file));
bone->setRot(readVector3d(*file));
bone->setAngle(readFloat(*file));
}
}
示例3: createHierarchy
//-------------------------------------------------------------------
void XMLSkeletonSerializer::createHierarchy(Skeleton* skel, TiXmlElement* mHierNode) {
LogManager::getSingleton().logMessage("XMLSkeletonSerializer: Reading Hierarchy data...");
Bone* bone;
Bone* parent;
String boneName;
String parentName;
for (TiXmlElement* hierElem = mHierNode->FirstChildElement(); hierElem != 0; hierElem = hierElem->NextSiblingElement())
{
boneName = hierElem->Attribute("bone");
parentName = hierElem->Attribute("parent");
bone = skel->getBone(boneName);
parent = skel->getBone(parentName);
parent->addChild(bone);
//LogManager::getSingleton().logMessage("XMLSkeletonSerialiser: lien: " + parent->getName() + "->" + bone->getName());
}
}
示例4: addChild
void Armature::addChild(DBObject* object, std::string parentName){
if(!object)
{
return;
}
if(parentName != "")
{
Bone* boneParent = getBone(parentName);
if (boneParent)
{
boneParent->addChild(object);
}
}
else
{
if(object->parent)
{
object->parent->removeChild(object);
}
object->setArmature(this);
}
}
示例5: Bone
Person::Person() : Bone(getRoot())
{
ColouredSurface* red = new ColouredSurface(1, 0, 0);
ColouredSurface* green = new ColouredSurface(0, 1, 0);
ColouredSurface* blue = new ColouredSurface(0, 0, 1);
Shape* pelvis = new Cylinder(0.08, 0.15, Point(0.3, 0, 0));
pelvis->setSurface(blue);
Bone* bPelvis = new Bone(pelvis);
pelvis->setRotation(90, 0, 0);
this->addChild("Pelvis", bPelvis);
Shape* chest = new Cylinder(0.08, 0.1, Point(0, 0.125, 0));
chest->setSurface(green);
Bone* bChest = new Bone(chest);
chest->setRotation(90, 0, 0);
Shape* head = new Sphere(0.08, Point(0, 0.13, 0));
TexturedSurface* headTex = new TexturedSurface("./face.jpg");
head->setTexture(headTex);
Bone* bHead = new Bone(head);
head->setRotation(90, 0, 0);
Shape* upperLeftArm = new Cylinder(0.02, 0.08, Point(-0.1, 0, 0));
upperLeftArm->setSurface(red);
upperLeftArm->setRotation(90, 0, 0);
Bone* ula = new Bone(upperLeftArm);
ula->setJointOffset(0, -0.04, 0);
Shape* upperLeftArmJoint = new Sphere(0.04, Point(-0.1, 0, 0));
upperLeftArmJoint->setSurface(blue);
upperLeftArmJoint->setRotation(90, 0, 0);
Bone* ulaj = new Bone(upperLeftArmJoint);
Shape* lowerLeftArm = new Cylinder(0.02, 0.08, Point(0, -0.08, 0));
lowerLeftArm->setSurface(green);
lowerLeftArm->setRotation(90, 0, 0);
Bone* lla = new Bone(lowerLeftArm);
lla->setJointOffset(0, -0.04, 0);
Shape* lowerLeftArmJoint = new Sphere(0.03, Point(0, -0.08, 0));
lowerLeftArmJoint->setSurface(blue);
lowerLeftArmJoint->setRotation(90, 0, 0);
Bone* llaj = new Bone(lowerLeftArmJoint);
Shape* upperRightArm = new Cylinder(0.02, 0.08, Point(0.1, 0, 0));
upperRightArm->setSurface(red);
upperRightArm->setRotation(90, 0, 0);
Bone* ura = new Bone(upperRightArm);
ura->setJointOffset(0, -0.04, 0);
Shape* upperRightArmJoint = new Sphere(0.04, Point(0.1, 0, 0));
upperRightArmJoint->setSurface(blue);
upperRightArmJoint->setRotation(90, 0, 0);
Bone* uraj = new Bone(upperRightArmJoint);
Shape* lowerRightArm = new Cylinder(0.02, 0.08, Point(0, -0.08, 0));
lowerRightArm->setSurface(green);
lowerRightArm->setRotation(90, 0, 0);
Bone* lra = new Bone(lowerRightArm);
lra->setJointOffset(0, -0.04, 0);
Shape* lowerRightArmJoint = new Sphere(0.03, Point(0, -0.08, 0));
lowerRightArmJoint->setSurface(blue);
lowerRightArmJoint->setRotation(90, 0, 0);
Bone* lraj = new Bone(lowerRightArmJoint);
Shape* upperLeftLeg = new Cylinder(0.03, 0.09, Point(-0.04, -0.07, 0));
upperLeftLeg->setSurface(red);
upperLeftLeg->setRotation(90, 0, 0);
Bone* ull = new Bone(upperLeftLeg);
ull->setJointOffset(0, -0.04, 0);
Shape* lowerLeftLeg = new Cylinder(0.03, 0.09, Point(0, -0.1, 0));
lowerLeftLeg->setSurface(blue);
lowerLeftLeg->setRotation(90, 0, 0);
Bone* lll = new Bone(lowerLeftLeg);
lll->setJointOffset(0, -0.02, 0);
Shape* lowerLeftLegJoint = new Sphere(0.03, Point(0, -0.1, 0));
lowerLeftLegJoint->setSurface(green);
Bone* lllj = new Bone(lowerLeftLegJoint);
Shape* upperRightLeg = new Cylinder(0.03, 0.09, Point(0.04, -0.07, 0));
upperRightLeg->setSurface(red);
upperRightLeg->setRotation(90, 0, 0);
Bone* url = new Bone(upperRightLeg);
url->setJointOffset(0, -0.04, 0);
Shape* lowerRightLeg = new Cylinder(0.03, 0.09, Point(0, -0.1, 0));
lowerRightLeg->setSurface(blue);
lowerRightLeg->setRotation(90, 0, 0);
Bone* lrl = new Bone(lowerRightLeg);
lrl->setJointOffset(0, -0.02, 0);
Shape* lowerRightLegJoint = new Sphere(0.03, Point(0, -0.1, 0));
lowerRightLegJoint->setSurface(green);
Bone* lrlj = new Bone(lowerRightLegJoint);
//.........这里部分代码省略.........
示例6: loadSkeleton
void Skeleton::loadSkeleton(const String& fileName) {
OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb");
if(!inFile) {
return;
}
bonesEntity = new Entity();
bonesEntity->visible = false;
addChild(bonesEntity);
unsigned int numBones;
float t[3],rq[4],s[3];
OSBasics::read(&numBones, sizeof(unsigned int), 1, inFile);
unsigned int namelen;
char buffer[1024];
Matrix4 mat;
unsigned int hasParent, boneID;
for(int i=0; i < numBones; i++) {
OSBasics::read(&namelen, sizeof(unsigned int), 1, inFile);
memset(buffer, 0, 1024);
OSBasics::read(buffer, 1, namelen, inFile);
Bone *newBone = new Bone(String(buffer));
OSBasics::read(&hasParent, sizeof(unsigned int), 1, inFile);
if(hasParent == 1) {
OSBasics::read(&boneID, sizeof(unsigned int), 1, inFile);
newBone->parentBoneId = boneID;
} else {
newBone->parentBoneId = -1;
}
OSBasics::read(t, sizeof(float), 3, inFile);
OSBasics::read(s, sizeof(float), 3, inFile);
OSBasics::read(rq, sizeof(float), 4, inFile);
bones.push_back(newBone);
Quaternion bq;
bq.set(rq[0], rq[1], rq[2], rq[3]);
newBone->baseRotation = bq;
newBone->baseScale = Vector3(s[0], s[1], s[2]);
newBone->basePosition = Vector3(t[0], t[1], t[2]);
newBone->setPosition(t[0], t[1], t[2]);
newBone->setRotationQuat(rq[0], rq[1], rq[2], rq[3]);
newBone->setScale(s[0], s[1], s[2]);
newBone->rebuildTransformMatrix();
newBone->setBaseMatrix(newBone->getTransformMatrix());
newBone->setBoneMatrix(newBone->getTransformMatrix());
OSBasics::read(t, sizeof(float), 3, inFile);
OSBasics::read(s, sizeof(float), 3, inFile);
OSBasics::read(rq, sizeof(float), 4, inFile);
Quaternion q;
q.set(rq[0], rq[1], rq[2], rq[3]);
Matrix4 m = q.createMatrix();
m.setPosition(t[0], t[1], t[2]);
newBone->setRestMatrix(m);
}
Bone *parentBone;
for(int i=0; i < bones.size(); i++) {
if(bones[i]->parentBoneId != -1) {
parentBone = bones[bones[i]->parentBoneId];
parentBone->addChildBone(bones[i]);
bones[i]->setParentBone(parentBone);
parentBone->addChild(bones[i]);
} else {
bonesEntity->addChild(bones[i]);
}
}
OSBasics::close(inFile);
}
示例7: _mergeSkeletonAnimations
void Skeleton::_mergeSkeletonAnimations(const Skeleton* src,
const BoneHandleMap& boneHandleMap,
const StringVector& animations)
{
ushort handle;
ushort numSrcBones = src->getNumBones();
ushort numDstBones = this->getNumBones();
if (boneHandleMap.size() != numSrcBones)
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Number of bones in the bone handle map must equal to "
"number of bones in the source skeleton.",
"Skeleton::_mergeSkeletonAnimations");
}
bool existsMissingBone = false;
// Check source skeleton structures compatible with ourself (that means
// identically bones with identical handles, and with same hierarchy, but
// not necessary to have same number of bones and bone names).
for (handle = 0; handle < numSrcBones; ++handle)
{
const Bone* srcBone = src->getBone(handle);
ushort dstHandle = boneHandleMap[handle];
// Does it exists in target skeleton?
if (dstHandle < numDstBones)
{
Bone* destBone = this->getBone(dstHandle);
// Check both bones have identical parent, or both are root bone.
const Bone* srcParent = static_cast<Bone*>(srcBone->getParent());
Bone* destParent = static_cast<Bone*>(destBone->getParent());
if ((srcParent || destParent) &&
(!srcParent || !destParent ||
boneHandleMap[srcParent->getHandle()] != destParent->getHandle()))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Source skeleton incompatible with this skeleton: "
"difference hierarchy between bone '" + srcBone->getName() +
"' and '" + destBone->getName() + "'.",
"Skeleton::_mergeSkeletonAnimations");
}
}
else
{
existsMissingBone = true;
}
}
// Clone bones if need
if (existsMissingBone)
{
// Create missing bones
for (handle = 0; handle < numSrcBones; ++handle)
{
const Bone* srcBone = src->getBone(handle);
ushort dstHandle = boneHandleMap[handle];
// The bone is missing in target skeleton?
if (dstHandle >= numDstBones)
{
Bone* dstBone = this->createBone(srcBone->getName(), dstHandle);
// Sets initial transform
dstBone->setPosition(srcBone->getInitialPosition());
dstBone->setOrientation(srcBone->getInitialOrientation());
dstBone->setScale(srcBone->getInitialScale());
dstBone->setInitialState();
}
}
// Link new bones to parent
for (handle = 0; handle < numSrcBones; ++handle)
{
const Bone* srcBone = src->getBone(handle);
ushort dstHandle = boneHandleMap[handle];
// Is new bone?
if (dstHandle >= numDstBones)
{
const Bone* srcParent = static_cast<Bone*>(srcBone->getParent());
if (srcParent)
{
Bone* destParent = this->getBone(boneHandleMap[srcParent->getHandle()]);
Bone* dstBone = this->getBone(dstHandle);
destParent->addChild(dstBone);
}
}
}
// Derive root bones in case it was changed
this->deriveRootBone();
// Reset binding pose for new bones
this->reset(true);
this->setBindingPose();
}
//.........这里部分代码省略.........
示例8: buildArmature
//.........这里部分代码省略.........
{
skinDataCopy = armatureDataCopy->getSkinData("");
}
}
if(animationArmatureData)
{
armature->getAnimation()->setAnimationDataList(animationArmatureData->animationDataList);
}
else
{
armature->getAnimation()->setAnimationDataList(armatureData->animationDataList);
}
SkinData* skinData = armatureData->getSkinData(skinName);
if(!skinData)
{
return nullptr;
//throw new ArgumentError();
}
Slot* slot;
DisplayData* displayData;
Armature* childArmature;
size_t i;
//var helpArray:Array = [];
for(size_t j = 0 ; j < skinData->slotDataList.size() ; j ++)
{
SlotData* slotData = skinData->slotDataList[j];
bone = armature->getBone(slotData->parent);
if(!bone)
{
continue;
}
slot = generateSlot();
slot->name = slotData->name;
slot->setBlendMode(slotData->blendMode);
slot->_originZOrder = slotData->zOrder;
slot->_dislayDataList = slotData->displayDataList;
std::vector<Object*> helpArray;
i = slotData->displayDataList.size();
helpArray.resize(i);
while(i --)
{
displayData = slotData->displayDataList[i];
if(displayData->type == DisplayData::ARMATURE)
{
DisplayData* displayDataCopy = 0;
if(skinDataCopy)
{
SlotData* slotDataCopy = skinDataCopy->getSlotData(slotData->name);
if(slotDataCopy)
{
displayDataCopy = slotDataCopy->displayDataList[i];
}
}
else
{
displayDataCopy = 0;
}
childArmature = buildArmature(displayData->name, displayDataCopy?displayDataCopy->name:"", _currentDataName, _currentTextureAtlasName);
if(childArmature)
{
helpArray[i] = childArmature;
}
//fix by Wayne Dimart:
// break; we don't use break here, or will crach the program due to incomplete helpArray.
continue;
}
else
{
helpArray[i] = generateDisplay(getTextureAtlas(_currentTextureAtlasName), displayData->name, displayData->pivot.x, displayData->pivot.y);
}
}
slot->setDisplayList(helpArray);
slot->changeDisplay(0);
bone->addChild(slot);
}
//
i = armature->_boneList.size();
while(i --)
{
armature->_boneList[i]->update();
}
i = armature->_slotList.size();
while(i --)
{
slot = armature->_slotList[i];
slot->update();
}
armature->updateSlotsZOrder();
return armature;
}
示例9: buildSlots
void BaseFactory::buildSlots(Armature *armature, const ArmatureData *armatureData, const SkinData *skinData, const SkinData *skinDataCopy) const
{
for (size_t i = 0, l = skinData->slotDataList.size(); i < l; ++i)
{
SlotData *slotData = skinData->slotDataList[i];
Bone *bone = armature->getBone(slotData->parent);
if (!bone)
{
continue;
}
Slot *slot = generateSlot(slotData);
slot->name = slotData->name;
slot->_originZOrder = slotData->zOrder;
slot->_slotData = slotData;
std::vector<std::pair<void*, DisplayType>> displayList;
void *frameDisplay = nullptr;
for (size_t j = 0, l = slotData->displayDataList.size(); j < l; ++j)
{
const DisplayData *displayData = slotData->displayDataList[j];
switch (displayData->type)
{
case DisplayType::DT_ARMATURE:
{
DisplayData *displayDataCopy = nullptr;
if (skinDataCopy)
{
const SlotData *slotDataCopy = skinDataCopy->getSlotData(slotData->name);
if (slotDataCopy)
{
displayDataCopy = slotDataCopy->displayDataList[i];
}
}
std::string currentDragonBonesDataName = _currentDragonBonesDataName;
std::string currentTextureAtlasName = _currentTextureAtlasName;
Armature *childArmature = buildArmature(displayData->name, "", displayDataCopy ? displayDataCopy->name : "", currentDragonBonesDataName, currentTextureAtlasName);
displayList.push_back(std::make_pair(childArmature, DisplayType::DT_ARMATURE));
_currentDragonBonesDataName = currentDragonBonesDataName;
_currentTextureAtlasName = currentTextureAtlasName;
break;
}
case DisplayType::DT_IMAGE:
{
void *display = getTextureDisplay(displayData->name, _currentTextureAtlasName, displayData);
displayList.push_back(std::make_pair(display, DisplayType::DT_IMAGE));
break;
}
case DisplayType::DT_FRAME:
{
//j
//frameDisplay = ;
break;
}
default:
break;
}
}
bone->addChild(slot);
if (!displayList.empty())
{
slot->setDisplayList(displayList, false);
}
}
}