Improve SoccerAi front point handling

This commit is contained in:
Benau 2016-09-27 16:24:38 +08:00
parent e26920e479
commit ff52d91372
5 changed files with 15 additions and 46 deletions

View File

@ -279,35 +279,3 @@ void AIBaseController::crashed(const Material *m)
}
} // crashed(Material)
//-----------------------------------------------------------------------------
void AIBaseController::checkPosition(const Vec3 &point, posData *pos_data,
Vec3 *lc, bool use_front_xyz) const
{
// Convert to local coordinates from the point of view of current kart
btTransform t;
t.setBasis(m_kart->getTrans().getBasis());
t.setOrigin(use_front_xyz ? m_kart->getFrontXYZ() : m_kart->getXYZ());
Vec3 local_coordinates = t.inverse()(point);
// Save local coordinates for later use if needed
if (lc) *lc = local_coordinates;
if (pos_data == NULL) return;
// lhs: tell whether it's left or right hand side
if (local_coordinates.getX() < 0)
pos_data->lhs = true;
else
pos_data->lhs = false;
// behind: tell whether it's behind or not
if (local_coordinates.getZ() < 0)
pos_data->behind = true;
else
pos_data->behind = false;
pos_data->angle = atan2f(fabsf(local_coordinates.getX()),
fabsf(local_coordinates.getZ()));
pos_data->distance = local_coordinates.length();
} // checkPosition

View File

@ -64,9 +64,6 @@ protected:
* for AI testing only. */
static int m_test_ai;
/** Position info structure of targets. */
struct posData {bool behind; bool lhs; float angle; float distance;};
void setControllerName(const std::string &name);
float steerToPoint(const Vec3 &point);
float normalizeAngle(float angle);
@ -77,9 +74,6 @@ protected:
/** This can be called to detect if the kart is stuck (i.e. repeatedly
* hitting part of the track). */
bool isStuck() const { return m_stuck; }
void checkPosition(const Vec3&, posData*,
Vec3* lc = NULL,
bool use_front_xyz = false) const;
public:
AIBaseController(AbstractKart *kart);

View File

@ -97,6 +97,9 @@ void SoccerAI::reset()
m_force_brake = false;
m_chasing_ball = false;
m_front_transform.setOrigin(m_kart->getFrontXYZ());
m_front_transform.setBasis(m_kart->getTrans().getBasis());
} // reset
//-----------------------------------------------------------------------------
@ -110,6 +113,8 @@ void SoccerAI::update(float dt)
#endif
m_force_brake = false;
m_chasing_ball = false;
m_front_transform.setOrigin(m_kart->getFrontXYZ());
m_front_transform.setBasis(m_kart->getTrans().getBasis());
if (m_world->getPhase() == World::GOAL_PHASE)
{
@ -209,10 +214,8 @@ Vec3 SoccerAI::determineBallAimingPosition()
const Vec3& ball_aim_pos = m_world->getBallAimPosition(m_opp_team);
const Vec3& orig_pos = m_world->getBallPosition();
Vec3 ball_lc;
Vec3 aim_lc;
checkPosition(orig_pos, NULL, &ball_lc, true/*use_front_xyz*/);
checkPosition(ball_aim_pos, NULL, &aim_lc, true/*use_front_xyz*/);
Vec3 ball_lc = m_front_transform.inverse()(orig_pos);
Vec3 aim_lc = m_front_transform.inverse()(ball_aim_pos);
// Too far from the ball,
// use path finding from arena ai to get close
@ -230,7 +233,7 @@ Vec3 SoccerAI::determineBallAimingPosition()
return ball_aim_pos;
}
else
return m_kart->getTrans()(Vec3(overtake_lc));
return m_front_transform(overtake_lc);
}
else
{

View File

@ -21,6 +21,8 @@
#include "karts/controller/arena_ai.hpp"
#include "LinearMath/btTransform.h"
#undef BALL_AIM_DEBUG
#ifdef BALL_AIM_DEBUG
#include "graphics/irr_driver.hpp"
@ -53,6 +55,8 @@ private:
bool m_force_brake;
bool m_chasing_ball;
btTransform m_front_transform;
Vec3 determineBallAimingPosition();
bool isOvertakable(const Vec3& ball_lc);
bool determineOvertakePosition(const Vec3& ball_lc, const Vec3& aim_lc,

View File

@ -1210,6 +1210,9 @@ void Kart::update(float dt)
// Update the position and other data taken from the physics
Moveable::update(dt);
Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);
if(!history->replayHistory())
m_controller->update(dt);
@ -1333,9 +1336,6 @@ void Kart::update(float dt)
m_body->getBroadphaseHandle()->m_collisionFilterGroup = 0;
}
Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);
// After the physics step was done, the position of the wheels (as stored
// in wheelInfo) is actually outdated, since the chassis was moved
// according to the force acting from the wheels. So the center of the