Exemplo n.º 1
0
SATProjection GetInterval(const std::vector<float2> &vertices, const float2 &axis)
{
	if(!vertices.size()) return SATProjection();

	SATProjection proj;

	proj.min = proj.max = vertices[0].dot(axis);
	for(u32 i=1;i<vertices.size();++i)
	{
		f32 d = vertices[i].dot(axis);
		proj.min = min(d, proj.min);
		proj.max = max(d, proj.max);
	}
	return proj;
};
Exemplo n.º 2
0
SATProjection getProjection(sf::Vector2f normal, Entity* const entity)
{
	double min = dotProduct(normal, entity->getVertexGlobalPosition(0));
	double max = min;

	for (int i(1); i < entity->getVertexCount(); ++i)
	{//project each vertex of the shape onto the normal
		//then calculate the maximum and minimum values in the array and return those
		//as a projection
		double dp = dotProduct(normal, entity->getVertexGlobalPosition(i));

		if (dp < min)
			min = dp;
		else if (dp > max)
			max = dp;

	}
	return(SATProjection(min, max));
}