예제 #1
0
//==============================================================================
void Sphere::setFromPointCloud(
	const void* buff, U count, PtrSize stride, PtrSize buffSize)
{
	// Calc min/max
	Vec4 min(Vec3(MAX_F32), 0.0);
	Vec4 max(Vec3(MIN_F32), 0.0);
	
	iteratePointCloud(buff, count, stride, buffSize, [&](const Vec3& pos)
	{
		for(U j = 0; j < 3; j++)
		{
			if(pos[j] > max[j])
			{
				max[j] = pos[j];
			}
			else if(pos[j] < min[j])
			{
				min[j] = pos[j];
			}
		}
	});

	m_center = (min + max) * 0.5; // average

	// max distance between center and the vec3 arr
	F32 maxDist = MIN_F32;

	iteratePointCloud(buff, count, stride, buffSize, [&](const Vec3& pos)
	{
		F32 dist = (Vec4(pos, 0.0) - m_center).getLengthSquared();
		if(dist > maxDist)
		{
			maxDist = dist;
		}
	});

	m_radius = sqrt(maxDist);
}
예제 #2
0
void Aabb::setFromPointCloud(const void* buff, U count, PtrSize stride, PtrSize buffSize)
{
	m_min = Vec4(Vec3(MAX_F32), 0.0);
	m_max = Vec4(Vec3(MIN_F32), 0.0);

	iteratePointCloud(buff, count, stride, buffSize, [&](const Vec3& pos) {
		for(U j = 0; j < 3; j++)
		{
			if(pos[j] > m_max[j])
			{
				m_max[j] = pos[j];
			}
			else if(pos[j] < m_min[j])
			{
				m_min[j] = pos[j];
			}
		}
	});
}