cocos2d::Vec2 SteeringBehaviors::wallAvoidance() { auto tmpMovingEntity = m_pOwner->getMovingEntity(); Vec2 tmpForce; auto tmpAllWalls = GamepMapSingleton->getWalls(); for (auto tmpIterator = tmpAllWalls.begin(); tmpIterator != tmpAllWalls.end(); tmpIterator++) { // 分别计算距离每个边的距离 auto tmpWallToOwner = tmpMovingEntity.getPosition() - tmpIterator->getPointA(); auto tmpDot = tmpWallToOwner.dot(tmpIterator->getNormal()); if (tmpDot >= tmpMovingEntity.getRadius()) { continue; } // @_@ 如果意外出去了,这里就还是相当于距离相当近 if (tmpDot <= 0) { tmpDot = 1; } tmpForce += m_wallAvoidanceMagnify * tmpIterator->getNormal() / tmpDot; } return tmpForce; }
void ShapeSegment::draw(const Graphic::Color& pColor) const { Graphic::System::get().drawLine( getPointA(), getPointB(), pColor ); }