Page 1 of 1

Collision shapes appear to have boxes around them

Posted: Wed Jun 12, 2019 11:42 pm
by whitwhoa
Would anyone happen to know why that when I draw my collision objects I'm seeing boxes around them?

Image

The following is how I have created my collision world and added the objects to it:

Code: Select all

	bt_collision_configuration = new btDefaultCollisionConfiguration();
	bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);

	btVector3 worldAabbMin(-scene_size, -scene_size, -scene_size);
	btVector3 worldAabbMax(scene_size, scene_size, scene_size);
	bt_broadphase = new bt32BitAxisSweep3(worldAabbMin, worldAabbMax, max_objects, 0, true);

	bt_collision_world = new btCollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);
	if (debug) {
		bt_collision_world->setDebugDrawer(&collision_debug_drawer);
	}

	btCollisionObject* sphere = new btCollisionObject();
	sphere->getWorldTransform().setOrigin(btVector3((btScalar)-2, (btScalar)2, (btScalar)4));
	btSphereShape* sphere_shape = new btSphereShape(1);
	sphere->setCollisionShape(sphere_shape);
	bt_collision_world->addCollisionObject(sphere);

	btCollisionObject* box = new btCollisionObject();
	box->getWorldTransform().setOrigin(btVector3((btScalar)2, (btScalar)2, (btScalar)4));
	btBoxShape* box_shape = new btBoxShape(btVector3((btScalar)1, (btScalar)1, (btScalar)1));
	box->setCollisionShape(box_shape);
	bt_collision_world->addCollisionObject(box);
Below is my override for drawLine(). It's highly inefficient, but I plan on making it a bit more robust once I know everything is working as expected.

Code: Select all

	void CollisionDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color) {

	//std::cout << to.x() << "," << to.y() << "," << to.z() << "\n";

	unsigned int VBO2, VAO2;

	GLfloat points[6];

	points[0] = from.getX();
	points[1] = from.getY();
	points[2] = from.getZ();
	points[3] = to.getX();
	points[4] = to.getY();
	points[5] = to.getZ();

	glGenVertexArrays(1, &VAO2);
	glGenBuffers(1, &VBO2);
	glBindVertexArray(VAO2);

	glBindBuffer(GL_ARRAY_BUFFER, VBO2);
	glBufferData(GL_ARRAY_BUFFER, sizeof(points), &points, GL_STATIC_DRAW);

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)0);
	glEnableVertexAttribArray(0);

	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glDrawArrays(GL_LINES, 0, 2);

	glBindVertexArray(0);
	glDeleteBuffers(1, &VBO2);
	glDeleteVertexArrays(1, &VAO2);

}

Re: Collision shapes appear to have boxes around them

Posted: Thu Jun 13, 2019 12:02 am
by drleviathan
CollisionDebugDrawer::drawLine() takes a color argument which you appear to ignore. I would bet that if you actually use the color argument the bounding box will show up a different shade than the shapes. It probably represents the bounding box of the object in the broadphase, which I think can be enabled/disabled but must somehow be enabled for you.

Re: Collision shapes appear to have boxes around them

Posted: Thu Jun 13, 2019 1:44 pm
by whitwhoa
drleviathan wrote: Thu Jun 13, 2019 12:02 am It probably represents the bounding box of the object in the broadphase, which I think can be enabled/disabled but must somehow be enabled for you.
This pointed me in the right direction! Greatly appreciated. The issue was from my lack of implementing `setDebugMode` and `getDebugMode` specifically the following line:

Code: Select all

int CollisionDebugDrawer::getDebugMode(void) const { return 3; }
I was returning a debug mode value which (as far as I can tell) does not exist within the `DebugDrawModes` enum:

Code: Select all

	enum DebugDrawModes
	{
		DBG_NoDebug = 0,
		DBG_DrawWireframe = 1,
		DBG_DrawAabb = 2,
		DBG_DrawFeaturesText = 4,
		DBG_DrawContactPoints = 8,
		DBG_NoDeactivation = 16,
		DBG_NoHelpText = 32,
		DBG_DrawText = 64,
		DBG_ProfileTimings = 128,
		DBG_EnableSatComparison = 256,
		DBG_DisableBulletLCP = 512,
		DBG_EnableCCD = 1024,
		DBG_DrawConstraints = (1 << 11),
		DBG_DrawConstraintLimits = (1 << 12),
		DBG_FastWireframe = (1 << 13),
		DBG_DrawNormals = (1 << 14),
		DBG_DrawFrames = (1 << 15),
		DBG_MAX_DEBUG_DRAW_MODE
	};
Once I changed the value being returned from `getDebugMode` to the value of `DBG_DrawWireframe` the bounding boxes around the collision objects were no longer displayed:

Image

Re: Collision shapes appear to have boxes around them

Posted: Thu Jun 13, 2019 3:43 pm
by drleviathan
The enum values are powers of 2 and represent binary bits in a numerical value. Multiple modes can be enabled by setting more than one bit.

You were returning 3 = 1 + 2 which is both DBG_DrawWireframe and DBG_DrawAabb.

Re: Collision shapes appear to have boxes around them

Posted: Thu Jun 13, 2019 4:22 pm
by whitwhoa
drleviathan wrote: Thu Jun 13, 2019 3:43 pm The enum values are powers of 2 and represent binary bits in a numerical value. Multiple modes can be enabled by setting more than one bit.

You were returning 3 = 1 + 2 which is both DBG_DrawWireframe and DBG_DrawAabb.
:!: NOW it makes sense! I have never really had a need for bitshifting / bitwise operators in the past so I have steered clear, but I knew the functionality existed. It wasn't clear to me what was going on when I looked at the code, but now that you have explained it, yeah that makes sense. Thanks again!