Exemplo n.º 1
0
//------------------------------------------------------------------------------
// utils
static V3d getCentroid(const V3d& offset, const std::vector<float>& vertices)
{
    V3d posSum(0);
    for (size_t i = 0; i < vertices.size(); i+=3)
        posSum += V3d(vertices[i], vertices[i+1], vertices[i+2]);
    if (vertices.size() > 0)
        posSum = 1.0/(vertices.size()/3.0) * posSum;
    return posSum + offset;
}
Exemplo n.º 2
0
	void ConvexHull::CenterHull()
	{
		// Calculate the average of all of the vertices, and then
		// offset all of them to make this the new origin position (0,0)
		const unsigned int numVertices = m_vertices.size();

		Vec2f posSum(0.0f, 0.0f);
	
		for(unsigned int i = 0; i < numVertices; i++)
			posSum += m_vertices[i];

		Vec2f averagePos(posSum / static_cast<float>(numVertices));

		for(unsigned int i = 0; i < numVertices; i++)
			m_vertices[i] -= averagePos;
	}