예제 #1
0
bool Box3D::intersectsApprox(const Box3D& b) const
{
	Box3D temp;
	AABB3D aabb_temp, aabb_temp2;
	//make temp localized
	temp.dims = b.dims;
	toLocal(b.origin, temp.origin);
	toLocalReorient(b.xbasis, temp.xbasis);
	toLocalReorient(b.ybasis, temp.ybasis);
	toLocalReorient(b.zbasis, temp.zbasis);
	temp.getAABB(aabb_temp);
	aabb_temp2.bmin.setZero();
	aabb_temp2.bmax = dims;
	if(!aabb_temp2.intersects(aabb_temp))
		return false;

	temp.dims = dims;
	b.toLocal(origin, temp.origin);
	b.toLocalReorient(xbasis, temp.xbasis);
	b.toLocalReorient(ybasis, temp.ybasis);
	b.toLocalReorient(zbasis, temp.zbasis);
	temp.getAABB(aabb_temp);
	aabb_temp2.bmax = b.dims;
	if(!aabb_temp2.intersects(aabb_temp))
		return false;
	return true;
}
예제 #2
0
bool ClipLine(const Vector3& x, const Vector3& v, const Box3D& b, Real& u1, Real& u2)
{
	Vector3 x2, v2;
	b.toLocal(x, x2);
	//for each face, p is dot(v, normal), q is signed dist to plane (dot(v,normal)-offset)
	//normal order: (-1,0,0), (1,0,0), (0,-1,0), (0,1,0), (0,0,-1), (0,0,1)
	//offset order: 0, dims.x, 0, dims.y, 0, dims.z
	v2.x=dot(v,b.xbasis);
	if(ClipLine1D(-x2.x, -v2.x, u1,u2) && ClipLine1D(x2.x-b.dims.x, v2.x, u1,u2))	{
		v2.y=dot(v,b.ybasis);
		if(ClipLine1D(-x2.y, -v2.y, u1,u2) && ClipLine1D(x2.y-b.dims.y, v2.y, u1,u2))	{
			v2.z=dot(v,b.zbasis);
			if(ClipLine1D(-x2.z,-v2.z, u1,u2) && ClipLine1D(x2.z-b.dims.z, v2.z, u1,u2)) {
				return true;
			}
		}
	}
	return false;
}