| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  godot_result_callbacks.cpp                                           */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "godot_result_callbacks.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | #include "area_bullet.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | #include "bullet_types_converter.h"
 | 
					
						
							|  |  |  | #include "collision_object_bullet.h"
 | 
					
						
							|  |  |  | #include "rigid_body_bullet.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-31 09:40:50 +02:00
										 |  |  | #include <BulletCollision/CollisionDispatch/btInternalEdgeUtility.h>
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  | 	@author AndreaCatania | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-31 09:40:50 +02:00
										 |  |  | bool godotContactAddedCallback(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { | 
					
						
							|  |  |  | 	if (!colObj1Wrap->getCollisionObject()->getCollisionShape()->isCompound()) { | 
					
						
							|  |  |  | 		btAdjustInternalEdgeContacts(cp, colObj1Wrap, colObj0Wrap, partId1, index1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | bool GodotFilterCallback::needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const { | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	return (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) || (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_areas) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_bodies) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-19 13:14:12 -07:00
										 |  |  | 		if (m_pickRay && !gObj->is_ray_pickable()) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (m_exclude->has(gObj->get_self())) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (count >= m_resultMax) { | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							|  |  |  | 		if (m_exclude->has(gObj->get_self())) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (count >= m_resultMax) { | 
					
						
							| 
									
										
										
										
											2018-11-26 18:15:29 +01:00
										 |  |  | 		return 1; // not used by bullet
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-26 18:15:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 	CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(convexResult.m_hitCollisionObject->getUserPointer()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	PhysicsDirectSpaceState3D::ShapeResult &result = m_results[count]; | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:05:16 +05:30
										 |  |  | 	result.shape = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is an odd name but contains the compound shape ID
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 	result.rid = gObj->get_self(); | 
					
						
							|  |  |  | 	result.collider_id = gObj->get_instance_id(); | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	result.collider = result.collider_id.is_null() ? nullptr : ObjectDB::get_instance(result.collider_id); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	++count; | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 	return 1; // not used by bullet
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							|  |  |  | 		if (gObj == m_self_object) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2018-02-16 19:06:00 +01:00
										 |  |  | 			// A kinematic body can't be stopped by a rigid body since the mass of kinematic body is infinite
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (m_infinite_inertia && !btObj->isStaticOrKinematicObject()) { | 
					
						
							| 
									
										
										
										
											2018-02-16 19:06:00 +01:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-16 19:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (gObj->getType() == CollisionObjectBullet::TYPE_AREA) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-16 19:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object)) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_areas) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_bodies) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		if (m_exclude->has(gObj->get_self())) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | btScalar GodotClosestConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (convexResult.m_localShapeInfo) { | 
					
						
							| 
									
										
										
										
											2021-03-12 19:05:16 +05:30
										 |  |  | 		m_shapeId = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is an odd name but contains the compound shape ID
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2018-09-16 16:02:15 +02:00
										 |  |  | 		m_shapeId = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-16 16:02:15 +02:00
										 |  |  | 	return btCollisionWorld::ClosestConvexResultCallback::addSingleResult(convexResult, normalInWorldSpace); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (m_count >= m_resultMax) { | 
					
						
							| 
									
										
										
										
											2018-11-26 18:15:29 +01:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-26 18:15:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_areas) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_bodies) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		if (m_exclude->has(gObj->get_self())) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (m_count >= m_resultMax) { | 
					
						
							| 
									
										
										
										
											2017-12-23 00:04:53 +01:00
										 |  |  | 		return cp.getDistance(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-23 00:04:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 	if (cp.getDistance() <= 0) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		PhysicsDirectSpaceState3D::ShapeResult &result = m_results[m_count]; | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		// Penetrated
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		CollisionObjectBullet *colObj; | 
					
						
							|  |  |  | 		if (m_self_object == colObj0Wrap->getCollisionObject()) { | 
					
						
							|  |  |  | 			colObj = static_cast<CollisionObjectBullet *>(colObj1Wrap->getCollisionObject()->getUserPointer()); | 
					
						
							|  |  |  | 			result.shape = cp.m_index1; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			colObj = static_cast<CollisionObjectBullet *>(colObj0Wrap->getCollisionObject()->getUserPointer()); | 
					
						
							|  |  |  | 			result.shape = cp.m_index0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 11:37:36 +02:00
										 |  |  | 		result.collider_id = colObj->get_instance_id(); | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 		result.collider = result.collider_id.is_null() ? nullptr : ObjectDB::get_instance(result.collider_id); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		result.rid = colObj->get_self(); | 
					
						
							|  |  |  | 		++m_count; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 00:04:53 +01:00
										 |  |  | 	return cp.getDistance(); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (m_count >= m_resultMax) { | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_areas) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_bodies) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		if (m_exclude->has(gObj->get_self())) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | btScalar GodotContactPairContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (m_count >= m_resultMax) { | 
					
						
							| 
									
										
										
										
											2018-11-26 18:15:29 +01:00
										 |  |  | 		return 1; // not used by bullet
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (m_self_object == colObj0Wrap->getCollisionObject()) { | 
					
						
							|  |  |  | 		B_TO_G(cp.m_localPointA, m_results[m_count * 2 + 0]); // Local contact
 | 
					
						
							|  |  |  | 		B_TO_G(cp.m_localPointB, m_results[m_count * 2 + 1]); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		B_TO_G(cp.m_localPointB, m_results[m_count * 2 + 0]); // Local contact
 | 
					
						
							|  |  |  | 		B_TO_G(cp.m_localPointA, m_results[m_count * 2 + 1]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	++m_count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 	return 1; // Not used by bullet
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { | 
					
						
							| 
									
										
										
										
											2020-10-08 12:45:03 +01:00
										 |  |  | 	if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); | 
					
						
							|  |  |  | 		CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_areas) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!collide_with_bodies) { | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-21 17:37:51 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		if (m_exclude->has(gObj->get_self())) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | btScalar GodotRestInfoContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { | 
					
						
							|  |  |  | 	if (cp.getDistance() <= m_min_distance) { | 
					
						
							|  |  |  | 		m_min_distance = cp.getDistance(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		CollisionObjectBullet *colObj; | 
					
						
							|  |  |  | 		if (m_self_object == colObj0Wrap->getCollisionObject()) { | 
					
						
							|  |  |  | 			colObj = static_cast<CollisionObjectBullet *>(colObj1Wrap->getCollisionObject()->getUserPointer()); | 
					
						
							|  |  |  | 			m_result->shape = cp.m_index1; | 
					
						
							|  |  |  | 			B_TO_G(cp.getPositionWorldOnB(), m_result->point); | 
					
						
							| 
									
										
										
										
											2018-12-22 19:26:18 -07:00
										 |  |  | 			B_TO_G(cp.m_normalWorldOnB, m_result->normal); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 			m_rest_info_bt_point = cp.getPositionWorldOnB(); | 
					
						
							|  |  |  | 			m_rest_info_collision_object = colObj1Wrap->getCollisionObject(); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			colObj = static_cast<CollisionObjectBullet *>(colObj0Wrap->getCollisionObject()->getUserPointer()); | 
					
						
							|  |  |  | 			m_result->shape = cp.m_index0; | 
					
						
							|  |  |  | 			B_TO_G(cp.m_normalWorldOnB * -1, m_result->normal); | 
					
						
							|  |  |  | 			m_rest_info_bt_point = cp.getPositionWorldOnA(); | 
					
						
							|  |  |  | 			m_rest_info_collision_object = colObj0Wrap->getCollisionObject(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 11:37:36 +02:00
										 |  |  | 		m_result->collider_id = colObj->get_instance_id(); | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | 		m_result->rid = colObj->get_self(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		m_collided = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 11:55:58 +02:00
										 |  |  | 	return 1; // Not used by bullet
 | 
					
						
							| 
									
										
										
										
											2017-11-04 20:52:59 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-19 02:04:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void GodotDeepPenetrationContactResultCallback::addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorldOnB, btScalar depth) { | 
					
						
							| 
									
										
										
										
											2018-04-04 10:49:10 +02:00
										 |  |  | 	if (m_penetration_distance > depth) { // Has penetration?
 | 
					
						
							| 
									
										
										
										
											2018-02-25 21:05:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 19:20:48 +02:00
										 |  |  | 		const bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject(); | 
					
						
							| 
									
										
										
										
											2018-02-25 21:05:14 +01:00
										 |  |  | 		m_penetration_distance = depth; | 
					
						
							| 
									
										
										
										
											2018-04-04 10:49:10 +02:00
										 |  |  | 		m_other_compound_shape_index = isSwapped ? m_index0 : m_index1; | 
					
						
							|  |  |  | 		m_pointWorld = isSwapped ? (pointInWorldOnB + (normalOnBInWorld * depth)) : pointInWorldOnB; | 
					
						
							| 
									
										
										
										
											2018-08-14 19:20:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 01:48:33 +01:00
										 |  |  | 		m_pointNormalWorld = isSwapped ? normalOnBInWorld * -1 : normalOnBInWorld; | 
					
						
							| 
									
										
										
										
											2017-11-19 02:04:49 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |