Merged the physics branch back to trunk. There should be no change at

this stage for users.
The physics branch added a few new stability options (which are disabled
by default), fixed bug and reproducing history files when using physics
replay, using --log=file command line option. See log on the physics
branch for full details.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10292 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-12-01 01:14:10 +00:00
parent 6dca16c420
commit 2c33ed75ed
23 changed files with 1360 additions and 719 deletions

View File

@ -470,6 +470,7 @@ set( SRCS ${SRCS} src/main.cpp
src/physics/physical_object.hpp
src/physics/physics.cpp
src/physics/physics.hpp
src/physics/stk_dynamics_world.hpp
src/physics/triangle_mesh.cpp
src/physics/triangle_mesh.hpp
src/physics/user_pointer.hpp

View File

@ -49,15 +49,15 @@
<!-- The title music. -->
<music title="main_theme.music"/>
<!-- Mostly for debugging: maximum number of history entrie$a -->
<!-- Mostly for debugging: maximum number of history entries -->
<history max-frames="10000"/>
<!-- Skidmark data: maximum number of skid marks, and
time for skidmars to fade out. -->
time for skidmarks to fade out. -->
<skid-marks max-number="100" fadeout-time="60"/>
<!-- Defines when the upright constraint should be acctive, it's
disables when the kart is more than this value from the track. -->
disabled when the kart is more than this value from the track. -->
<near-ground distance="2"/>
<!-- How long the end animation will be shown. -->
@ -231,9 +231,12 @@
<mass value="225"/>
<!-- Suspension related values. stiffness: kart's suspension stiffness.
rest Length of suspension when at rest. travel-cm: maximum
movement of suspension - in cm!! -->
<suspension stiffness="248.0" rest="0.2" travel-cm="19"/>
rest: Length of suspension when at rest.
travel-cm: maximum movement of suspension - in cm!!
exp-string-response: dampen the suspension spring reaction
exponentially -->
<suspension stiffness="248" rest="0.2" travel-cm="19"
exp-spring-response="false"/>
<!-- Wheel related parameters: damping-relaxation/compression: for
bullet, damping parameters. Radius and width of wheel.
@ -253,26 +256,22 @@
<friction slip="10000000"/>
<!-- Values related to stability of the chassis: damping, and reduced
impact of roll. -->
impact of roll.
downward-impulse-factor: A speed proportional impulse applied each
frame that pushes the vehicle onto the ground.
track-connection-accel: An artificial force that pulls a wheel to
the ground if its off ground. Reduces the affect if a kart loses
contact with the ground (i.e. it then can't steer or accelerate
anymore). -->
<stability roll-influence="0.03"
chassis-linear-damping="0.2"
chassis-angular-damping="0"/>
chassis-angular-damping="0"
downward-impulse-factor="0"
track-connection-accel="0"/>
<!-- Parameters for the upright constraint, which keeps karts upright. -->
<upright tolerance="0.2" max-force="30"/>
<!-- An artificial force that pulls a wheel to the ground if its off
ground. Reduces the affect if a kart loses contact with the ground
(i.e. it then can't steer or accelerate anymore). -->
<track-connection-accel value="2"/>
<!-- jump-velocity is the z-axis velocity set when a jump is initiated.
This will cause the kart to start rising, till it is pulled back
by gravity. A higher value means higher Z velocity, meaning the
kart will rise faster and higher, and will be in the air longer.
Notice that jumps are currently disabled, so this value is ignored. -->
<jump velocity="3.0"/>
<!-- collision-side-impulse is an additional (artificial) impulse that
pushes the slower kart out of the way of the faster karts (i.e.
sideways to the faster kart) when a collision happens. This is
@ -291,11 +290,13 @@
band-speed-increase="7" band-fade-out-time="3"
in-face-time="4 6 7"/>
<!-- Kart-specific explosion parameters. Height: how high this
this kart is being pushed in the sky by an explosion.
Time: how long it takes before the kart can drive again.
<!-- Kart-specific explosion parameters.
Time: how long it takes before the kart can drive again (this
determines how height the kart is being thrown).
Invulnerability-time: how long a kart will be invulnerable
after being hit by an explosion. -->
after being hit by an explosion.
radius: Kart closer to this value will be affected by
an explosion as well. -->
<explosion time="2" radius="5"
invulnerability-time="6" />

View File

@ -293,6 +293,7 @@ supertuxkart_SOURCES = \
physics/physical_object.hpp \
physics/physics.cpp \
physics/physics.hpp \
phsyics/stk_dynamics_world.hpp \
physics/triangle_mesh.cpp \
physics/triangle_mesh.hpp \
physics/user_pointer.hpp \

View File

@ -38,6 +38,7 @@ STKConfig::~STKConfig()
if(m_title_music)
delete m_title_music;
} // ~STKConfig
//-----------------------------------------------------------------------------
/** Loads the stk configuration file. After loading it checks if all necessary
* values are actually defined, otherwise an error message is printed and STK

View File

@ -389,6 +389,9 @@ namespace UserConfigParams
/** Special debug camera being high over the kart. */
PARAM_PREFIX bool m_camera_debug PARAM_DEFAULT( false );
/** True if physics debugging should be enabled. */
PARAM_PREFIX bool m_physics_debug PARAM_DEFAULT( false );
/** True if slipstream debugging is activated. */
PARAM_PREFIX bool m_slipstream_debug PARAM_DEFAULT( false );

View File

@ -414,6 +414,26 @@
>
</File>
</Filter>
<Filter
Name="input"
>
<File
RelativePath="..\..\input\binding.cpp"
>
</File>
<File
RelativePath="..\..\input\device_manager.cpp"
>
</File>
<File
RelativePath="..\..\input\input_device.cpp"
>
</File>
<File
RelativePath="..\..\input\input_manager.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="challenges"
@ -927,26 +947,6 @@
>
</File>
</Filter>
<Filter
Name="input"
>
<File
RelativePath="..\..\input\binding.cpp"
>
</File>
<File
RelativePath="..\..\input\device_manager.cpp"
>
</File>
<File
RelativePath="..\..\input\input_device.cpp"
>
</File>
<File
RelativePath="..\..\input\input_manager.cpp"
>
</File>
</Filter>
<Filter
Name="race"
>
@ -1712,6 +1712,10 @@
RelativePath="..\..\physics\physics.hpp"
>
</File>
<File
RelativePath="..\..\physics\stk_dynamics_world.hpp"
>
</File>
<File
RelativePath="..\..\physics\triangle_mesh.hpp"
>

View File

@ -235,7 +235,7 @@ void InputManager::handleStaticAction(int key, int value)
break;
case KEY_F10:
if(world) history->Save();
if(world && value) history->Save();
break;
case KEY_F11:

View File

@ -276,10 +276,8 @@ void Kart::createPhysics()
// -------------------------
m_vehicle_raycaster =
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_body, m_vehicle_raycaster, this);
//FIXMEJH m_kart_properties->getTrackConnectionAccel());
// never deactivate the vehicle
m_body->setActivationState(DISABLE_DEACTIVATION);
@ -293,13 +291,16 @@ void Kart::createPhysics()
btVector3 wheel_direction(0.0f, -1.0f, 0.0f);
btVector3 wheel_axle(-1.0f, 0.0f, 0.0f);
btKart::btVehicleTuning tuning;
tuning.m_maxSuspensionTravelCm = m_kart_properties->getSuspensionTravelCM();
for(unsigned int i=0; i<4; i++)
{
bool is_front_wheel = i<2;
btWheelInfo& wheel = m_vehicle->addWheel(
m_kart_model->getWheelPhysicsPosition(i),
wheel_direction, wheel_axle, suspension_rest,
wheel_radius, *m_tuning, is_front_wheel);
wheel_radius, tuning, is_front_wheel);
wheel.m_suspensionStiffness = m_kart_properties->getSuspensionStiffness();
wheel.m_wheelsDampingRelaxation = m_kart_properties->getWheelDampingRelaxation();
wheel.m_wheelsDampingCompression = m_kart_properties->getWheelDampingCompression();
@ -416,7 +417,6 @@ Kart::~Kart()
World::getWorld()->getPhysics()->removeKart(this);
delete m_vehicle;
delete m_tuning;
delete m_vehicle_raycaster;
delete m_uprightConstraint;
@ -537,6 +537,7 @@ void Kart::reset()
m_bounce_back_time = 0.0f;
m_skidding = 1.0f;
m_time_last_crash = 0.0f;
m_speed = 0.0f;
m_view_blocked_by_plunger = 0.0f;
if(m_terrain_sound)
@ -575,9 +576,12 @@ void Kart::reset()
if (m_skidmarks)
{
m_skidmarks->reset();
m_skidmarks->adjustFog( track_manager->getTrack( race_manager->getTrackName() )->isFogEnabled() );
const Track *track =
track_manager->getTrack( race_manager->getTrackName() );
m_skidmarks->adjustFog(track->isFogEnabled() );
}
m_vehicle->reset();
for(int j=0; j<m_vehicle->getNumWheels(); j++)
{
m_vehicle->updateWheelTransform(j, true);
@ -751,12 +755,12 @@ float Kart::getActualWheelForce()
*/
bool Kart::isOnGround() const
{
return (m_vehicle->getNumWheelsOnGround() == m_vehicle->getNumWheels()
return ((int)m_vehicle->getNumWheelsOnGround() == m_vehicle->getNumWheels()
&& !playingEmergencyAnimation());
} // isOnGround
//-----------------------------------------------------------------------------
/** The kart is near the ground, but not necesarily on it (small jumps). This
/** The kart is near the ground, but not necessarily on it (small jumps). This
* is used to determine when to switch off the upright constraint, so that
* explosions can be more violent, while still
*/
@ -1678,18 +1682,6 @@ void Kart::updatePhysics(float dt)
}
} // !m_brake
} // not accelerating
#ifdef ENABLE_JUMP
if(m_controls.jump && isOnGround())
{
//Vector3 impulse(0.0f, 0.0f, 10.0f);
// getVehicle()->getRigidBody()->applyCentralImpulse(impulse);
btVector3 velocity = m_body->getLinearVelocity();
velocity.setZ( m_kart_properties->getJumpVelocity() );
getBody()->setLinearVelocity( velocity );
}
#endif
if (isOnGround())
{
if((fabs(m_controls.m_steer) > 0.001f) && m_controls.m_drift)
@ -1725,7 +1717,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
@ -1745,7 +1737,7 @@ void Kart::updatePhysics(float dt)
if (distanceFromUp < 0.85f)
{
friction = 0.0f;
enable_skidding = true;
enable_sliding = true;
}
else if (distanceFromUp > 0.9f)
{
@ -1754,7 +1746,7 @@ void Kart::updatePhysics(float dt)
else
{
friction = (distanceFromUp - 0.85f) / 0.5f;
enable_skidding = true;
enable_sliding = true;
}
}
@ -1764,7 +1756,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;

View File

@ -27,7 +27,7 @@
* of karts.
*/
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btTransform.h"
#include "items/attachment.hpp"
#include "items/powerup.hpp"
@ -36,24 +36,23 @@
#include "karts/emergency_animation.hpp"
#include "karts/max_speed.hpp"
#include "karts/moveable.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "tracks/terrain_info.hpp"
#include "utils/no_copy.hpp"
class btKart;
class btUprightConstraint;
class btVehicleTuning;
class Camera;
class Item;
class Quad;
class Shadow;
class SFXBase;
class SkidMarks;
class SlipStream;
class KartModel;
class ParticleEmitter;
class ParticleKind;
class Rain;
class SFXBase;
class Shadow;
class SkidMarks;
class SlipStream;
/** The main kart class. All type of karts are of this object, but with
* different controllers. The controllers are what turn a kart into a
@ -133,8 +132,6 @@ private:
// Bullet physics parameters
// -------------------------
btRaycastVehicle::btVehicleTuning
*m_tuning;
btCompoundShape m_kart_chassis;
btVehicleRaycaster *m_vehicle_raycaster;
btKart *m_vehicle;
@ -416,7 +413,7 @@ public:
const std::string& getIdent() const {return m_kart_properties->getIdent();}
// ------------------------------------------------------------------------
/** Returns the start transform, i.e. position and rotation. */
const btTransform getResetTransform() const {return m_reset_transform;}
const btTransform& getResetTransform() const {return m_reset_transform;}
// ------------------------------------------------------------------------
/** Returns the controller of this kart. */
Controller* getController() { return m_controller; }

View File

@ -29,6 +29,7 @@
#include "graphics/mesh_tools.hpp"
#include "io/xml_node.hpp"
#include "karts/kart.hpp"
#include "physics/btKart.hpp"
#include "utils/constants.hpp"
#define SKELETON_DEBUG 0
@ -510,7 +511,9 @@ void KartModel::update(float rotation, float steer, const float suspension[4])
m_max_suspension[i]);
float ratio = clamped_suspension[i] / suspension_length;
const int sign = ratio < 0 ? -1 : 1;
ratio = sign * fabsf(ratio*(2-ratio)); // expanded form of 1 - (1 - x)^2, i.e. making suspension display quadratic and not linear
// expanded form of 1 - (1 - x)^2, i.e. making suspension display
// quadratic and not linear
ratio = sign * fabsf(ratio*(2-ratio));
clamped_suspension[i] = ratio*suspension_length;
} // for i<4
@ -521,6 +524,16 @@ void KartModel::update(float rotation, float steer, const float suspension[4])
for(unsigned int i=0; i<4; i++)
{
if(!m_wheel_node[i]) continue;
#ifdef DEBUG
if(UserConfigParams::m_physics_debug)
{
// Make wheels that are not touching the ground invisible
bool wheel_has_contact =
m_kart->getVehicle()->getWheelInfo(i).m_raycastInfo
.m_isInContact;
m_wheel_node[i]->setVisible(wheel_has_contact);
}
#endif
core::vector3df pos = m_wheel_graphics_position[i].toIrrVector();
pos.Y += clamped_suspension[i];
m_wheel_node[i]->setPosition(pos);

View File

@ -72,7 +72,7 @@ KartProperties::KartProperties(const std::string &filename)
m_wheel_damping_compression = m_friction_slip = m_roll_influence =
m_wheel_radius = m_chassis_linear_damping =
m_chassis_angular_damping = m_suspension_rest =
m_max_speed_reverse_ratio = m_jump_velocity =
m_max_speed_reverse_ratio =
m_rescue_vert_offset = m_upright_tolerance = m_collision_side_impulse =
m_upright_max_force = m_suspension_travel_cm =
m_track_connection_accel =
@ -93,9 +93,10 @@ KartProperties::KartProperties(const std::string &filename)
m_rescue_time = m_rescue_height = m_explosion_time =
m_explosion_radius = m_ai_steering_variation =
m_swatter_distance2 = m_swatter_duration = m_squash_slowdown =
m_squash_duration = UNDEFINED;
m_squash_duration = m_downward_impulse_factor = UNDEFINED;
m_gravity_center_shift = Vec3(UNDEFINED);
m_exp_spring_response = false;
m_has_skidmarks = true;
m_version = 0;
m_color = video::SColor(255, 0, 0, 0);
@ -387,6 +388,7 @@ void KartProperties::getAllData(const XMLNode * root)
suspension_node->get("stiffness", &m_suspension_stiffness);
suspension_node->get("rest", &m_suspension_rest );
suspension_node->get("travel-cm", &m_suspension_travel_cm);
suspension_node->get("exp-spring-response", &m_exp_spring_response );
}
if(const XMLNode *wheels_node = root->getNode("wheels"))
@ -401,9 +403,16 @@ void KartProperties::getAllData(const XMLNode * root)
if(const XMLNode *stability_node = root->getNode("stability"))
{
stability_node->get("roll-influence", &m_roll_influence);
stability_node->get("chassis-linear-damping", &m_chassis_linear_damping);
stability_node->get("chassis-angular-damping", &m_chassis_angular_damping);
stability_node->get("roll-influence",
&m_roll_influence );
stability_node->get("chassis-linear-damping",
&m_chassis_linear_damping );
stability_node->get("chassis-angular-damping",
&m_chassis_angular_damping);
stability_node->get("downward-impulse-factor",
&m_downward_impulse_factor);
stability_node->get("track-connection-accel",
&m_track_connection_accel );
}
if(const XMLNode *upright_node = root->getNode("upright"))
@ -412,12 +421,6 @@ void KartProperties::getAllData(const XMLNode * root)
upright_node->get("max-force", &m_upright_max_force);
}
if(const XMLNode *track_connection_node = root->getNode("track-connection-accel"))
track_connection_node->get("value", &m_track_connection_accel);
if(const XMLNode *jump_node = root->getNode("jump"))
jump_node->get("velocity", &m_jump_velocity);
if(const XMLNode *collision_node = root->getNode("collision"))
collision_node->get("side-impulse", &m_collision_side_impulse);
@ -569,6 +572,8 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_roll_influence, "stability roll-influence" );
CHECK_NEG(m_chassis_linear_damping, "stability chassis-linear-damping" );
CHECK_NEG(m_chassis_angular_damping, "stability chassis-angular-damping");
CHECK_NEG(m_downward_impulse_factor, "stability downward-impulse-factor");
CHECK_NEG(m_track_connection_accel, "stability track-connection-accel" );
CHECK_NEG(m_engine_power[0], "engine power[0]" );
CHECK_NEG(m_engine_power[1], "engine power[1]" );
CHECK_NEG(m_engine_power[2], "engine power[2]" );
@ -581,10 +586,8 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_suspension_rest, "suspension rest" );
CHECK_NEG(m_suspension_travel_cm, "suspension travel-cm" );
CHECK_NEG(m_collision_side_impulse, "collision side-impulse" );
CHECK_NEG(m_jump_velocity, "jump velocity" );
CHECK_NEG(m_upright_tolerance, "upright tolerance" );
CHECK_NEG(m_upright_max_force, "upright max-force" );
CHECK_NEG(m_track_connection_accel, "track-connection-accel" );
CHECK_NEG(m_plunger_in_face_duration[0],"plunger in-face-time[0]" );
CHECK_NEG(m_plunger_in_face_duration[1],"plunger in-face-time[1]" );
CHECK_NEG(m_plunger_in_face_duration[2],"plunger in-face-time[2]" );

View File

@ -217,21 +217,41 @@ private:
float m_friction_slip;
float m_roll_influence;
float m_wheel_radius;
/** An impulse pushing the kart down which is proportional to speed. So
* the actual impulse is speed * m_downward_impulse_factor. Set it to
* 0 to disable completely. Based on
* http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=6059\
* &p=21240&hilit=vehicle#p21240 */
float m_downward_impulse_factor;
/** Artifical acceleration that pulls a kart down onto the track if one
* axis loses contact with the track. */
float m_track_connection_accel;
/** Linear damping of the chassis to prevent it from toppling over. */
float m_chassis_linear_damping;
/** Angular damping to prevent it from turning too easily. */
float m_chassis_angular_damping;
float m_max_speed[3];
float m_max_speed_reverse_ratio;
Vec3 m_gravity_center_shift; /**< Shift of center of gravity. */
float m_track_connection_accel; /**< Artifical acceleration that pulls a
* kart down onto the track if one axis
* loses contact with the track. */
/** Shift of center of gravity. */
Vec3 m_gravity_center_shift;
/** The suspension reaction is dampened to reach an exponential behaviour.
* See http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=7369\
* &p=25236&hilit=vehicle#p25236 for details. */
bool m_exp_spring_response;
float m_suspension_rest;
float m_suspension_travel_cm;
/** An additional artifical side-impulse that pushes the slower kart
* out of the way of the faster kart in case of a collision. */
float m_collision_side_impulse;
/** Vertical velocity set when jumping. */
float m_jump_velocity;
float m_upright_tolerance;
float m_upright_max_force;
@ -418,6 +438,12 @@ public:
float getChassisAngularDamping () const
{return m_chassis_angular_damping; }
/** Artifical downward impulse every frame. */
float getDownwardImpulseFactor() const { return m_downward_impulse_factor;}
/** Returns artificial acceleration to keep wheels on track. */
float getTrackConnectionAccel () const {return m_track_connection_accel;}
/** Returns the maximum speed dependent on the difficult level. */
float getMaxSpeed () const {return
m_max_speed[race_manager->getDifficulty()];}
@ -456,8 +482,8 @@ public:
/** Returns the amount the suspension can extend. */
float getSuspensionTravelCM () const {return m_suspension_travel_cm; }
/** Returns jump velocity (unused atm). */
float getJumpVelocity () const {return m_jump_velocity; }
/** Returns if the spring should be exponentially dampened. */
bool getExpSpringResponse() const {return m_exp_spring_response; }
/** Returns the (artificial) collision side impulse this kart will apply
* to a slower kart in case of a collision. */
@ -491,9 +517,6 @@ public:
/** Returns the maximum value of the upright counteracting force. */
float getUprightMaxForce () const {return m_upright_max_force; }
/** Returns artificial acceleration to keep wheels on track. */
float getTrackConnectionAccel () const {return m_track_connection_accel;}
/** Returns the maximum length of a rubber band before it breaks. */
float getRubberBandMaxLength () const {return m_rubber_band_max_length;}

View File

@ -457,6 +457,15 @@ int handleCmdLinePreliminary(int argc, char **argv)
{
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MISC;
}
else if( !strcmp(argv[i], "--log=terminal"))
{
UserConfigParams::m_log_errors=false;
}
else if( !strcmp(argv[i], "--log=file"))
{
UserConfigParams::m_log_errors=true;
}
else if ( !strcmp(argv[i], "--debug=all") )
{
UserConfigParams::m_verbosity |= UserConfigParams::LOG_ALL;
@ -607,6 +616,11 @@ int handleCmdLine(int argc, char **argv)
{
UserConfigParams::m_camera_debug=1;
}
else if(UserConfigParams::m_artist_debug_mode &&
!strcmp(argv[i], "--physics-debug"))
{
UserConfigParams::m_physics_debug=1;
}
else if(!strcmp(argv[i], "--kartsize-debug"))
{
for(unsigned int i=0;
@ -859,14 +873,7 @@ int handleCmdLine(int argc, char **argv)
race_manager->setNumLaps(atoi(argv[i+1]));
i++;
}
else if( !strcmp(argv[i], "--log=terminal"))
{
UserConfigParams::m_log_errors=false;
}
else if( !strcmp(argv[i], "--log=file"))
{
UserConfigParams::m_log_errors=true;
} else if( sscanf(argv[i], "--profile-laps=%d", &n)==1)
else if( sscanf(argv[i], "--profile-laps=%d", &n)==1)
{
printf("Profiling %d laps\n",n);
UserConfigParams::m_no_start_screen = true;
@ -923,6 +930,8 @@ int handleCmdLine(int argc, char **argv)
else if( !strcmp(argv[i], "--debug=flyable") ) {}
else if( !strcmp(argv[i], "--debug=misc" ) ) {}
else if( !strcmp(argv[i], "--debug=all" ) ) {}
else if( !strcmp(argv[i], "--log=terminal" ) ) {}
else if( !strcmp(argv[i], "--log=file" ) ) {}
else if( !strcmp(argv[i], "--screensize") ||
!strcmp(argv[i], "-s") ) {i++;}
else if( !strcmp(argv[i], "--fullscreen") || !strcmp(argv[i], "-f")) {}

View File

@ -368,6 +368,10 @@ void World::terminateRace()
*/
void World::resetAllKarts()
{
// Reset the physics 'remaining' time to 0 so that the number
// of timesteps is reproducible if doing a physics-based history run
getPhysics()->getPhysicsWorld()->resetLocalTime();
// If track checking is requested, check all rescue positions if
// they are heigh enough.
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES &&
@ -902,6 +906,9 @@ void World::restartRace()
projectile_manager->cleanup();
race_manager->reset();
// Make sure to overwrite the data from the previous race.
if(!history->replayHistory()) history->initRecording();
} // restartRace
//-----------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -8,57 +8,233 @@
* 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 "physics/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;
class Kart;
///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;
private:
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:
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_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
* the friction parameter in the wheels since friction directly affects
* skidding.
*/
bool m_allow_sliding;
btRigidBody* m_chassisBody;
int m_num_wheels_on_ground;
int m_indexRightAxis;
int m_indexUpAxis;
int m_indexForwardAxis;
/** The STK kart object which uses this vehicle. This is mostly used to
* get access to the kart properties, which also define physics
* properties. */
Kart *m_kart;
void defaultInit();
public:
btKart(const btVehicleTuning& tuning,btRigidBody* chassis,
btVehicleRaycaster* raycaster, float track_connect_accel );
//constructor to create a car from an existing rigidbody
btKart(btRigidBody* chassis, btVehicleRaycaster* raycaster,
Kart *kart);
virtual ~btKart() ;
void reset();
///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);
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; }
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 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; }
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;
};
#endif //BT_KART_H
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 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_RAYCASTVEHICLE_H

View File

@ -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"

View File

@ -27,6 +27,7 @@
#include "physics/btUprightConstraint.hpp"
#include "physics/irr_debug_drawer.hpp"
#include "physics/physical_object.hpp"
#include "physics/stk_dynamics_world.hpp"
#include "physics/triangle_mesh.hpp"
#include "tracks/track.hpp"
@ -48,7 +49,7 @@ Physics::Physics() : btSequentialImpulseConstraintSolver()
void Physics::init(const Vec3 &world_min, const Vec3 &world_max)
{
m_axis_sweep = new btAxisSweep3(world_min, world_max);
m_dynamics_world = new btDiscreteDynamicsWorld(m_dispatcher,
m_dynamics_world = new STKDynamicsWorld(m_dispatcher,
m_axis_sweep,
this,
m_collision_conf);

View File

@ -31,10 +31,12 @@
#include "btBulletDynamicsCommon.h"
#include "physics/irr_debug_drawer.hpp"
#include "physics/stk_dynamics_world.hpp"
#include "physics/user_pointer.hpp"
class Vec3;
class Kart;
class STKDynamicsWorld;
class Vec3;
/**
* \ingroup physics
@ -89,7 +91,10 @@ private:
}
}; // CollisionList
btDynamicsWorld *m_dynamics_world;
/** Pointer to the physics dynamics world. */
STKDynamicsWorld *m_dynamics_world;
/** Used in physics debugging to draw the physics world. */
IrrDebugDrawer *m_debug_drawer;
btCollisionDispatcher *m_dispatcher;
btBroadphaseInterface *m_axis_sweep;
@ -107,7 +112,7 @@ public:
void KartKartCollision(Kart *ka, Kart *kb);
void update (float dt);
void draw ();
btDynamicsWorld*
STKDynamicsWorld*
getPhysicsWorld () const {return m_dynamics_world;}
/** Activates the next debug mode (or switches it off again).
*/

View File

@ -0,0 +1,47 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2011 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_STK_DYNAMICS_WORLD_HPP
#define HEADER_STK_DYNAMICS_WORLD_HPP
#include "btBulletDynamicsCommon.h"
class STKDynamicsWorld : public btDiscreteDynamicsWorld
{
public:
/** The standard constructor which just created a btDiscreteDynamicsWorld. */
STKDynamicsWorld(btDispatcher* dispatcher,
btBroadphaseInterface* pairCache,
btConstraintSolver* constraintSolver,
btCollisionConfiguration* collisionConfiguration)
: btDiscreteDynamicsWorld(dispatcher, pairCache,
constraintSolver,
collisionConfiguration)
{
}
/** Resets m_localTime to 0. This allows more precise replay of
* physics, which is important for replaying histories. */
virtual void resetLocalTime() { m_localTime = 0; }
}; // STKDynamicsWorld
#endif
/* EOF */

View File

@ -24,6 +24,7 @@
#include "io/file_manager.hpp"
#include "modes/world.hpp"
#include "karts/kart.hpp"
#include "physics/physics.hpp"
#include "race/race_manager.hpp"
#include "tracks/track.hpp"
#include "utils/constants.hpp"
@ -99,6 +100,8 @@ void History::updateSaving(float dt)
}
else
{
// m_size must be m_all_deltas.size() or smaller
if(m_size<(int)m_all_deltas.size())
m_size ++;
}
m_all_deltas[m_current] = dt;
@ -122,12 +125,15 @@ void History::updateSaving(float dt)
void History::updateReplay(float dt)
{
m_current++;
World *world = World::getWorld();
if(m_current>=(int)m_all_deltas.size())
{
printf("Replay finished.\n");
exit(2);
m_current = 0;
// Note that for physics replay all physics parameters
// need to be reset, e.g. velocity, ...
world->restartRace();
}
World *world = World::getWorld();
unsigned int num_karts = world->getNumKarts();
for(unsigned k=0; k<num_karts; k++)
{
@ -337,8 +343,7 @@ void History::Load()
fgets(s, 1023, fd);
int buttonsCompressed;
float x,y,z,rx,ry,rz,rw;
sscanf(s, "%d %f %f %d %f %f %f %f %f %f %f\n",
&j,
sscanf(s, "%f %f %d %f %f %f %f %f %f %f\n",
&m_all_controls[i].m_steer,
&m_all_controls[i].m_accel,
&buttonsCompressed,

View File

@ -47,18 +47,35 @@ public:
HISTORY_POSITION = 1,
HISTORY_PHYSICS = 2 };
private:
// maximum number of history events to store
/** maximum number of history events to store. */
HistoryReplayMode m_replay_mode;
/** Points to the last used entry, and will wrap around. */
int m_current;
/** True if the buffer has wrapped around. */
bool m_wrapped;
/** Counts how many entries in the arrays are used. So if
* the buffer hasn't wrapped around, this will indicate
* how many entries to save. */
int m_size;
/** Stores all time step sizes. */
std::vector<float> m_all_deltas;
/** Stores the kart controls being used (for physics replay). */
std::vector<KartControl> m_all_controls;
/** Stores the coordinates (for simple replay). */
AlignedArray<Vec3> m_all_xyz;
/** Stores the rotations of the karts. */
AlignedArray<btQuaternion> m_all_rotations;
/** The identities of the karts to use. */
std::vector<std::string> m_kart_ident;
void allocateMemory(int number_of_frames);
void updateSaving(float dt);
void updateReplay(float dt);
@ -70,7 +87,7 @@ public:
void Save ();
void Load ();
// ------------------------------------------------------------------------
// -------------------I-----------------------------------------------------
/** Returns the identifier of the n-th kart. */
const std::string& getKartIdent(unsigned int n)
{

View File

@ -1234,7 +1234,8 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id)
m_start_transforms[position].setOrigin(xyz);
m_start_transforms[position].setRotation(
btQuaternion(btVector3(0,1,0),h ) );
btQuaternion(btVector3(0,1,0),
h*DEGREE_TO_RAD ) );
}
else if(name=="camera")
{