本文整理汇总了C++中CollisionObject2D::add_shape方法的典型用法代码示例。如果您正苦于以下问题:C++ CollisionObject2D::add_shape方法的具体用法?C++ CollisionObject2D::add_shape怎么用?C++ CollisionObject2D::add_shape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CollisionObject2D
的用法示例。
在下文中一共展示了CollisionObject2D::add_shape方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memnew
void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
if (unparenting || !can_update_body)
return;
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
if (polygon.size() == 0)
return;
bool solids = build_mode == BUILD_SOLIDS;
if (solids) {
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
Vector<Vector<Vector2> > decomp = _decompose_in_convex();
shape_from = co->get_shape_count();
for (int i = 0; i < decomp.size(); i++) {
Ref<ConvexPolygonShape2D> convex = memnew(ConvexPolygonShape2D);
convex->set_points(decomp[i]);
co->add_shape(convex, get_transform());
if (trigger)
co->set_shape_as_trigger(co->get_shape_count() - 1, true);
}
shape_to = co->get_shape_count() - 1;
if (shape_to < shape_from) {
shape_from = -1;
shape_to = -1;
}
} else {
Ref<ConcavePolygonShape2D> concave = memnew(ConcavePolygonShape2D);
PoolVector<Vector2> segments;
segments.resize(polygon.size() * 2);
PoolVector<Vector2>::Write w = segments.write();
for (int i = 0; i < polygon.size(); i++) {
w[(i << 1) + 0] = polygon[i];
w[(i << 1) + 1] = polygon[(i + 1) % polygon.size()];
}
w = PoolVector<Vector2>::Write();
concave->set_segments(segments);
co->add_shape(concave, get_transform());
if (trigger)
co->set_shape_as_trigger(co->get_shape_count() - 1, true);
shape_from = co->get_shape_count() - 1;
shape_to = co->get_shape_count() - 1;
}
//co->add_shape(shape,get_transform());
}
示例2: memnew
void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
if (polygon.size()==0)
return;
bool solids=build_mode==BUILD_SOLIDS;
if (solids) {
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
Vector< Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon);
for(int i=0;i<decomp.size();i++) {
Ref<ConvexPolygonShape2D> convex = memnew( ConvexPolygonShape2D );
convex->set_points(decomp[i]);
co->add_shape(convex,get_transform());
}
} else {
Ref<ConcavePolygonShape2D> concave = memnew( ConcavePolygonShape2D );
DVector<Vector2> segments;
segments.resize(polygon.size()*2);
DVector<Vector2>::Write w=segments.write();
for(int i=0;i<polygon.size();i++) {
w[(i<<1)+0]=polygon[i];
w[(i<<1)+1]=polygon[(i+1)%polygon.size()];
}
w=DVector<Vector2>::Write();
concave->set_segments(segments);
co->add_shape(concave,get_transform());
}
//co->add_shape(shape,get_transform());
}
示例3:
void CollisionShape2D::_add_to_collision_object(Object *p_obj) {
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
co->add_shape(shape,get_transform());
if (trigger)
co->set_shape_as_trigger(co->get_shape_count()-1,true);
}