本文整理汇总了C++中VRTransformPtr::getParent方法的典型用法代码示例。如果您正苦于以下问题:C++ VRTransformPtr::getParent方法的具体用法?C++ VRTransformPtr::getParent怎么用?C++ VRTransformPtr::getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VRTransformPtr
的用法示例。
在下文中一共展示了VRTransformPtr::getParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply
// called from VRTransform::apply_constraints
void VRConstraint::apply(VRTransformPtr obj, VRObjectPtr parent, bool force) {
if (!active || obj->getPhysics()->isPhysicalized()) return;
auto now = VRGlobals::CURRENT_FRAME;
if (apply_time_stamp == now && !force) return;
apply_time_stamp = now;
if (local) parent = obj->getParent(true);
if (auto r = Referential.lock()) parent = r;
Matrix4d J;
if (parent) J = parent->getMatrixTo(obj);
else J = obj->getWorldMatrix();
J.mult(refMatrixB);
J.multLeft(refMatrixAI);
for (int i=0; i<3; i++) { // translation
if (min[i] > max[i]) continue; // free
if (min[i] > J[3][i]) J[3][i] = min[i]; // lower bound
if (max[i] < J[3][i]) J[3][i] = max[i]; // upper bound
}
Vec3d angles = VRTransform::computeEulerAngles(J);
auto sign = [](float a) {
return a<0?-1:1;
};
// TODO: this is not correct, for example [180, 20, 180], corresponds to [0, 160, 0], and not [0, 20, 0] !!
// this tries to fix it somewhat, but its not clean!
if ( abs(angles[0]) > Pi*0.5 && abs(angles[2]) > Pi*0.5) {
angles[0] -= sign(angles[0])*Pi;
angles[2] -= sign(angles[2])*Pi;
angles[1] = Pi - angles[1];
}
Vec3d angleDiff;
for (int i=3; i<6; i++) { // rotation
if (min[i] > max[i]) continue; // free
float a = angles[i-3];
float d1 = min[i]-a; while(d1 > Pi) d1 -= 2*Pi; while(d1 < -Pi) d1 += 2*Pi;
float d2 = max[i]-a; while(d2 > Pi) d2 -= 2*Pi; while(d2 < -Pi) d2 += 2*Pi;
if (d1 > 0 && abs(d1) <= abs(d2)) angleDiff[i-3] = d1; // lower bound
if (d2 < 0 && abs(d2) <= abs(d1)) angleDiff[i-3] = d2; // upper bound
}
VRTransform::applyEulerAngles(J, angles + angleDiff);
J.multLeft(refMatrixA);
J.mult(refMatrixBI);
obj->setMatrixTo(J, parent);
}