本文整理汇总了C++中Transform2D::worldToLocal方法的典型用法代码示例。如果您正苦于以下问题:C++ Transform2D::worldToLocal方法的具体用法?C++ Transform2D::worldToLocal怎么用?C++ Transform2D::worldToLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transform2D
的用法示例。
在下文中一共展示了Transform2D::worldToLocal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
bool test(const Circle& circle, const RotatedRectangle& rect) {
/*
Let E be the centre of the rectangle (i.e. the origin of its local coordinate frame).
Define the regions A-I as below, where the central region E has the dimensions of the rectangle.
A │ B │ C
──┼───┼──
D │ E │ F
──┼───┼──
G │ H │ I
Check distance to side in regions: B, D, F, and H.
Check distance to corner in regions: A, C, G, and I.
Region E is always an intersection.
Note: This diagram and the circle are symmetric, so we can use absolute values to simplify the comparisons.
i.e.
hw
B │ C
──┼── hh
E │ F
*/
Transform2D trans = rect.getTransform();
Transform2D pos = trans.worldToLocal({circle.centre(0), circle.centre(1), 0});
double hw = 0.5 * rect.getSize()(0);
double hh = 0.5 * rect.getSize()(1);
double r = circle.radius;
double x = std::abs(pos(0));
double y = std::abs(pos(1));
if (x < hw && y < hh) { // E
return true;
}
if (x < hw && y > hh) { // B
return y < hh + r;
}
if (x > hw && y < hh) { // F
return x < hw + r;
}
// if (x > hw && y > hh) { // C
arma::vec2 cornerDiff = { hw - x, hh - y };
return arma::norm(cornerDiff) < r;
// }
}