Added Sprite::getRadius().
This commit is contained in:
parent
1dfd878a20
commit
ff65f6ceb6
3 changed files with 17 additions and 6 deletions
|
@ -109,12 +109,10 @@ World::testCollision(std::shared_ptr<Sprite> spriteA,
|
|||
}
|
||||
axis = thor::unitVector(axis);
|
||||
float centerA = thor::dotProduct(axis, spriteA->getPosition());
|
||||
float radiusA = std::static_pointer_cast<sf::CircleShape>(
|
||||
spriteA->mShape.shape)->getRadius();
|
||||
float radiusA = spriteA->getRadius();
|
||||
float movementA = thor::dotProduct(axis, spriteA->getSpeed() * (elapsed / 1000.0f));
|
||||
float centerB = thor::dotProduct(axis, spriteB->getPosition());
|
||||
float radiusB = std::static_pointer_cast<sf::CircleShape>(
|
||||
spriteB->mShape.shape)->getRadius();
|
||||
float radiusB = spriteB->getRadius();
|
||||
float movementB = thor::dotProduct(axis, spriteB->getSpeed() * (elapsed / 1000.0f));
|
||||
|
||||
// Allow movement if sprites are moving apart.
|
||||
|
@ -132,8 +130,7 @@ World::testCollision(std::shared_ptr<Sprite> spriteA,
|
|||
if (circle->mShape.type != Sprite::Shape::Type::CIRCLE) {
|
||||
std::swap(circle, rect);
|
||||
}
|
||||
float radius =
|
||||
std::static_pointer_cast<sf::CircleShape>(circle->mShape.shape)->getRadius();
|
||||
float radius = circle->getRadius();
|
||||
sf::Vector2f halfsize = rect->getSize() / 2.0f;
|
||||
sf::Vector2f circlePos = circle->getPosition();
|
||||
sf::Vector2f rectPos = rect->getPosition();
|
||||
|
|
|
@ -188,3 +188,16 @@ void
|
|||
Sprite::setPosition(const sf::Vector2f& position) {
|
||||
mShape.shape->setPosition(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radius of this sprite. Will fail if this is not a circle.
|
||||
*
|
||||
* @return The radius of this sprite.
|
||||
*/
|
||||
float
|
||||
Sprite::getRadius() const {
|
||||
std::shared_ptr<sf::CircleShape> circleShape =
|
||||
std::dynamic_pointer_cast<sf::CircleShape>(mShape.shape);
|
||||
assert(circleShape);
|
||||
return circleShape->getRadius();
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ protected:
|
|||
void setSpeed(sf::Vector2f direction, float speed);
|
||||
void setAngle(float angle);
|
||||
void setPosition(const sf::Vector2f& position);
|
||||
float getRadius() const;
|
||||
|
||||
// Private types.
|
||||
private:
|
||||
|
|
Reference in a new issue