1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Asset::WallCollision Asset::GetClosestWallCollision(const std::vector<const Room::Wall*>& walls) const {
typedef std::pair< sf::Vector2<CoordT>, sf::Vector2<CoordT> > Edge;
const Room::Wall* wall_hit = NULL, * landing_wall = NULL;
util::intersect_ret temp, closest;
VelocityT para_vel;
if(this->m_StandingOn) para_vel = this->m_StandingOn->get_unit_parallel_vector() * this->mVelocity.x;
else para_vel = this->mVelocity;
//if we aren't standing on anything, we just move wherever our velocity takes us
BOOST_FOREACH(const Room::Wall* wall, walls) {
if(!wall->thin) {
// test intersections of wall with player collision box
BOOST_FOREACH(const Edge& edge, this->GetCollisonBoxEdges()) {
temp = util::find_intersection(std::make_pair(wall->start, wall->start - para_vel), edge);
if(temp.has_intersect && temp.distance < closest.distance) {
std::cout<<"wall->start collision with "<<this<<" edge w/ distance of "<<temp.distance<<"\n";
closest = temp;
wall_hit = wall;
}
temp = util::find_intersection(std::make_pair(wall->end, wall->end - para_vel), edge);
if(temp.has_intersect && temp.distance < closest.distance) {
std::cout<<"wall->end collision with "<<this<<" edge w/ distance of "<<temp.distance<<"\n";
closest = temp;
wall_hit = wall;
}
}
}
}
BOOST_FOREACH(const Edge& edge, this->GetCollisonBoxEdges()) {
//test intersections of player collision box with walls
BOOST_FOREACH(const Room::Wall* wall, walls) {
if(!wall->thin) {
temp = util::find_intersection(std::make_pair(edge.first, edge.first + para_vel), std::make_pair(wall->start, wall->end));
if(temp.has_intersect && temp.distance < closest.distance) {
std::cout<<this<<"'s top center pt collision with wall w/ distance of "<<temp.distance<<"\n";
closest = temp;
wall_hit = wall;
landing_wall = NULL;
}
}
if(!wall->thin || para_vel.y > 0) {
temp = util::find_intersection(std::make_pair(edge.second, edge.second + para_vel), std::make_pair(wall->start, wall->end));
if(temp.has_intersect && temp.distance < closest.distance) {
std::cout<<this<<"'s bot center pt collision with wall w/ distance of "<<temp.distance<<"\n";
closest = temp;
//since this is a bottom (standing part), remember to set that we are LANDING on this wall, not just hitting it!
wall_hit = landing_wall = wall;
}
}
}
}
return WallCollision(wall_hit, landing_wall, closest);
}
|