本文整理汇总了C++中BodyPart::getId方法的典型用法代码示例。如果您正苦于以下问题:C++ BodyPart::getId方法的具体用法?C++ BodyPart::getId怎么用?C++ BodyPart::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BodyPart
的用法示例。
在下文中一共展示了BodyPart::getId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadConnectionTransform
void Creature::loadConnectionTransform(const BodyPart& body, const Constraint& constraint, btTransform & trans) {
if (body.getId() == constraint.getIdBodyA()) {
Constraint::locateConnectionOrigin(body, constraint.getConnectionA(), trans);
} else {
assert(body.getId() == constraint.getIdBodyB());
Constraint::locateConnectionOrigin(body, constraint.getConnectionB(), trans);
}
trans = body.getRigidBody()->getCenterOfMassTransform() * trans;
}
示例2: removePart
void Body::removePart(std::string part_uuid) {
//Get shared pointer of the Part to be removed
boost::shared_ptr<Part> part = getPartByUUID(part_uuid);
//TODO: Handle removal of root BP or root Organ
if (part == nullptr || part->getId() == "ROOT" || part->getId() == "UPPER_TORSO")
{
return;
}
debug_print("Removing Part %s...\n", part->getId().c_str());
//Create a list of all parts to be removed
std::vector<string>* rem_list = new std::vector<string>();
//Add the part given to the function...
rem_list->push_back(part_uuid);
//...and everything that lies downstream of it (Organs and Bodyparts)
makeDownstreamPartList(part_uuid, rem_list);
//Remove duplicates from the list
std::sort(rem_list->begin(), rem_list->end());
rem_list->erase(std::unique(rem_list->begin(), rem_list->end()), rem_list->end());
#ifdef _DEBUG
for (auto it = rem_list->begin(); it != rem_list->end(); it++)
{
debug_print("UUID %s is Part %s \n", getPartByUUID(*it)->getUUID().c_str(), getPartByUUID(*it)->getId().c_str());
}
#endif
//Make a temporary list, in which UUIDs of empty bodyparts are stored.
// Its contents are later added to the rem_list
std::vector<string>* bp_rem = new std::vector<string>();
//Iterate over all parts to be removed...
for (auto it_rl = rem_list->begin(); it_rl != rem_list->end(); it_rl++)
{
//...if the part is an Organ, remove it from its connectors connected_organs list
if (getPartByUUID(*it_rl)->getType() == TYPE_ORGAN)
{
Organ *o = static_cast<Organ*>(getPartByUUID(*it_rl).get());
Organ *con = static_cast<Organ*>(getPartByUUID(o->getConnectorUUID()).get());
con->removeConnectedOrgan(*it_rl);
}
//..for all parts: remove from super part child list.
// If the super part is found to be empty (removeChild() returns true), add it
// to the temporary bp_rem list.
BodyPart* super = static_cast<BodyPart*>(getPartByUUID(getPartByUUID(*it_rl)->getSuperPartUUID()).get());
BodyPart* old_super;
if (super->removeChild(*it_rl))
{
debug_print("BodyPart %s is empty, add to unregister\n", super->getId().c_str());
bp_rem->push_back(super->getUUID());
bool done = false;
//For every BodyPart that is to be deleted as empty, remove it from its own
// super BodyPart and check wheter it needs to be removed as well!
while (!done)
{
old_super = super;
super = static_cast<BodyPart*>(getPartByUUID(super->getSuperPartUUID()).get());
if (super->removeChild(old_super->getUUID()))
{
debug_print("BodyPart %s is empty, add to unregister\n", super->getId().c_str());
bp_rem->push_back(super->getUUID());
}
else {
done = true;
}
}
}
}
//Merge the temporary removal list into the rem_list
rem_list->insert(rem_list->end(), bp_rem->begin(), bp_rem->end());
//Remove duplicates again
std::sort(rem_list->begin(), rem_list->end());
rem_list->erase(std::unique(rem_list->begin(), rem_list->end()), rem_list->end());
//Unregister the Parts, causing the shared pointers to destroy their references and themselves.
unregisterParts(rem_list);
//Clear the part variable. This should cause the last use of the shared pointer
// to the part to be freed, therefore destroying the part.
part.reset();
//Refresh all lists and maps
refreshLists();
#ifdef _DEBUG
printBodyMap("body_mt.gv", root.get());
#endif
debug_print("done.\n");
}
示例3: enter
string Body::enter(rapidxml::xml_node<> *node, std::map<string, string>* child_map, std::map<string, string>* organ_link_map) {
using namespace rapidxml;
int organ_count, bodyparts, it;
xml_node<> *temp;
xml_node<> **organ_node_list;
char *id = nullptr, *name = nullptr, *_name = nullptr;
float surface = 0.0f;
//Make a count of the body_part nodes in this node and parse all standard
// nodes for the bodypart of this node
temp = node->first_node();
bodyparts = 0;
while (temp != nullptr){
_name = temp->name();
if (!strcmp(_name, "body_part")) { bodyparts++; }
if (!strcmp(_name, "id")) { id = temp->value(); }
if (!strcmp(_name, "name")) { name = temp->value(); }
if (!strcmp(_name, "surface")) { surface = atof(temp->value()); }
temp = temp->next_sibling();
}
//if any of the mandatory vars for bodyparts are NULL, ERROR!
if (id == nullptr || name == nullptr){
throw new bdef_parse_error("Not all mandatory BodyPart variables defined!", node);
}
//make the bodypart, make the pointer to it shared and store it in the part_map
BodyPart* bp = new BodyPart((string)id, (string)name, surface, this);
boost::shared_ptr<BodyPart> p (bp);
part_map->insert(
std::pair<std::string, boost::shared_ptr<Part>>(
bp->getUUID(), boost::static_pointer_cast<Part>(p)));
//reset temporary variables for reuse with the organs
id = nullptr; name = nullptr;
//DEBUG: Print new BodyPart
debug_print("New BodyPart created: \n\tID: %s \n\tName: %s \n\tSurface: %f\n",
bp->getId().c_str(), bp->getName().c_str(), bp->getSurface());
//If there are no body_part nodes...
if (bodyparts == 0){
//...there must be organs instead!
// variables
Organ **organs;
xml_attribute<> *attr;
xml_node<> *tdef_node;
char *connector = nullptr;
bool symmetrical = false;
it = 0;
// temp vars for tissue definitions
char *tdef_id, *tdef_custom_id, *tdef_name;
float tdef_hit_prob;
tissue_def *tdefs = nullptr;
int tdef_count = 0, tdef_it = 0;
//Reset back to the first node in the given node
temp = node->first_node();
//scan for organ nodes in the given node
organ_count = 0;
while (temp != nullptr){
if (!strcmp(temp->name(),"organ")) { organ_count++; }
temp = temp->next_sibling();
}
//If there are no organs AND no bodyparts, ERROR!
if (organ_count == 0){
throw bdef_parse_error("No body part and no organ definition!", node);
}
//compile a list of nodes holding the organ definitions
//and parse the remaining nodes to make the bodypart
organ_node_list = new xml_node<>*[organ_count];
temp = node->first_node();
while (temp != nullptr){
_name = temp->name();
if (!strcmp(_name,"organ")) {
organ_node_list[it] = temp;
it++;
}
temp = temp->next_sibling();
}
//.........这里部分代码省略.........