Fixed #2742 - incorrect triggering if cannon line triggereed Caused

by not updating m_front_xyz when moving the kart (so an incorrect
position was used to detect checkline triggering).
This commit is contained in:
hiker 2017-01-20 14:13:12 +11:00
parent 4506f4baed
commit b5f285a182
9 changed files with 37 additions and 2 deletions

View File

@ -427,6 +427,14 @@ void Kart::reset()
} // reset
// -----------------------------------------------------------------------------
void Kart::setXYZ(const Vec3& a)
{
AbstractKart::setXYZ(a);
Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);
} // setXYZ
// -----------------------------------------------------------------------------
void Kart::increaseMaxSpeed(unsigned int category, float add_speed,
float engine_force, float duration,

View File

@ -286,6 +286,7 @@ public:
virtual bool playCustomSFX (unsigned int type);
virtual void setController(Controller *controller);
virtual void setXYZ(const Vec3& a);
// ========================================================================
// Powerup related functions.

View File

@ -84,7 +84,7 @@ public:
virtual void stopFlying();
/** Sets the XYZ coordinates of the moveable. */
void setXYZ(const Vec3& a)
virtual void setXYZ(const Vec3& a)
{
m_transform.setOrigin(a);
if(m_motion_state)

View File

@ -781,6 +781,7 @@ void World::moveKartTo(AbstractKart* kart, const btTransform &transform)
// Project kart to surface of track
// This will set the physics transform
Track::getCurrentTrack()->findGround(kart);
CheckManager::get()->resetAfterKartMove(kart);
} // moveKartTo

View File

@ -137,6 +137,13 @@ void CheckLine::reset(const Track &track)
}
} // reset
// ----------------------------------------------------------------------------
void CheckLine::resetAfterKartMove(unsigned int kart_index)
{
AbstractKart *kart = World::getWorld()->getKart(kart_index);
m_previous_position[kart_index] = kart->getXYZ();
} // resetAfterKartMove
// ----------------------------------------------------------------------------
void CheckLine::changeDebugColor(bool is_active)
{
@ -167,7 +174,7 @@ void CheckLine::changeDebugColor(bool is_active)
* additional data.
*/
bool CheckLine::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
unsigned int kart_index)
unsigned int kart_index)
{
World* w = World::getWorld();
core::vector2df p=new_pos.toIrrVector2d();

View File

@ -77,6 +77,7 @@ public:
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
unsigned int indx);
virtual void reset(const Track &track);
virtual void resetAfterKartMove(unsigned int kart_index);
virtual void changeDebugColor(bool is_active);
/** Returns the actual line data for this checkpoint. */
const core::line2df &getLine2D() const {return m_line;}

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include "io/xml_node.hpp"
#include "karts/abstract_kart.hpp"
#include "tracks/ambient_light_sphere.hpp"
#include "tracks/check_cannon.hpp"
#include "tracks/check_goal.hpp"
@ -117,6 +118,19 @@ void CheckManager::reset(const Track &track)
(*i)->reset(track);
} // reset
// ----------------------------------------------------------------------------
/** Called after a kart is moved (e.g. after a rescue) to reset any cached
* check information. Without this an incorrect crossing of a checkline
* could be triggered since a CheckLine stores the previous position).
* \param kart_index Index of the kart that was moved.
*/
void CheckManager::resetAfterKartMove(AbstractKart *kart)
{
std::vector<CheckStructure*>::iterator i;
for (i = m_all_checks.begin(); i != m_all_checks.end(); i++)
(*i)->resetAfterKartMove(kart->getWorldKartId());
} // resetAfterKartMove
// ----------------------------------------------------------------------------
/** Updates all animations. Called one per time step.
* \param dt Time since last call.

View File

@ -25,6 +25,7 @@
#include <string>
#include <vector>
class AbstractKart;
class CheckStructure;
class Track;
class XMLNode;
@ -48,6 +49,7 @@ public:
void load(const XMLNode &node);
void update(float dt);
void reset(const Track &track);
void resetAfterKartMove(AbstractKart *kart);
unsigned int getLapLineIndex() const;
int getChecklineTriggering(const Vec3 &from, const Vec3 &to) const;
// ------------------------------------------------------------------------

View File

@ -105,6 +105,7 @@ public:
CheckStructure(const XMLNode &node, unsigned int index);
virtual ~CheckStructure() {};
virtual void update(float dt);
virtual void resetAfterKartMove(unsigned int kart_index) {};
virtual void changeDebugColor(bool is_active) {}
/** True if going from old_pos to new_pos crosses this checkline. This function
* is called from update (of the checkline structure).