diff options
Diffstat (limited to 'scene/resources/capsule_shape.cpp')
-rw-r--r-- | scene/resources/capsule_shape.cpp | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/scene/resources/capsule_shape.cpp b/scene/resources/capsule_shape.cpp index bd30f009c4..1aa3fee0ca 100644 --- a/scene/resources/capsule_shape.cpp +++ b/scene/resources/capsule_shape.cpp @@ -29,43 +29,39 @@ #include "capsule_shape.h" #include "servers/physics_server.h" - Vector<Vector3> CapsuleShape::_gen_debug_mesh_lines() { - float radius = get_radius(); float height = get_height(); - Vector<Vector3> points; - Vector3 d(0,0,height*0.5); - for(int i=0;i<360;i++) { + Vector3 d(0, 0, height * 0.5); + for (int i = 0; i < 360; i++) { - float ra=Math::deg2rad((float)i); - float rb=Math::deg2rad((float)i+1); - Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*radius; - Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*radius; + float ra = Math::deg2rad((float)i); + float rb = Math::deg2rad((float)i + 1); + Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; + Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius; - points.push_back(Vector3(a.x,a.y,0)+d); - points.push_back(Vector3(b.x,b.y,0)+d); + points.push_back(Vector3(a.x, a.y, 0) + d); + points.push_back(Vector3(b.x, b.y, 0) + d); - points.push_back(Vector3(a.x,a.y,0)-d); - points.push_back(Vector3(b.x,b.y,0)-d); + points.push_back(Vector3(a.x, a.y, 0) - d); + points.push_back(Vector3(b.x, b.y, 0) - d); - if (i%90==0) { + if (i % 90 == 0) { - points.push_back(Vector3(a.x,a.y,0)+d); - points.push_back(Vector3(a.x,a.y,0)-d); + points.push_back(Vector3(a.x, a.y, 0) + d); + points.push_back(Vector3(a.x, a.y, 0) - d); } - Vector3 dud = i<180?d:-d; - - points.push_back(Vector3(0,a.y,a.x)+dud); - points.push_back(Vector3(0,b.y,b.x)+dud); - points.push_back(Vector3(a.y,0,a.x)+dud); - points.push_back(Vector3(b.y,0,b.x)+dud); + Vector3 dud = i < 180 ? d : -d; + points.push_back(Vector3(0, a.y, a.x) + dud); + points.push_back(Vector3(0, b.y, b.x) + dud); + points.push_back(Vector3(a.y, 0, a.x) + dud); + points.push_back(Vector3(b.y, 0, b.x) + dud); } return points; @@ -74,14 +70,14 @@ Vector<Vector3> CapsuleShape::_gen_debug_mesh_lines() { void CapsuleShape::_update_shape() { Dictionary d; - d["radius"]=radius; - d["height"]=height; - PhysicsServer::get_singleton()->shape_set_data(get_shape(),d); + d["radius"] = radius; + d["height"] = height; + PhysicsServer::get_singleton()->shape_set_data(get_shape(), d); } void CapsuleShape::set_radius(float p_radius) { - radius=p_radius; + radius = p_radius; _update_shape(); notify_change_to_owners(); _change_notify("radius"); @@ -94,7 +90,7 @@ float CapsuleShape::get_radius() const { void CapsuleShape::set_height(float p_height) { - height=p_height; + height = p_height; _update_shape(); notify_change_to_owners(); _change_notify("height"); @@ -107,19 +103,19 @@ float CapsuleShape::get_height() const { void CapsuleShape::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius","radius"),&CapsuleShape::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"),&CapsuleShape::get_radius); - ClassDB::bind_method(D_METHOD("set_height","height"),&CapsuleShape::set_height); - ClassDB::bind_method(D_METHOD("get_height"),&CapsuleShape::get_height); - - ADD_PROPERTY( PropertyInfo(Variant::REAL,"radius",PROPERTY_HINT_RANGE,"0.01,4096,0.01"), "set_radius","get_radius") ; - ADD_PROPERTY( PropertyInfo(Variant::REAL,"height",PROPERTY_HINT_RANGE,"0.01,4096,0.01"), "set_height","get_height") ; + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleShape::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleShape::get_radius); + ClassDB::bind_method(D_METHOD("set_height", "height"), &CapsuleShape::set_height); + ClassDB::bind_method(D_METHOD("get_height"), &CapsuleShape::get_height); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "height", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_height", "get_height"); } -CapsuleShape::CapsuleShape() : Shape( PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CAPSULE)) { +CapsuleShape::CapsuleShape() + : Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CAPSULE)) { - radius=1.0; - height=1.0; + radius = 1.0; + height = 1.0; _update_shape(); } |