本文整理汇总了C++中BodyPart::getParentId方法的典型用法代码示例。如果您正苦于以下问题:C++ BodyPart::getParentId方法的具体用法?C++ BodyPart::getParentId怎么用?C++ BodyPart::getParentId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BodyPart
的用法示例。
在下文中一共展示了BodyPart::getParentId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showBodyDetails
void MainWindow::showBodyDetails( const Creature& creature, const BodyPart& body ) {
getUiInspector().lst_body_details->addItem(QString(
body.getName().c_str()));
getUiInspector().lst_body_details->addItem(QString(
(" Mass: " + TO_STRING(body.getMass())).c_str()));
getUiInspector().lst_body_details->addItem(QString(
(" Torque: " + TO_STRING(body.getMaxTorque())).c_str()));
getUiInspector().lst_body_details->addItem(QString(
std::string(" Size").c_str()));
getUiInspector().lst_body_details->addItem(QString(
(" [x]: " + TO_STRING(body.getSizeX())).c_str()));
getUiInspector().lst_body_details->addItem(QString(
(" [y]: " + TO_STRING(body.getSizeY())).c_str()));
getUiInspector().lst_body_details->addItem(QString(
(" [z]: " + TO_STRING(body.getSizeZ())).c_str()));
//Angles
BodyPart* parent = body.getParentId() == Creature::B_NONE
? NULL : &creature.getBodyPart(body.getParentId());
if (parent) {
getUiInspector().lst_body_details->addItem(QString(
(" Parent: " + parent->getName()).c_str()));
// getUiInspector().lst_body_details->addItem(QString(std::string(" Angles:").c_str()));
// getUiInspector().lst_body_details->addItem(QString(
// (" XY:" + TO_STRING(
// MathUtil::getAngle(MathUtil::XY,
// parent->getRigidBody()->getCenterOfMassPosition(),
// body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
// getUiInspector().lst_body_details->addItem(QString(
// (" YZ:" + TO_STRING(
// MathUtil::getAngle(MathUtil::YZ,
// parent->getRigidBody()->getCenterOfMassPosition(),
// body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
// getUiInspector().lst_body_details->addItem(QString(
// (" ZX:" + TO_STRING(
// MathUtil::getAngle(MathUtil::ZX,
// parent->getRigidBody()->getCenterOfMassPosition(),
// body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
}
}
示例2: calculateMaxTorque
void Creature::calculateMaxTorque() {
double gravity = Math::abs(BulletSimulator::getSingleton().getWorld().getGravity().y());
int terminal[getNumberOfBodyParts()];
for (int i = 0; i < getNumberOfBodyParts(); ++i) {
terminal[i] = 0;
getBodyPart(i).setMaxTorque(0.0);
}
//Determinar nodos terminales (sum == 1)
for (int i = 0; i < getNumberOfConstraints(); ++i) {
assert(getConstraint(i).getIdBodyA() < getNumberOfBodyParts() &&
getConstraint(i).getIdBodyA() >= 0);
assert(getConstraint(i).getIdBodyB() < getNumberOfBodyParts() &&
getConstraint(i).getIdBodyB() >= 0);
// if (!getBodyPart(getConstraint(i).getIdBodyA()).isRoot()) {
++terminal[getConstraint(i).getIdBodyA()];
// }
// if (!getBodyPart(getConstraint(i).getIdBodyB()).isRoot()) {
++terminal[getConstraint(i).getIdBodyB()];
// }
}
for (int e = 0; e < getNumberOfBodyParts(); ++e) {
if (terminal[e] != 1) continue;
int count = 0;
BodyPart * body = &getBodyPart(e);
std::vector<BodyPart*> extremities;
while (body != &getRoot() && count++ < getNumberOfBodyParts()) {
extremities.push_back(body);
body = &getBodyPart(body->getParentId());
}
extremities.push_back(body);
double arm_length = 0.0;
btTransform trans;
btVector3 center_of_mass;
btVector3 connection;
// A 0 B 1 C 2 Root 3
// |-----|-----|-----|-----|
for (int i = extremities.size() - 2; i >= 0; --i) {
// DEBUG(extremity[i]->getName() + " ; " + extremity[i+1]->getName());
Constraint* constraint = getConstraint(*extremities[i], *extremities[i + 1]);
assert(constraint);
center_of_mass = extremities[i]->getRigidBody()->getCenterOfMassPosition();
loadConnectionTransform(*extremities[i], *constraint, trans);
connection = btVector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
arm_length = (center_of_mass - connection).length();
// BDEBUG("arm=" + TO_STRING(arm_length));
extremities[i]->addMaxTorque(arm_length * extremities[i]->getMass() * gravity);
for (int j = i - 1; j >= 0; --j) {
constraint = getConstraint(*extremities[j], *extremities[i]);
if (!constraint) {
// DEBUG("NOT FOUND: " + extremity[i]->getName() + " ; " + extremity[i + 1]->getName());
continue;
}
// DEBUG("FOUND (" + constraint->getName() + "): " + extremity[i]->getName() + " ; " + extremity[i + 1]->getName());
assert(constraint);
center_of_mass = extremities[i]->getRigidBody()->getCenterOfMassPosition();
loadConnectionTransform(*extremities[i], *constraint, trans);
connection = btVector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
arm_length += (center_of_mass - connection).length();
center_of_mass = extremities[j]->getRigidBody()->getCenterOfMassPosition();
loadConnectionTransform(*extremities[j], *constraint, trans);
connection = btVector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
arm_length += (center_of_mass - connection).length();
extremities[i]->addMaxTorque(arm_length * extremities[j]->getMass() * gravity);
}
}
}
}