Example #1
0
Collision::OBB Collision::getOBB(const sf::Sprite& object){
	//Gets the oriented bounding box of object, which is the local bounds of the object rotated
	sf::FloatRect box(object.getLocalBounds());
	maths::Vector2 topleft, botright, topright, botleft;

	float rot = object.getRotation();
	maths::Vector2 origin = object.getOrigin();
	maths::Vector2 position = object.getPosition();
	
	//Get rotated coordinates of vertices
	topleft = position + maths::Vector2(box.left, box.top).rotate(rot, origin);
	botright = position + maths::Vector2(box.left + box.width, box.top + box.height).rotate(rot, origin);
	topright = position + maths::Vector2(box.left + box.width, box.top).rotate(rot, origin);
	botleft = position + maths::Vector2(box.left, box.top + box.height).rotate(rot, origin);


	return OBB(topleft, botleft, topright, botright);
}
Example #2
0
sf::FloatRect Collision::getOriginalBoundingBox(const sf::Sprite& object){
	//Get unrotated bounding box in world coordinates
	sf::FloatRect rect = object.getLocalBounds();
	maths::Vector2 tl = object.getPosition() - object.getOrigin() + maths::Vector2(rect.left, rect.top);
	return sf::FloatRect(tl.x, tl.y, rect.width, rect.height);
}