本文整理汇总了C++中Body::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::addChild方法的具体用法?C++ Body::addChild怎么用?C++ Body::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Mei
TEST(TestMeiDocument, FlattenedDocTree) {
Mei *mei = new Mei();
Music *mus = new Music();
Body *body = new Body();
Staff *staff = new Staff();
Staff *s2 = new Staff();
Note *n1 = new Note();
Note *n2 = new Note();
Note *n3 = new Note();
MeiDocument *doc = new MeiDocument();
mei->addChild(mus);
// empty since mei not added as document root yet
ASSERT_TRUE(doc->getFlattenedTree().empty());
doc->setRootElement(mei);
ASSERT_EQ(2, doc->getFlattenedTree().size());
mus->addChild(body);
body->addChild(staff);
body->addChild(s2);
staff->addChild(n1);
staff->addChild(n2);
s2->addChild(n3);
doc->lookBack(n2, "mei");
ASSERT_EQ(8, doc->getFlattenedTree().size());
staff->removeChild(n2);
ASSERT_EQ(7, doc->getFlattenedTree().size());
ASSERT_EQ(s2, doc->getFlattenedTree()[5]);
staff->removeChildrenWithName("note");
ASSERT_EQ(6, doc->getFlattenedTree().size());
body->deleteAllChildren();
ASSERT_EQ(3, doc->getFlattenedTree().size());
std::vector<MeiElement*> newChildren;
Staff *newStaff1 = new Staff();
Staff *newStaff2 = new Staff();
newChildren.push_back(newStaff1);
newChildren.push_back(newStaff2);
body->setChildren(newChildren);
ASSERT_EQ(5, doc->getFlattenedTree().size());
// check contents
MeiElement* elements[] = { mei, mus, body, newStaff1, newStaff2 };
std::vector<MeiElement*> rightOrder (elements, elements + sizeof(elements) / sizeof(MeiElement));
for (int i = 0; i < rightOrder.size(); i++) {
// check don't overshoot memory allocation
ASSERT_LT(i, doc->getFlattenedTree().size());
ASSERT_EQ(rightOrder[i], doc->getFlattenedTree()[i]);
}
}
示例2: processChild
Body* System::processChild(pugi::xml_node tmpRoot, Body* parent)
{
//Deal with the root node
xml_node tmpNode;
std::string tmpName = tmpRoot.child_value("name");
std::string tmpType = tmpRoot.child_value("type");
std::string tmpDesc = tmpRoot.child_value("desc");
int tmpRadius = atoi(tmpRoot.child_value("radius"));
std::string tmpTexture = tmpRoot.child_value("texture");
int tmpOrbitRadius = atoi(tmpRoot.child_value("orbit_radius"));
f32 tmpOrbitSpeed = atof(tmpRoot.child_value("orbit_speed"));
int tmpBrightness = atoi(tmpRoot.child_value("bright"));
core::vector3df tmpDefaultPos = parent->getPosition();
tmpDefaultPos.X += tmpOrbitRadius;
//core::vector3df(tmpOrbitRadius,0.0f,0.0f);
Body* rootBody = new Body(this->smgr,this->driver,tmpDefaultPos,tmpRadius,tmpName,tmpDesc,tmpType,tmpOrbitRadius,tmpOrbitSpeed,parent,tmpTexture,tmpBrightness);
tmpNode = tmpRoot.child("children").first_child();
bool morePlanets = true;
while(tmpNode && morePlanets){
rootBody->addChild(processChild(tmpNode,rootBody));
if(tmpNode.next_sibling()){
tmpNode = tmpNode.next_sibling();
continue;
}
else{
morePlanets=false;
}
}
return rootBody;
}