Ejemplo n.º 1
0
AABB3D FormTriangle::getAABB() {
	AABB3D aabb;

	aabb._lowerBound = aabb._upperBound = _points[0];

	aabb.expand(_points[1]);
	aabb.expand(_points[2]);

	aabb.calculateHalfDims();
	aabb.calculateCenter();

	return aabb;
}
Ejemplo n.º 2
0
AABB3D AABB3D::getTransformedAABB(const Matrix4x4f &mat) const {
	AABB3D transformedAABB;

	Vec3f newCenter(mat * _center);

	transformedAABB._lowerBound = newCenter;
	transformedAABB._upperBound = newCenter;

	// Loop through all corners, transform, and compare
	for (int x = -1; x <= 1; x += 2)
	for (int y = -1; y <= 1; y += 2)
	for (int z = -1; z <= 1; z += 2) {
		Vec3f corner(x * _halfDims.x + _center.x, y * _halfDims.y + _center.y, z * _halfDims.z + _center.z);

		// Transform the corner
		corner = mat * corner;

		// Compare bounds
		if (corner.x > transformedAABB._upperBound.x)
			transformedAABB._upperBound.x = corner.x;
		if (corner.y > transformedAABB._upperBound.y)
			transformedAABB._upperBound.y = corner.y;
		if (corner.z > transformedAABB._upperBound.z)
			transformedAABB._upperBound.z = corner.z;

		if (corner.x < transformedAABB._lowerBound.x)
			transformedAABB._lowerBound.x = corner.x;
		if (corner.y < transformedAABB._lowerBound.y)
			transformedAABB._lowerBound.y = corner.y;
		if (corner.z < transformedAABB._lowerBound.z)
			transformedAABB._lowerBound.z = corner.z;
	}

	// Move from local into world space
	transformedAABB.calculateHalfDims();
	transformedAABB.calculateCenter();

	return transformedAABB;
}