Replaced btKart with a fresh copy of bullet's raycast vehicle (i.e. all
STK specific tuning was removed). STK callbacks for zipper and sliding are empty, only projectVehicleToSurface was added back in. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/physics@10144 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
60633c5a65
commit
dbec3ae30a
@ -278,8 +278,8 @@ void Kart::createPhysics()
|
||||
new btKartRaycaster(World::getWorld()->getPhysics()->getPhysicsWorld());
|
||||
m_tuning = new btKart::btVehicleTuning();
|
||||
m_tuning->m_maxSuspensionTravelCm = m_kart_properties->getSuspensionTravelCM();
|
||||
m_vehicle = new btKart(*m_tuning, m_body, m_vehicle_raycaster,
|
||||
m_kart_properties->getTrackConnectionAccel());
|
||||
m_vehicle = new btKart(*m_tuning, m_body, m_vehicle_raycaster);
|
||||
//FIXMEJH m_kart_properties->getTrackConnectionAccel());
|
||||
|
||||
// never deactivate the vehicle
|
||||
m_body->setActivationState(DISABLE_DEACTIVATION);
|
||||
@ -1724,7 +1724,7 @@ void Kart::updatePhysics(float dt)
|
||||
// you have full traction; above 0.5 rad angles you have absolutely none;
|
||||
// inbetween there is a linear change in friction
|
||||
float friction = 1.0f;
|
||||
bool enable_skidding = false;
|
||||
bool enable_sliding = false;
|
||||
|
||||
// This way the current skidding
|
||||
// handling can be disabled for certain material (e.g. the
|
||||
@ -1744,7 +1744,7 @@ void Kart::updatePhysics(float dt)
|
||||
if (distanceFromUp < 0.85f)
|
||||
{
|
||||
friction = 0.0f;
|
||||
enable_skidding = true;
|
||||
enable_sliding = true;
|
||||
}
|
||||
else if (distanceFromUp > 0.9f)
|
||||
{
|
||||
@ -1753,7 +1753,7 @@ void Kart::updatePhysics(float dt)
|
||||
else
|
||||
{
|
||||
friction = (distanceFromUp - 0.85f) / 0.5f;
|
||||
enable_skidding = true;
|
||||
enable_sliding = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1763,7 +1763,7 @@ void Kart::updatePhysics(float dt)
|
||||
wheel.m_frictionSlip = friction*m_kart_properties->getFrictionSlip();
|
||||
}
|
||||
|
||||
m_vehicle->enableSliding(enable_skidding);
|
||||
m_vehicle->setSliding(enable_sliding);
|
||||
|
||||
float steering = getMaxSteerAngle() * m_controls.m_steer*m_skidding;
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "karts/moveable.hpp"
|
||||
#include "karts/kart_model.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "physics/btKart.hpp"
|
||||
#include "tracks/terrain_info.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
@ -133,8 +134,7 @@ private:
|
||||
|
||||
// Bullet physics parameters
|
||||
// -------------------------
|
||||
btRaycastVehicle::btVehicleTuning
|
||||
*m_tuning;
|
||||
btKart::btVehicleTuning *m_tuning;
|
||||
btCompoundShape m_kart_chassis;
|
||||
btVehicleRaycaster *m_vehicle_raycaster;
|
||||
btKart *m_vehicle;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,61 +4,244 @@
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies.
|
||||
* Erwin Coumans makes no representations about the suitability
|
||||
* of this software for any purpose.
|
||||
* Erwin Coumans makes no representations about the suitability
|
||||
* of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
#ifndef HEADER_BT_KART_HPP
|
||||
#define HEADER_BT_KART_HPP
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#ifndef BT_KART_HPP
|
||||
#define BT_KART_HPP
|
||||
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
|
||||
#include "btkartRaycast.hpp"
|
||||
class btDynamicsWorld;
|
||||
struct btWheelInfo;
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "BulletDynamics/Vehicle/btWheelInfo.h"
|
||||
#include "BulletDynamics/Dynamics/btActionInterface.h"
|
||||
|
||||
/** The btKart is a raycast vehicle, that does not skid. It therefore solves
|
||||
* the problems with the plain bullet physics that karts would often rotate
|
||||
* on a spot if one of the wheels loses contact with the ground.
|
||||
* \ingroup physics
|
||||
*/
|
||||
class btKart : public btRaycastVehicle
|
||||
class btVehicleTuning;
|
||||
|
||||
///rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
|
||||
class btKart : public btActionInterface
|
||||
{
|
||||
void defaultInit(const btVehicleTuning& tuning);
|
||||
btScalar m_track_connect_accel;
|
||||
int m_num_wheels_on_ground;
|
||||
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;
|
||||
|
||||
protected:
|
||||
btAlignedObjectArray<btVector3> m_forwardWS;
|
||||
btAlignedObjectArray<btVector3> m_axle;
|
||||
btAlignedObjectArray<btScalar> m_forwardImpulse;
|
||||
btAlignedObjectArray<btScalar> m_sideImpulse;
|
||||
|
||||
///backwards compatibility
|
||||
int m_userConstraintType;
|
||||
int m_userConstraintId;
|
||||
|
||||
public:
|
||||
|
||||
btKart(const btVehicleTuning& tuning,btRigidBody* chassis,
|
||||
btVehicleRaycaster* raycaster, float track_connect_accel );
|
||||
virtual ~btKart() ;
|
||||
btScalar rayCast(btWheelInfo& wheel);
|
||||
btScalar rayCast(btWheelInfo& wheel, const btVector3& ray);
|
||||
bool projectVehicleToSurface(const btVector3& ray, bool translate_vehicle);
|
||||
virtual void updateVehicle(btScalar step);
|
||||
void resetSuspension();
|
||||
int getNumWheelsOnGround() const { return m_num_wheels_on_ground; }
|
||||
void setRaycastWheelInfo(int wheelIndex , bool isInContact,
|
||||
const btVector3& hitPoint,
|
||||
const btVector3& hitNormal,btScalar depth);
|
||||
void setPitchControl(btScalar pitch) { m_pitchControl = pitch; }
|
||||
void activateZipper(btScalar vel) { m_zipper_active = true; m_zipper_velocity = vel; }
|
||||
void deactivateZipper() { m_zipper_active = false; }
|
||||
void updateSuspension(btScalar deltaTime);
|
||||
virtual void updateFriction(btScalar timeStep);
|
||||
|
||||
/** Sliding (skidding) will only be permited when this is set to true. Also check
|
||||
* the friction parameter in the wheels since friction directly affects skidding
|
||||
*/
|
||||
void enableSliding(bool enabled) { m_allow_sliding = enabled; }
|
||||
class btVehicleTuning
|
||||
{
|
||||
public:
|
||||
|
||||
btVehicleTuning()
|
||||
:m_suspensionStiffness(btScalar(5.88)),
|
||||
m_suspensionCompression(btScalar(0.83)),
|
||||
m_suspensionDamping(btScalar(0.88)),
|
||||
m_maxSuspensionTravelCm(btScalar(500.)),
|
||||
m_frictionSlip(btScalar(10.5)),
|
||||
m_maxSuspensionForce(btScalar(6000.))
|
||||
{
|
||||
}
|
||||
btScalar m_suspensionStiffness;
|
||||
btScalar m_suspensionCompression;
|
||||
btScalar m_suspensionDamping;
|
||||
btScalar m_maxSuspensionTravelCm;
|
||||
btScalar m_frictionSlip;
|
||||
btScalar m_maxSuspensionForce;
|
||||
|
||||
};
|
||||
protected:
|
||||
|
||||
btScalar m_tau;
|
||||
btScalar m_damping;
|
||||
btVehicleRaycaster* m_vehicleRaycaster;
|
||||
btScalar m_pitchControl;
|
||||
btScalar m_steeringValue;
|
||||
btScalar m_currentVehicleSpeedKmHour;
|
||||
|
||||
btRigidBody* m_chassisBody;
|
||||
|
||||
int m_num_wheels_on_ground;
|
||||
int m_indexRightAxis;
|
||||
int m_indexUpAxis;
|
||||
int m_indexForwardAxis;
|
||||
|
||||
void defaultInit(const btVehicleTuning& tuning);
|
||||
|
||||
public:
|
||||
|
||||
//constructor to create a car from an existing rigidbody
|
||||
btKart(const btVehicleTuning& tuning,btRigidBody* chassis, btVehicleRaycaster* raycaster );
|
||||
|
||||
virtual ~btKart() ;
|
||||
|
||||
|
||||
///btActionInterface interface
|
||||
virtual void updateAction( btCollisionWorld* collisionWorld, btScalar step)
|
||||
{
|
||||
(void) collisionWorld;
|
||||
updateVehicle(step);
|
||||
}
|
||||
|
||||
///btActionInterface interface
|
||||
void debugDraw(btIDebugDraw* debugDrawer);
|
||||
|
||||
const btTransform& getChassisWorldTransform() const;
|
||||
|
||||
btScalar rayCast(btWheelInfo& wheel);
|
||||
|
||||
virtual void updateVehicle(btScalar step);
|
||||
|
||||
|
||||
void resetSuspension();
|
||||
|
||||
btScalar getSteeringValue(int wheel) const;
|
||||
|
||||
void setSteeringValue(btScalar steering,int wheel);
|
||||
|
||||
|
||||
void applyEngineForce(btScalar force, int wheel);
|
||||
|
||||
const btTransform& getWheelTransformWS( int wheelIndex ) const;
|
||||
|
||||
void updateWheelTransform( int wheelIndex, bool interpolatedTransform = true );
|
||||
|
||||
// void setRaycastWheelInfo( int wheelIndex , bool isInContact, const btVector3& hitPoint, const btVector3& hitNormal,btScalar depth);
|
||||
|
||||
btWheelInfo& addWheel( const btVector3& connectionPointCS0, const btVector3& wheelDirectionCS0,const btVector3& wheelAxleCS,btScalar suspensionRestLength,btScalar wheelRadius,const btVehicleTuning& tuning, bool isFrontWheel);
|
||||
|
||||
inline int getNumWheels() const {
|
||||
return int (m_wheelInfo.size());
|
||||
}
|
||||
|
||||
btAlignedObjectArray<btWheelInfo> m_wheelInfo;
|
||||
|
||||
|
||||
const btWheelInfo& getWheelInfo(int index) const;
|
||||
|
||||
btWheelInfo& getWheelInfo(int index);
|
||||
|
||||
void updateWheelTransformsWS(btWheelInfo& wheel , bool interpolatedTransform = true);
|
||||
|
||||
|
||||
void setBrake(btScalar brake,int wheelIndex);
|
||||
|
||||
void setPitchControl(btScalar pitch)
|
||||
{
|
||||
m_pitchControl = pitch;
|
||||
}
|
||||
|
||||
void updateSuspension(btScalar deltaTime);
|
||||
|
||||
virtual void updateFriction(btScalar timeStep);
|
||||
|
||||
|
||||
|
||||
inline btRigidBody* getRigidBody()
|
||||
{
|
||||
return m_chassisBody;
|
||||
}
|
||||
|
||||
const btRigidBody* getRigidBody() const
|
||||
{
|
||||
return m_chassisBody;
|
||||
}
|
||||
|
||||
inline int getRightAxis() const
|
||||
{
|
||||
return m_indexRightAxis;
|
||||
}
|
||||
inline int getUpAxis() const
|
||||
{
|
||||
return m_indexUpAxis;
|
||||
}
|
||||
|
||||
inline int getForwardAxis() const
|
||||
{
|
||||
return m_indexForwardAxis;
|
||||
}
|
||||
|
||||
|
||||
///Worldspace forward vector
|
||||
btVector3 getForwardVector() const
|
||||
{
|
||||
const btTransform& chassisTrans = getChassisWorldTransform();
|
||||
|
||||
btVector3 forwardW (
|
||||
chassisTrans.getBasis()[0][m_indexForwardAxis],
|
||||
chassisTrans.getBasis()[1][m_indexForwardAxis],
|
||||
chassisTrans.getBasis()[2][m_indexForwardAxis]);
|
||||
|
||||
return forwardW;
|
||||
}
|
||||
|
||||
///Velocity of vehicle (positive if velocity vector has same direction as foward vector)
|
||||
btScalar getCurrentSpeedKmHour() const
|
||||
{
|
||||
return m_currentVehicleSpeedKmHour;
|
||||
}
|
||||
|
||||
virtual void setCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
|
||||
{
|
||||
m_indexRightAxis = rightIndex;
|
||||
m_indexUpAxis = upIndex;
|
||||
m_indexForwardAxis = forwardIndex;
|
||||
}
|
||||
|
||||
|
||||
///backwards compatibility
|
||||
int getUserConstraintType() const
|
||||
{
|
||||
return m_userConstraintType ;
|
||||
}
|
||||
|
||||
void setUserConstraintType(int userConstraintType)
|
||||
{
|
||||
m_userConstraintType = userConstraintType;
|
||||
};
|
||||
|
||||
void setUserConstraintId(int uid)
|
||||
{
|
||||
m_userConstraintId = uid;
|
||||
}
|
||||
|
||||
int getUserConstraintId() const
|
||||
{
|
||||
return m_userConstraintId;
|
||||
}
|
||||
private:
|
||||
btScalar rayCast(btWheelInfo& wheel, const btVector3& ray);
|
||||
public:
|
||||
void setSliding(bool active);
|
||||
void activateZipper(float speed);
|
||||
void deactivateZipper();
|
||||
bool btKart::projectVehicleToSurface(const btVector3& ray,
|
||||
bool translate_vehicle);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of wheels on the ground. */
|
||||
unsigned int getNumWheelsOnGround() const {return m_num_wheels_on_ground;}
|
||||
};
|
||||
|
||||
#endif //BT_KART_H
|
||||
#if 0
|
||||
class btDefaultVehicleRaycaster : public btVehicleRaycaster
|
||||
{
|
||||
btDynamicsWorld* m_dynamicsWorld;
|
||||
public:
|
||||
btDefaultVehicleRaycaster(btDynamicsWorld* world)
|
||||
:m_dynamicsWorld(world)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void* castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif //BT_RAYCASTVEHICLE_H
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
* of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
#ifndef BTKARTRAYCASTER_HPP
|
||||
#define BTKARTRAYCSATER_HPP
|
||||
#ifndef BTKARTRAYCAST_HPP
|
||||
#define BTKARTRAYCAST_HPP
|
||||
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user