1) Added adjustment of rotation of chassis after skidding.

2) Renamed setTimedImpulse to setTimedCentralImpulse.
New skidding is still disabled.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10652 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2012-01-12 00:09:04 +00:00
parent 814ab822d0
commit ee88af76b9
4 changed files with 46 additions and 21 deletions

View File

@ -1787,14 +1787,15 @@ void Kart::updateSkidding(float dt)
float bonus_time, bonus_force;
m_kart_properties->getSkidBonus(m_skid_time,
&bonus_time, &bonus_force);
printf("skid time %f bonus %f bonus-time %f\n",
m_skid_time, bonus_time, bonus_force);
// Set skid_time to a negative value indicating how long an
// additional rotation is going to be applied to the chassis
if(m_skid_time > m_kart_properties->getSkidVisualTime())
m_skid_time = - m_kart_properties->getSkidVisualTime();
else
m_skid_time = - m_skid_time;
float t = (m_skid_time <= m_kart_properties->getSkidVisualTime())
? m_skid_time
: m_kart_properties->getSkidVisualTime();
float vso = getVisualSkidOffset();
btVector3 rot(0, vso, 0);
m_vehicle->setTimedRotation(t, rot/(3.0f*t));
m_skid_time = 0;
if(bonus_time>0)
{
MaxSpeed::increaseMaxSpeed(MaxSpeed::MS_INCREASE_SKIDDING,
@ -1803,15 +1804,6 @@ void Kart::updateSkidding(float dt)
handleZipper(0);
}
}
if(m_skid_time<0)
{
// Apply additional rotation to the physics model
float vso = getVisualSkidOffset();
btVector3 rot(0, vso*m_kart_properties->getPostSkidRotation(), 0);
getBody()->applyTorque(rot);
m_skid_time += dt;
if(m_skid_time>0) m_skid_time = 0;
}
m_vehicle->setSkidAngularVelocity(ang_vel);
} // updateSkidding
@ -2204,7 +2196,7 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
m_zipper_fire->resizeBox(std::max(0.25f, getSpeed()*dt));
}
}
printf("visual %f %f\n", World::getWorld()->getTime(), getVisualSkidOffset());
Moveable::updateGraphics(dt, center_shift,
btQuaternion(getVisualSkidOffset(), 0, 0));
@ -2245,7 +2237,7 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
float Kart::getVisualSkidOffset() const
{
float speed_ratio = getSpeed()/MaxSpeed::getCurrentMaxSpeed();
if(m_kart_properties->getSkidVisualTime()==0)
//if(m_kart_properties->getSkidVisualTime()==0)
return getSteerPercent()*m_kart_properties->getSkidVisual()
* speed_ratio * m_skidding*m_skidding;
float f = fabsf(m_skid_time);

View File

@ -119,6 +119,8 @@ void btKart::reset()
m_num_wheels_on_ground = 0;
m_additional_impulse = btVector3(0,0,0);
m_time_additional_impulse = 0;
m_additional_rotation = btVector3(0,0,0);
m_time_additional_rotation = 0;
} // reset
// ----------------------------------------------------------------------------
@ -439,6 +441,16 @@ void btKart::updateVehicle( btScalar step )
m_time_additional_impulse -= step;
m_chassisBody->applyCentralImpulse(m_additional_impulse);
}
if(m_time_additional_rotation>0)
{
btTransform &t = m_chassisBody->getWorldTransform();
t.setRotation(t.getRotation()
*btQuaternion(m_additional_rotation.getY()*step,
m_additional_rotation.getX()*step,
m_additional_rotation.getZ()*step));
m_time_additional_rotation -= step;
}
} // updateVehicle
// ----------------------------------------------------------------------------

View File

@ -98,12 +98,23 @@ private:
/** The time the additional impulse should be applied. */
float m_time_additional_impulse;
/** Additional rotation that is applied over a certain amount of time. */
btVector3 m_additional_rotation;
/** Duration over which the additional rotation is applied. */
float m_time_additional_rotation;
/** The rigid body that is the chassis of the kart. */
btRigidBody *m_chassisBody;
/** Number of wheels that touch the ground. */
int m_num_wheels_on_ground;
/** Index of the right axis. */
int m_indexRightAxis;
/** Index of the up axis. */
int m_indexUpAxis;
/** Index of the forward axis. */
int m_indexForwardAxis;
/** The STK kart object which uses this vehicle. This is mostly used to
@ -210,7 +221,7 @@ public:
/** Sets an impulse that is applied for a certain amount of time.
* \param t Time for the impulse to be active.
* \param imp The impulse to apply. */
void setTimedImpulse(float t, const btVector3 &imp)
void setTimedCentralImpulse(float t, const btVector3 &imp)
{
// Only add impulse if no other impulse is active.
if(m_time_additional_impulse>0) return;
@ -220,6 +231,16 @@ public:
// ------------------------------------------------------------------------
/** Returns the time an additional impulse is activated. */
float getImpulseTime() const { return m_time_additional_impulse; }
// ------------------------------------------------------------------------
/** Sets a rotation that is applied over a certain amount of time (to avoid
* a too rapid changes in the kart).
* \param t Time for the rotation to be applied.
* \param torque The rotation to apply. */
void setTimedRotation(float t, const btVector3 &rot)
{
m_additional_rotation = rot;
m_time_additional_rotation = t;
} // setTimedTorque
}; // class btKart
#endif //BT_KART_HPP

View File

@ -356,7 +356,7 @@ void Physics::KartKartCollision(Kart *kart_a, const Vec3 &contact_point_a,
float t =
faster_kart->getKartProperties()->getCollisionImpulseTime();
if(t>0)
slower_kart->getVehicle()->setTimedImpulse(t, impulse);
slower_kart->getVehicle()->setTimedCentralImpulse(t, impulse);
else
slower_kart->getBody()->applyCentralImpulse(impulse);
slower_kart->getBody()->setAngularVelocity(btVector3(0,0,0));
@ -377,7 +377,7 @@ void Physics::KartKartCollision(Kart *kart_a, const Vec3 &contact_point_a,
float t =
faster_kart->getKartProperties()->getCollisionImpulseTime();
if(t>0)
faster_kart->getVehicle()->setTimedImpulse(t, impulse);
faster_kart->getVehicle()->setTimedCentralImpulse(t, impulse);
else
faster_kart->getBody()->applyCentralImpulse(impulse);
faster_kart->getBody()->setAngularVelocity(btVector3(0,0,0));
@ -393,7 +393,7 @@ void Physics::KartKartCollision(Kart *kart_a, const Vec3 &contact_point_a,
impulse *= faster_kart->getKartProperties()->getCollisionImpulse();
t = faster_kart->getKartProperties()->getCollisionImpulseTime();
if(t>0)
slower_kart->getVehicle()->setTimedImpulse(t, impulse);
slower_kart->getVehicle()->setTimedCentralImpulse(t, impulse);
else
slower_kart->getBody()->applyCentralImpulse(impulse);
slower_kart->getBody()->setAngularVelocity(btVector3(0,0,0));