(Re-)Added support for disablind sliding and zipper (based
on implementation in trunk). Now the physics branch (with disabled new features) behaves like current trunk. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/physics@10287 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
31aed84b82
commit
4dbdc5c588
@ -38,17 +38,14 @@ btRigidBody& btActionInterface::getFixedBody()
|
||||
// ============================================================================
|
||||
btKart::btKart(btRigidBody* chassis, btVehicleRaycaster* raycaster,
|
||||
Kart *kart)
|
||||
: m_vehicleRaycaster(raycaster),
|
||||
m_pitchControl(btScalar(0.))
|
||||
: m_vehicleRaycaster(raycaster)
|
||||
{
|
||||
m_chassisBody = chassis;
|
||||
m_indexRightAxis = 0;
|
||||
m_indexUpAxis = 2;
|
||||
m_indexForwardAxis = 1;
|
||||
m_currentVehicleSpeedKmHour = btScalar(0.);
|
||||
m_steeringValue = btScalar(0.);
|
||||
m_num_wheels_on_ground = 0;
|
||||
m_kart = kart;
|
||||
reset();
|
||||
} // btKart
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -108,6 +105,11 @@ void btKart::reset()
|
||||
wheel.m_rotation = 0;
|
||||
updateWheelTransformsWS(wheel);
|
||||
}
|
||||
m_zipper_active = false;
|
||||
m_zipper_velocity = btScalar(0);
|
||||
m_allow_sliding = false;
|
||||
m_currentVehicleSpeedKmHour = btScalar(0.);
|
||||
m_num_wheels_on_ground = 0;
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -662,6 +664,21 @@ void btKart::updateFriction(btScalar timeStep)
|
||||
(btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
|
||||
if(!groundObject) continue;
|
||||
|
||||
if(m_zipper_active && m_zipper_velocity > 0)
|
||||
{
|
||||
if (wheel==2 || wheel==3)
|
||||
{
|
||||
// The zipper velocity is the speed that should be
|
||||
// reached. So compute the impulse to accelerate the
|
||||
// kart up to that speed:
|
||||
m_forwardImpulse[wheel] =
|
||||
0.5f*(m_zipper_velocity -
|
||||
getRigidBody()->getLinearVelocity().length())
|
||||
/ m_chassisBody->getInvMass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
btScalar rollingFriction = 0.f;
|
||||
|
||||
if (wheelInfo.m_engineForce != 0.f)
|
||||
@ -713,12 +730,15 @@ void btKart::updateFriction(btScalar timeStep)
|
||||
|
||||
} // for (int wheel=0; wheel<getNumWheels(); wheel++)
|
||||
|
||||
m_zipper_active = false;
|
||||
m_zipper_velocity = 0;
|
||||
if (sliding)
|
||||
{
|
||||
for (int wheel = 0; wheel < getNumWheels(); wheel++)
|
||||
{
|
||||
if (m_sideImpulse[wheel] != btScalar(0.) &&
|
||||
m_wheelInfo[wheel].m_skidInfo< btScalar(1.))
|
||||
if (m_sideImpulse[wheel] != btScalar(0.) &&
|
||||
m_allow_sliding &&
|
||||
m_wheelInfo[wheel].m_skidInfo< btScalar(1.) )
|
||||
{
|
||||
m_forwardImpulse[wheel] *= m_wheelInfo[wheel].m_skidInfo;
|
||||
m_sideImpulse[wheel] *= m_wheelInfo[wheel].m_skidInfo;
|
||||
@ -818,18 +838,29 @@ void btKart::debugDraw(btIDebugDraw* debugDrawer)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Enables or disables sliding.
|
||||
* \param active Enable (true) or disable sliding.
|
||||
*/
|
||||
void btKart::setSliding(bool active)
|
||||
{
|
||||
m_allow_sliding = active;
|
||||
} // setSliding
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Activates an additional speedup for the kart so that it reaches the
|
||||
* specified speed.
|
||||
* \param speed The speed to reach.
|
||||
*/
|
||||
void btKart::activateZipper(float speed)
|
||||
{
|
||||
m_zipper_active = true;
|
||||
m_zipper_velocity = speed;
|
||||
} // activateZipper
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void btKart::deactivateZipper()
|
||||
{
|
||||
m_zipper_active = false;
|
||||
} // deactivateZipper
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -25,7 +25,7 @@ class Kart;
|
||||
///rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
|
||||
class btKart : public btActionInterface
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
btAlignedObjectArray<btVector3> m_forwardWS;
|
||||
btAlignedObjectArray<btVector3> m_axle;
|
||||
btAlignedObjectArray<btScalar> m_forwardImpulse;
|
||||
@ -59,12 +59,17 @@ public:
|
||||
};
|
||||
protected:
|
||||
|
||||
btScalar m_tau;
|
||||
btScalar m_damping;
|
||||
btVehicleRaycaster* m_vehicleRaycaster;
|
||||
btScalar m_pitchControl;
|
||||
btScalar m_steeringValue;
|
||||
btScalar m_currentVehicleSpeedKmHour;
|
||||
btScalar m_damping;
|
||||
btVehicleRaycaster *m_vehicleRaycaster;
|
||||
btScalar m_currentVehicleSpeedKmHour;
|
||||
bool m_zipper_active;
|
||||
btScalar m_zipper_velocity;
|
||||
|
||||
/** Sliding (skidding) will only be permited when this is true. Also check
|
||||
* the friction parameter in the wheels since friction directly affects
|
||||
* skidding.
|
||||
*/
|
||||
bool m_allow_sliding;
|
||||
|
||||
btRigidBody* m_chassisBody;
|
||||
|
||||
@ -139,11 +144,6 @@ public:
|
||||
|
||||
|
||||
void setBrake(btScalar brake,int wheelIndex);
|
||||
|
||||
void setPitchControl(btScalar pitch)
|
||||
{
|
||||
m_pitchControl = pitch;
|
||||
}
|
||||
|
||||
void updateSuspension(btScalar deltaTime);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user