Browse Source

-added collision exception to 3D Physics API too

Juan Linietsky 11 years ago
parent
commit
cf04e1a827
2 changed files with 28 additions and 0 deletions
  1. 26 0
      scene/3d/physics_body.cpp
  2. 2 0
      scene/3d/physics_body.h

+ 26 - 0
scene/3d/physics_body.cpp

@@ -69,6 +69,29 @@ uint32_t PhysicsBody::get_layer_mask() const {
 	return layer_mask;
 	return layer_mask;
 }
 }
 
 
+void PhysicsBody::add_collision_exception_with(Node* p_node) {
+
+	ERR_FAIL_NULL(p_node);
+	PhysicsBody *physics_body = p_node->cast_to<PhysicsBody>();
+	if (!physics_body) {
+		ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
+	}
+	ERR_FAIL_COND(!physics_body);
+	PhysicsServer::get_singleton()->body_add_collision_exception(get_rid(),physics_body->get_rid());
+
+}
+
+void PhysicsBody::remove_collision_exception_with(Node* p_node) {
+
+	ERR_FAIL_NULL(p_node);
+	PhysicsBody *physics_body = p_node->cast_to<PhysicsBody>();
+	if (!physics_body) {
+		ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
+	}
+	ERR_FAIL_COND(!physics_body);
+	PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(),physics_body->get_rid());
+}
+
 void PhysicsBody::_bind_methods() {
 void PhysicsBody::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody::set_layer_mask);
 	ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody::set_layer_mask);
 	ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody::get_layer_mask);
 	ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody::get_layer_mask);
@@ -146,6 +169,9 @@ void StaticBody::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("set_bounce","bounce"),&StaticBody::set_bounce);
 	ObjectTypeDB::bind_method(_MD("set_bounce","bounce"),&StaticBody::set_bounce);
 	ObjectTypeDB::bind_method(_MD("get_bounce"),&StaticBody::get_bounce);
 	ObjectTypeDB::bind_method(_MD("get_bounce"),&StaticBody::get_bounce);
 
 
+	ObjectTypeDB::bind_method(_MD("add_collision_exception_with","body:PhysicsBody"),&PhysicsBody::add_collision_exception_with);
+	ObjectTypeDB::bind_method(_MD("remove_collision_exception_with","body:PhysicsBody"),&PhysicsBody::remove_collision_exception_with);
+
 	ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_friction"),_SCS("get_friction"));
 	ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_friction"),_SCS("get_friction"));
 	ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_bounce"),_SCS("get_bounce"));
 	ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_bounce"),_SCS("get_bounce"));
 
 

+ 2 - 0
scene/3d/physics_body.h

@@ -53,6 +53,8 @@ public:
 	void set_layer_mask(uint32_t p_mask);
 	void set_layer_mask(uint32_t p_mask);
 	uint32_t get_layer_mask() const;
 	uint32_t get_layer_mask() const;
 
 
+	void add_collision_exception_with(Node* p_node); //must be physicsbody
+	void remove_collision_exception_with(Node* p_node);
 
 
 	PhysicsBody();
 	PhysicsBody();