Jump to content

Unwanted Bounding Box Padding.


Go to solution Solved by Josh,

Recommended Posts

Posted

I brought this up in the discord and now I'm posting it here. It seems that models that have a collision mesh get additional padding on the 2D grid view. This can make it hard to scale certain models like pipes.

No collision box

image.png.e48261d4489875f7a3b0730b8043c01e.png

After adding a box collision shape.

image.png.2e25382f6a246afee2095fbdca1e4b26.png

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

  • 1 month later...
Posted

It appears that NewtonCollisionCalculateAABB is calculating extra padding around box colliders. Probably around all of them, judging by this code.

void dgCollisionInstance::CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const
{
	switch (m_scaleType)
	{
		case m_unit:
		{
			m_childShape->CalcAABB (matrix, p0, p1);
			p0 -= m_padding;
			p1 += m_padding;
			break;
		}

		case m_uniform:
		case m_nonUniform:
		{
			dgMatrix matrix1 (matrix);
			matrix1[0] = matrix1[0].Scale(m_scale.m_x);
			matrix1[1] = matrix1[1].Scale(m_scale.m_y);
			matrix1[2] = matrix1[2].Scale(m_scale.m_z);
			m_childShape->CalcAABB (matrix1, p0, p1);
			p0 -= m_padding;
			p1 += m_padding;
			break;
		}

		case m_global:
		default:
		{
			dgMatrix matrix1 (matrix);
			matrix1[0] = matrix1[0].Scale(m_scale.m_x);
			matrix1[1] = matrix1[1].Scale(m_scale.m_y);
			matrix1[2] = matrix1[2].Scale(m_scale.m_z);
			m_childShape->CalcAABB (m_aligmentMatrix * matrix1, p0, p1);
			p0 -= m_padding;
			p1 += m_padding;
			break;
		}
	}

	dgAssert (p0.m_w == dgFloat32 (0.0f));
	dgAssert (p1.m_w == dgFloat32 (0.0f));
}

 

Let's build cool stuff and have fun. :)

  • Solution
Posted

I just reduced the resulting AABB by the value above, and it seems to work correctly.

NewtonCollisionCalculateAABB(col, &identity.i.x, &bounds.min.x, &bounds.max.x);
const float DG_MAX_COLLISION_AABB_PADDING = dgFloat32(1.0f / 16.0f);
bounds.min += DG_MAX_COLLISION_AABB_PADDING;
bounds.max -= DG_MAX_COLLISION_AABB_PADDING;
bounds.Update();

 

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...