From 3898678e76f20bfc1ed64a82c1952111c0502335 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 21 Feb 2017 13:36:00 +0800 Subject: [PATCH] Use raycasted position for point 2 Fix #2796, #2774 --- src/karts/controller/skidding_ai.cpp | 16 +++++++++------- src/karts/controller/test_ai.cpp | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 092e3393f..c3ee4fafa 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -40,6 +40,7 @@ #include "karts/skidding.hpp" #include "modes/linear_world.hpp" #include "modes/profile_world.hpp" +#include "physics/triangle_mesh.hpp" #include "race/race_manager.hpp" #include "tracks/drive_graph.hpp" #include "tracks/track.hpp" @@ -911,8 +912,15 @@ bool SkiddingAI::steerToAvoid(const std::vector &items_to_avoid, const Vec3& left = items_to_avoid[index_left_most]->getXYZ(); int node_index = items_to_avoid[index_left_most]->getGraphNode(); const Vec3& normal = DriveGraph::get()->getNode(node_index)->getNormal(); + Vec3 hit; + Vec3 hit_nor(0, 1, 0); + const Material* m; + m_track->getPtrTriangleMesh()->castRay( + Vec3(line_to_target.getMiddle()) + normal, + Vec3(line_to_target.getMiddle()) + normal * -10000, &hit, &m, + &hit_nor); Vec3 p1 = line_to_target.start, - p2 = line_to_target.getMiddle() + normal.toIrrVector(), + p2 = line_to_target.getMiddle() + hit_nor.toIrrVector(), p3 = line_to_target.end; int item_index = -1; @@ -929,12 +937,6 @@ bool SkiddingAI::steerToAvoid(const std::vector &items_to_avoid, else { const Vec3& right = items_to_avoid[index_right_most]->getXYZ(); - int node_index = items_to_avoid[index_right_most]->getGraphNode(); - const Vec3& normal = DriveGraph::get()->getNode(node_index)->getNormal(); - Vec3 p1 = line_to_target.start, - p2 = line_to_target.getMiddle() + normal.toIrrVector(), - p3 = line_to_target.end; - if (right.sideofPlane(p1, p2, p3) >= 0) { // Right of rightmost point diff --git a/src/karts/controller/test_ai.cpp b/src/karts/controller/test_ai.cpp index 915b18772..95313d8a8 100644 --- a/src/karts/controller/test_ai.cpp +++ b/src/karts/controller/test_ai.cpp @@ -40,6 +40,7 @@ #include "karts/skidding.hpp" #include "modes/linear_world.hpp" #include "modes/profile_world.hpp" +#include "physics/triangle_mesh.hpp" #include "race/race_manager.hpp" #include "tracks/drive_graph.hpp" #include "tracks/track.hpp" @@ -917,8 +918,15 @@ bool SkiddingAI::steerToAvoid(const std::vector &items_to_avoid, const Vec3& left = items_to_avoid[index_left_most]->getXYZ(); int node_index = items_to_avoid[index_left_most]->getGraphNode(); const Vec3& normal = DriveGraph::get()->getNode(node_index)->getNormal(); + Vec3 hit; + Vec3 hit_nor(0, 1, 0); + const Material* m; + m_track->getPtrTriangleMesh()->castRay( + Vec3(line_to_target.getMiddle()) + normal, + Vec3(line_to_target.getMiddle()) + normal * -10000, &hit, &m, + &hit_nor); Vec3 p1 = line_to_target.start, - p2 = line_to_target.getMiddle() + normal.toIrrVector(), + p2 = line_to_target.getMiddle() + hit_nor.toIrrVector(), p3 = line_to_target.end; int item_index = -1; @@ -935,12 +943,6 @@ bool SkiddingAI::steerToAvoid(const std::vector &items_to_avoid, else { const Vec3& right = items_to_avoid[index_right_most]->getXYZ(); - int node_index = items_to_avoid[index_right_most]->getGraphNode(); - const Vec3& normal = DriveGraph::get()->getNode(node_index)->getNormal(); - Vec3 p1 = line_to_target.start, - p2 = line_to_target.getMiddle() + normal.toIrrVector(), - p3 = line_to_target.end; - if (right.sideofPlane(p1, p2, p3) >= 0) { // Right of rightmost point