Make angle computation work in 3D
This commit is contained in:
parent
3f86722181
commit
4574686c1d
@ -86,9 +86,7 @@ float AIBaseController::steerToPoint(const Vec3 &point)
|
|||||||
|
|
||||||
// First translate and rotate the point the AI is aiming
|
// First translate and rotate the point the AI is aiming
|
||||||
// at into the kart's local coordinate system.
|
// at into the kart's local coordinate system.
|
||||||
Vec3 lc;
|
Vec3 lc = m_kart->getTrans().inverse()(point);
|
||||||
btTransform trans = m_kart->getTrans().inverse();
|
|
||||||
lc = trans(point);
|
|
||||||
|
|
||||||
// The point the kart is aiming at can be reached 'incorrectly' if the
|
// The point the kart is aiming at can be reached 'incorrectly' if the
|
||||||
// point is below the y=x line: Instead of aiming at that point directly
|
// point is below the y=x line: Instead of aiming at that point directly
|
||||||
@ -287,10 +285,10 @@ void AIBaseController::checkPosition(const Vec3 &point, posData *pos_data,
|
|||||||
Vec3 *lc, bool use_front_xyz) const
|
Vec3 *lc, bool use_front_xyz) const
|
||||||
{
|
{
|
||||||
// Convert to local coordinates from the point of view of current kart
|
// Convert to local coordinates from the point of view of current kart
|
||||||
btQuaternion q(btVector3(0, 1, 0), -m_kart->getHeading());
|
btTransform t;
|
||||||
Vec3 p = point -
|
t.setBasis(m_kart->getTrans().getBasis());
|
||||||
(use_front_xyz ? m_kart->getFrontXYZ() : m_kart->getXYZ());
|
t.setOrigin(use_front_xyz ? m_kart->getFrontXYZ() : m_kart->getXYZ());
|
||||||
Vec3 local_coordinates = quatRotate(q, p);
|
Vec3 local_coordinates = t.inverse()(point);
|
||||||
|
|
||||||
// Save local coordinates for later use if needed
|
// Save local coordinates for later use if needed
|
||||||
if (lc) *lc = local_coordinates;
|
if (lc) *lc = local_coordinates;
|
||||||
@ -308,8 +306,8 @@ void AIBaseController::checkPosition(const Vec3 &point, posData *pos_data,
|
|||||||
else
|
else
|
||||||
pos_data->behind = false;
|
pos_data->behind = false;
|
||||||
|
|
||||||
pos_data->angle = atan2(fabsf(local_coordinates.getX()),
|
pos_data->angle = atan2f(fabsf(local_coordinates.getX()),
|
||||||
fabsf(local_coordinates.getZ()));
|
fabsf(local_coordinates.getZ()));
|
||||||
pos_data->distance = p.length();
|
pos_data->distance = local_coordinates.length();
|
||||||
|
|
||||||
} // checkPosition
|
} // checkPosition
|
||||||
|
@ -1330,15 +1330,19 @@ void SkiddingAI::handleItems(const float dt)
|
|||||||
bool straight_ahead = false;
|
bool straight_ahead = false;
|
||||||
if (m_kart_behind)
|
if (m_kart_behind)
|
||||||
{
|
{
|
||||||
posData behind_pos = {0};
|
Vec3 behind_lc = m_kart->getTrans().inverse()
|
||||||
checkPosition(m_kart_behind->getXYZ(), &behind_pos);
|
(m_kart_behind->getXYZ());
|
||||||
if (behind_pos.angle < 0.2f) straight_behind = true;
|
const float abs_angle =
|
||||||
|
atan2f(fabsf(behind_lc.x()), fabsf(behind_lc.z()));
|
||||||
|
if (abs_angle < 0.2f) straight_behind = true;
|
||||||
}
|
}
|
||||||
if (m_kart_ahead)
|
if (m_kart_ahead)
|
||||||
{
|
{
|
||||||
posData ahead_pos = {0};
|
Vec3 ahead_lc = m_kart->getTrans().inverse()
|
||||||
checkPosition(m_kart_ahead->getXYZ(), &ahead_pos);
|
(m_kart_ahead->getXYZ());
|
||||||
if (ahead_pos.angle < 0.2f) straight_ahead = true;
|
const float abs_angle =
|
||||||
|
atan2f(fabsf(ahead_lc.x()), fabsf(ahead_lc.z()));
|
||||||
|
if (abs_angle < 0.2f) straight_ahead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bowling balls are slower, so only fire on closer karts - but when
|
// Bowling balls are slower, so only fire on closer karts - but when
|
||||||
|
@ -1336,15 +1336,19 @@ void SkiddingAI::handleItems(const float dt)
|
|||||||
bool straight_ahead = false;
|
bool straight_ahead = false;
|
||||||
if (m_kart_behind)
|
if (m_kart_behind)
|
||||||
{
|
{
|
||||||
posData behind_pos = {0};
|
Vec3 behind_lc = m_kart->getTrans().inverse()
|
||||||
checkPosition(m_kart_behind->getXYZ(), &behind_pos);
|
(m_kart_behind->getXYZ());
|
||||||
if (behind_pos.angle < 0.2f) straight_behind = true;
|
const float abs_angle =
|
||||||
|
atan2f(fabsf(behind_lc.x()), fabsf(behind_lc.z()));
|
||||||
|
if (abs_angle < 0.2f) straight_behind = true;
|
||||||
}
|
}
|
||||||
if (m_kart_ahead)
|
if (m_kart_ahead)
|
||||||
{
|
{
|
||||||
posData ahead_pos = {0};
|
Vec3 ahead_lc = m_kart->getTrans().inverse()
|
||||||
checkPosition(m_kart_ahead->getXYZ(), &ahead_pos);
|
(m_kart_ahead->getXYZ());
|
||||||
if (ahead_pos.angle < 0.2f) straight_ahead = true;
|
const float abs_angle =
|
||||||
|
atan2f(fabsf(ahead_lc.x()), fabsf(ahead_lc.z()));
|
||||||
|
if (abs_angle < 0.2f) straight_ahead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bowling balls are slower, so only fire on closer karts - but when
|
// Bowling balls are slower, so only fire on closer karts - but when
|
||||||
|
Loading…
Reference in New Issue
Block a user