btTriangleMesh debug draw

Post Reply
Kavarna
Posts: 2
Joined: Mon May 29, 2017 1:35 pm

btTriangleMesh debug draw

Post by Kavarna »

My first topic here! :D

So, I tried to create a collision shape from a btTriangleMesh then draw it's wireframe.
It's not as easy as it sounds :)
So, basically, here's what I've tried so far

Code: Select all

	auto Vertices = m_Graphics->GetTorus( )->GetVertices( ); // Took them straight from the Rendering Engine
	auto Indices = m_Graphics->GetTorus( )->GetIndices( ); // Took them straight from the Rendering Engine
	unsigned int TriangleCount = Indices.size( ) / 3;
	btTriangleMesh * TorusMesh = new btTriangleMesh( true, false );
	for ( unsigned int i = 0; i < TriangleCount; ++i ) // Create triangles in TorusMesh
	{
		TorusMesh->addTriangle( btVector3( // First Point
			Vertices[ Indices[ i * 3 ] ].Position.x,
			Vertices[ Indices[ i * 3 ] ].Position.y,
			Vertices[ Indices[ i * 3 ] ].Position.z ), btVector3( // Second Point
				Vertices[ Indices[ i * 3 + 1 ] ].Position.x,
				Vertices[ Indices[ i * 3 + 1 ] ].Position.y,
				Vertices[ Indices[ i * 3 + 1 ] ].Position.z ), btVector3( // Third Point
					Vertices[ Indices[ i * 3 + 2 ] ].Position.x,
					Vertices[ Indices[ i * 3 + 2 ] ].Position.y,
					Vertices[ Indices[ i * 3 + 2 ] ].Position.z ) );
	}
	btCollisionShape* TorusShape = new btBvhTriangleMeshShape( TorusMesh, false, true ); // Create a collision shape
This is the way I want to debug

Code: Select all

	setDebugMode( DBG_DrawWireframe );
And here is the call to the debugger

Code: Select all

	m_pWorld->debugDrawObject( btTransform::getIdentity( ), TorusShape,
			btVector3( 1, 1, 1 ) );
	// I also draw the Torus here
Am I missing something here?
How should I create a custom 3D Mesh?
Attachments
The red one is the Torus in my Rendering Engine and the white lines are drawn by Bullet
The red one is the Torus in my Rendering Engine and the white lines are drawn by Bullet
MS 2017-05-29 16-50-16-358.jpg (149.82 KiB) Viewed 3079 times
Post Reply