本文整理汇总了C++中ShapeSW::get_closest_point_to方法的典型用法代码示例。如果您正苦于以下问题:C++ ShapeSW::get_closest_point_to方法的具体用法?C++ ShapeSW::get_closest_point_to怎么用?C++ ShapeSW::get_closest_point_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShapeSW
的用法示例。
在下文中一共展示了ShapeSW::get_closest_point_to方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_closest_point_to_object_volume
Vector3 PhysicsDirectSpaceStateSW::get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const {
CollisionObjectSW *obj = PhysicsServerSW::singleton->area_owner.getornull(p_object);
if (!obj) {
obj = PhysicsServerSW::singleton->body_owner.getornull(p_object);
}
ERR_FAIL_COND_V(!obj, Vector3());
ERR_FAIL_COND_V(obj->get_space() != space, Vector3());
float min_distance = 1e20;
Vector3 min_point;
bool shapes_found = false;
for (int i = 0; i < obj->get_shape_count(); i++) {
if (obj->is_shape_set_as_disabled(i))
continue;
Transform shape_xform = obj->get_transform() * obj->get_shape_transform(i);
ShapeSW *shape = obj->get_shape(i);
Vector3 point = shape->get_closest_point_to(shape_xform.affine_inverse().xform(p_point));
point = shape_xform.xform(point);
float dist = point.distance_to(p_point);
if (dist < min_distance) {
min_distance = dist;
min_point = point;
}
shapes_found = true;
}
if (!shapes_found) {
return obj->get_transform().origin; //no shapes found, use distance to origin.
} else {
return min_point;
}
}