Example #1
0
void AABB::Test()
{
	AABB aabb1(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(1.0f, 1.0f, 1.0f));
	AABB aabb2(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(2.0f, 2.0f, 2.0f));
	AABB aabb3(Vector3f(1.0f, 0.0f, 0.0f), Vector3f(2.0f, 1.0f, 1.0f));
	AABB aabb4(Vector3f(0.0f, 0.0f, -2.0f), Vector3f(1.0f, 1.0f, -1.0f));
	AABB aabb5(Vector3f(0.0f, 0.5f, 0.0f), Vector3f(1.0f, 1.5f, 1.0f));
	AABB aabb6(Vector3f(0.3f, 0.5f, 0.7f), Vector3f(1.3f, 1.5f, 1.7f));

	IntersectData aabb1Intersectaabb2 = aabb1.IntersectAABB(aabb2);
	IntersectData aabb1Intersectaabb3 = aabb1.IntersectAABB(aabb3);
	IntersectData aabb1Intersectaabb4 = aabb1.IntersectAABB(aabb4);
	IntersectData aabb1Intersectaabb5 = aabb1.IntersectAABB(aabb5);
	IntersectData aabb1Intersectaabb6 = aabb1.IntersectAABB(aabb6);

	assert(aabb1Intersectaabb2.GetDoesIntersect() == false);
	assert(aabb1Intersectaabb2.GetDistance()      == 0.0f);

	assert(aabb1Intersectaabb3.GetDoesIntersect() == false);
	assert(aabb1Intersectaabb3.GetDistance()      == 0.0f);

	assert(aabb1Intersectaabb4.GetDoesIntersect() == false);
	assert(aabb1Intersectaabb4.GetDistance()      == 1.0f);
	
	assert(aabb1Intersectaabb5.GetDoesIntersect() == true);
	assert(aabb1Intersectaabb5.GetDistance()      == -0.5f);

	assert(aabb1Intersectaabb6.GetDoesIntersect() == true);
	assert(aabb1Intersectaabb6.GetDistance()      == -0.3f);

//	std::cout << "AABB1 intersect AABB2: " << aabb1Intersectaabb2.GetDoesIntersect() 
//	          << ", Distance: "            << aabb1Intersectaabb2.GetDistance() << std::endl;
//
//	std::cout << "AABB1 intersect AABB3: " << aabb1Intersectaabb3.GetDoesIntersect() 
//	          << ", Distance: "            << aabb1Intersectaabb3.GetDistance() << std::endl;
//
//	std::cout << "AABB1 intersect AABB4: " << aabb1Intersectaabb4.GetDoesIntersect() 
//	          << ", Distance: "            << aabb1Intersectaabb4.GetDistance() << std::endl;
//
//	std::cout << "AABB1 intersect AABB5: " << aabb1Intersectaabb5.GetDoesIntersect() 
//	          << ", Distance: "            << aabb1Intersectaabb5.GetDistance() << std::endl;
//
//	std::cout << "AABB1 intersect AABB6: " << aabb1Intersectaabb6.GetDoesIntersect() 
//	          << ", Distance: "            << aabb1Intersectaabb6.GetDistance() << std::endl;
}
Example #2
0
void UT_aabb(const char* params)
{
	Lumix::AABB aabb1;
	Lumix::AABB aabb2(Lumix::Vec3(0, 0, 0), Lumix::Vec3(1, 1, 1));

	LUMIX_EXPECT(aabb2.min.x == 0);
	LUMIX_EXPECT(aabb2.min.y == 0);
	LUMIX_EXPECT(aabb2.min.z == 0);

	LUMIX_EXPECT(aabb2.max.x == 1);
	LUMIX_EXPECT(aabb2.max.y == 1);
	LUMIX_EXPECT(aabb2.max.z == 1);

	aabb1 = aabb2;
	LUMIX_EXPECT(aabb1.min.x == aabb2.min.x);
	LUMIX_EXPECT(aabb1.min.y == aabb2.min.y);
	LUMIX_EXPECT(aabb1.min.z == aabb2.min.z);

	LUMIX_EXPECT(aabb1.max.x == aabb2.max.x);
	LUMIX_EXPECT(aabb1.max.y == aabb2.max.y);
	LUMIX_EXPECT(aabb1.max.z == aabb2.max.z);

	Lumix::Vec3 points[8];
	aabb2.getCorners(Lumix::Matrix::IDENTITY, points);
	LUMIX_EXPECT(points[0].x == 0);
	LUMIX_EXPECT(points[0].y == 0);
	LUMIX_EXPECT(points[0].z == 0);

	LUMIX_EXPECT(points[1].x == 0);
	LUMIX_EXPECT(points[1].y == 0);
	LUMIX_EXPECT(points[1].z == 1);

	LUMIX_EXPECT(points[2].x == 0);
	LUMIX_EXPECT(points[2].y == 1);
	LUMIX_EXPECT(points[2].z == 0);

	LUMIX_EXPECT(points[3].x == 0);
	LUMIX_EXPECT(points[3].y == 1);
	LUMIX_EXPECT(points[3].z == 1);

	LUMIX_EXPECT(points[4].x == 1);
	LUMIX_EXPECT(points[4].y == 0);
	LUMIX_EXPECT(points[4].z == 0);

	LUMIX_EXPECT(points[5].x == 1);
	LUMIX_EXPECT(points[5].y == 0);
	LUMIX_EXPECT(points[5].z == 1);

	LUMIX_EXPECT(points[6].x == 1);
	LUMIX_EXPECT(points[6].y == 1);
	LUMIX_EXPECT(points[6].z == 0);

	LUMIX_EXPECT(points[7].x == 1);
	LUMIX_EXPECT(points[7].y == 1);
	LUMIX_EXPECT(points[7].z == 1);

	Lumix::AABB aabb3(Lumix::Vec3(0, 0, 0), Lumix::Vec3(1, 1, 1));
	Lumix::AABB aabb4(Lumix::Vec3(1, 2, 3), Lumix::Vec3(2, 3, 4));
	Lumix::Matrix mtx = Lumix::Matrix::IDENTITY;
	mtx.setTranslation(Lumix::Vec3(1, 2, 3));
	aabb3.transform(mtx);

	LUMIX_EXPECT(aabb3.min.x == aabb4.min.x);
	LUMIX_EXPECT(aabb3.min.y == aabb4.min.y);
	LUMIX_EXPECT(aabb3.min.z == aabb4.min.z);

	LUMIX_EXPECT(aabb3.max.x == aabb4.max.x);
	LUMIX_EXPECT(aabb3.max.y == aabb4.max.y);
	LUMIX_EXPECT(aabb3.max.z == aabb4.max.z);
}