[SOLVED] BulletPlaneShape, BulletGhostNode collision issue

Hello,

while testing BulletGhostNode i faced the following issue: if there is a BulletPlaneShape in the scene, the ghost object always reports that it’s overlapping with the plane even though they are far apart. is this the default behavior?

any help is appreciated,
best regards,

Here is the code i’m using:

int main(int argc, char *argv[])
{
	// Open a new window framework and set the title
	framework.open_framework(argc, argv);
	framework.set_window_title("My Panda3D Window");

	// Open the window
	WindowFramework *window = framework.open_window();
	NodePath camera = window->get_camera_group();
	camera.set_pos(0, 40, 20);
	camera.look_at(0, 0, 0);
	Thread *current_thread = Thread::get_current_thread();

	//=============
	// bullet world
	PT(BulletWorld) world = new BulletWorld;
	world->set_gravity(LVector3f(0, 0, -9.81));

	//=============
	//plane
	PT(BulletPlaneShape) plane_shape = new BulletPlaneShape(LVector3f(0, 0, 1), 0);
	PT(BulletRigidBodyNode) plane_node = new BulletRigidBodyNode("plane1");
	plane_node->add_shape(plane_shape);
	NodePath plane_nodepath = window->get_render().attach_new_node(plane_node);
	plane_nodepath.set_pos(0, 0, -2);
	world->attach_rigid_body(plane_node);
	plane_node->set_into_collide_mask(CollideMask::all_on());

	//=============
	// bullet debug
	PT(BulletDebugNode) debug_node = new BulletDebugNode("debug");
	debug_node->set_verbose(false);
	NodePath debug_nodepath = window->get_render().attach_new_node(debug_node);
	debug_nodepath.show();
	world->set_debug_node(debug_node);

	//============
	// ghost node for collision testing
	PT(BulletBoxShape) ghost_box_shape = new BulletBoxShape(LVector3f(1, 1, 1));
	PT(BulletGhostNode) ghost_box_node = new BulletGhostNode("ghost_box");
	ghost_box_node->add_shape(ghost_box_shape);
	NodePath ghost_box_nodepath = window->get_render().attach_new_node(ghost_box_node);
	ghost_box_nodepath.set_pos(-3, 3, 10);
	ghost_box_nodepath.set_collide_mask(3);
	world->attach_ghost(ghost_box_node);

	while(framework.do_frame(current_thread))
	{
		world->do_physics(globalClock->get_dt());
		
		int n = ghost_box_node->get_num_overlapping_nodes();
		if( n > 0)
		{
			for(int z = 0; z < n; z++)
				cout << ghost_box_node->get_overlapping_node(z)->get_name() << "\n";
		}
	}

	framework.close_framework();
	return (0);
}

[size=150]after debugging bullet’s code i found the following:
the AABB for a plane is the whole world (largest possible dimensions)

aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));

aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));

to override this behavior you must override:
getAabb(trans,minAabb,maxAabb);

in the definition of btStaticPlaneShape[/size]

I think there is need for some clarification. The method BulletGhostNode::get_overlapping_node(int) directly accesses the overlapping pair cache, which holds overlapping objects. Overlapping is defined to be overlap of AABB (!!!). And the AABB of a plane is, like you found out already, infinitely large, since the plane has to be contained inside the AABB.

If you want to check for collisions with a particular object you should use the method BulletBodyNode::checkCollisionWith(PandaNode node).

Tinkering with the AABB method of Bullet itself is likely to mess up the whole broadphase collision algorithm of Bullet.
broadphase --> check for AABB overlaps
narrowphase --> check for geometry collisions