If a 3D box(a bounding box) knows it's position, it's width, it's height and it's depth, what would be the most efficient(can run in real time) way of detecting if a 3D co-ordinate is inside that box?
I already have something in place to check for it but I am wondering if there is anything more efficient,

vPosition is the position of the 3D Coordinate
GetPosition( ) returns the position of the 3D box

bool CBoundingBox::IsInside( VEC vPosition )
{
	return ( ( vPosition.x > GetPosition( ).x && vPosition.x < GetPosition( ).x + m_fWidth ) ||
	( vPosition.y < GetPosition( ).y && vPosition.y > GetPosition( ).y - m_fHeight ) ||
	( vPosition.z > GetPosition( ).z && vPosition.z < GetPosition( ).z + m_fWidth ) );
}

Recommended Answers

All 3 Replies

Are the boxes rotated, will they ever rotate?

at the moment they aren't, and i don't think i will, i might just rotate the model inside the box and always keep the box the same rotation.

If the bounding box does not rotate, then I'm thinking you can
compare the distance between the box. Just like you would in a circle to
circle collision test. What do you think. I can't really test it out, but I am guessing you can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.