Jump to content

Recommended Posts

  • 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...