Replaced diameter with radius.

This commit is contained in:
Felix Ableitner 2013-03-27 16:09:01 +01:00
parent 98e2836c14
commit 7a074b7c3d
3 changed files with 7 additions and 7 deletions

View file

@ -156,12 +156,12 @@ World::astarArea(Area* start, Area* end) const {
* *
* @param start Position to start the path from. * @param start Position to start the path from.
* @param end Position to move to. * @param end Position to move to.
* @param diameter Diameter of the moving object. * @param radius Radius of the moving object.
* @return Path from end to start (path from start to end in reverse order). * @return Path from end to start (path from start to end in reverse order).
*/ */
std::vector<sf::Vector2f> std::vector<sf::Vector2f>
World::getPath(const sf::Vector2f& start, const sf::Vector2f& end, World::getPath(const sf::Vector2f& start, const sf::Vector2f& end,
float diameter) const { float radius) const {
std::vector<Portal*> portals = astarArea(getArea(start), getArea(end)); std::vector<Portal*> portals = astarArea(getArea(start), getArea(end));
std::vector<sf::Vector2f> path; std::vector<sf::Vector2f> path;
@ -176,11 +176,11 @@ World::getPath(const sf::Vector2f& start, const sf::Vector2f& end,
if (percentage < 0 || percentage > 1.0f) { if (percentage < 0 || percentage > 1.0f) {
if (thor::squaredLength(p->start - path.back()) < if (thor::squaredLength(p->start - path.back()) <
thor::squaredLength(p->end - path.back())) { thor::squaredLength(p->end - path.back())) {
thor::setLength(startToEnd, 0.5f * diameter); thor::setLength(startToEnd, radius);
point = p->start + startToEnd; point = p->start + startToEnd;
} }
else { else {
thor::setLength(startToEnd, 0.5f * diameter); thor::setLength(startToEnd, radius);
point = p->end - startToEnd; point = p->end - startToEnd;
} }
} }
@ -189,7 +189,7 @@ World::getPath(const sf::Vector2f& start, const sf::Vector2f& end,
} }
// Take two points on a line orthogonal to the portal. // Take two points on a line orthogonal to the portal.
thor::setLength(startToEnd, diameter / 2.0f); thor::setLength(startToEnd, radius);
startToEnd = thor::perpendicularVector(startToEnd); startToEnd = thor::perpendicularVector(startToEnd);
path.push_back(point + startToEnd); path.push_back(point + startToEnd);
path.push_back(point - startToEnd); path.push_back(point - startToEnd);

View file

@ -32,7 +32,7 @@ public:
void step(int elapsed); void step(int elapsed);
void generateAreas(); void generateAreas();
std::vector<sf::Vector2f> getPath(const sf::Vector2f& start, std::vector<sf::Vector2f> getPath(const sf::Vector2f& start,
const sf::Vector2f& end, float diameter) const; const sf::Vector2f& end, float radius) const;
// Private types. // Private types.
private: private:

View file

@ -127,7 +127,7 @@ Character::releaseTrigger() {
*/ */
bool bool
Character::setDestination(const sf::Vector2f& destination) { Character::setDestination(const sf::Vector2f& destination) {
mPath = mWorld.getPath(getPosition(), destination, 2 * getRadius()); mPath = mWorld.getPath(getPosition(), destination, getRadius());
if (!mPath.empty()) { if (!mPath.empty()) {
setSpeed(mPath.back() - getPosition(), mMovementSpeed); setSpeed(mPath.back() - getPosition(), mMovementSpeed);
} }