added backwards aiming for plunger

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2790 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2008-12-26 21:11:08 +00:00
parent fe49e9f8cf
commit 943fa76519
3 changed files with 12 additions and 8 deletions

View File

@ -141,7 +141,7 @@ Flyable::~Flyable()
//-----------------------------------------------------------------------------
void Flyable::getClosestKart(const Kart **minKart, float *minDistSquared,
btVector3 *minDelta, const Kart* inFrontOf) const
btVector3 *minDelta, const Kart* inFrontOf, const bool backwards) const
{
btTransform tProjectile = (inFrontOf != NULL ? inFrontOf->getTrans() : getTrans());
@ -170,7 +170,7 @@ void Flyable::getClosestKart(const Kart **minKart, float *minDistSquared,
trans.getBasis()[1][1],
trans.getBasis()[2][1]);
float angle = to_target.angle(direction);
const float angle = to_target.angle( backwards ? -direction : direction );
if(fabsf(angle) > 1) continue;
}

View File

@ -82,7 +82,8 @@ protected:
Useful e.g. for throwing projectiles in front only.
*/
void getClosestKart(const Kart **minKart, float *minDistSquared,
btVector3 *minDelta, const Kart* inFrontOf=NULL) const;
btVector3 *minDelta, const Kart* inFrontOf=NULL,
const bool backwards=false) const;
/** init bullet for moving objects like projectiles */
void createPhysics(float y_offset,
const btVector3 velocity,

View File

@ -39,7 +39,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
// find closest kart in front of the current one
const Kart *closest_kart=0; btVector3 direction; float kartDistSquared;
getClosestKart(&closest_kart, &kartDistSquared, &direction, kart /* search in front of this kart */);
getClosestKart(&closest_kart, &kartDistSquared, &direction, kart /* search in front of this kart */, m_reverse_mode);
btTransform trans = kart->getTrans();
@ -52,7 +52,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
float pitch = kart->getTerrainPitch(heading);
// aim at this kart if it's not too far
if(closest_kart != NULL && kartDistSquared < 30*30 && !m_reverse_mode) // aiming doesn't work backwards
if(closest_kart != NULL && kartDistSquared < 30*30)
{
const float time = sqrt(kartDistSquared) / (m_speed - closest_kart->getSpeed());
@ -69,14 +69,17 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
btMatrix3x3 m;
m.setEulerZYX(pitch, 0.0f, projectileAngle);
trans.setBasis(m);
createPhysics(y_offset, btVector3(0.0f, m_speed*2, 0.0f),
new btCylinderShape(0.5f*m_extend), 0.0f /* gravity */, false /* rotates */, false, &trans );
}
else
{
trans = kart->getKartHeading();
}
createPhysics(y_offset, btVector3(0.0f, m_speed*2, 0.0f),
new btCylinderShape(0.5f*m_extend), 0.0f /* gravity */, false /* rotates */, m_reverse_mode, &trans );
}
if(m_reverse_mode)
m_rubber_band = NULL;