From aa27ba317d80bd9d13de3e7626aebde6f4a327f4 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Wed, 19 Nov 2008 22:43:21 +0000 Subject: [PATCH] Changed the default for the physics wheels to be just at the corners of the chassis (and not where the graphical wheels are). Improved physics settings for hexley. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2479 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/stk_config.data | 10 +++- .../src/BulletDynamics/Vehicle/btKart.cpp | 3 +- src/karts/kart.cpp | 17 ++++++- src/karts/kart_model.cpp | 46 +++++++++++++++---- src/karts/kart_model.hpp | 2 +- src/karts/kart_properties.cpp | 10 ++-- 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/data/stk_config.data b/data/stk_config.data index 0c6cff551..f52d8c499 100644 --- a/data/stk_config.data +++ b/data/stk_config.data @@ -46,7 +46,15 @@ (corn-f 4 ) (corn-r 4 ) (wheelie-max-speed-ratio 0.7 ) ;; percentage of max speed for wheelies to work - (gravity-center-shift 0 0 0.3) + + ;; Shift of the chassis with regards to the center of mass. E.g. with the + ;; the value commented out below the chassis will be 30 cm higher than the + ;; center of mass - or the center of mass will be 30 cm lower than the + ;; middle of the chassis. So this effectively lowers the center of mass, + ;; making the kart more stable and less likely to topple over. + ;; Default (if nothing is defined here) is that the center of the mass is + ;; at the very bottom of the chassis! + ;;(gravity-center-shift 0 0 0.3) (wheelie-max-pitch 45.0 ) ;; maximum pitch to use when doing a wheelie (wheelie-pitch-rate 60.0 ) ;; rate/sec with which the kart goes up (wheelie-restore-rate 90.0 ) ;; rate/sec with which the kart does down diff --git a/src/bullet/src/BulletDynamics/Vehicle/btKart.cpp b/src/bullet/src/BulletDynamics/Vehicle/btKart.cpp index b24f6b222..87aff4ba9 100644 --- a/src/bullet/src/BulletDynamics/Vehicle/btKart.cpp +++ b/src/bullet/src/BulletDynamics/Vehicle/btKart.cpp @@ -461,7 +461,8 @@ void btKart::updateFriction(btScalar timeStep) if (m_forwardImpulse[wheel] != btScalar(0.)) { - m_chassisBody->applyImpulse(m_forwardWS[wheel]*(m_forwardImpulse[wheel]),rel_pos); + m_chassisBody->applyImpulse(m_forwardWS[wheel]*(m_forwardImpulse[wheel]), + btVector3(0,0,0)); } if (m_sideImpulse[wheel] != btScalar(0.)) { diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index d6641df43..bcfc61120 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -833,7 +833,22 @@ void Kart::updatePhysics (float dt) m_engine_sound->speed(0.6f + (float)(m_speed / max_speed)*0.7f); m_engine_sound->position(getXYZ()); } - +#ifdef XX + printf("forward %f %f %f %f side %f %f %f %f angVel %f %f %f heading %f\n" + ,m_vehicle->m_forwardImpulse[0] + ,m_vehicle->m_forwardImpulse[1] + ,m_vehicle->m_forwardImpulse[2] + ,m_vehicle->m_forwardImpulse[3] + ,m_vehicle->m_sideImpulse[0] + ,m_vehicle->m_sideImpulse[1] + ,m_vehicle->m_sideImpulse[2] + ,m_vehicle->m_sideImpulse[3] + ,m_body->getAngularVelocity().getX() + ,m_body->getAngularVelocity().getY() + ,m_body->getAngularVelocity().getZ() + ,getHPR().getHeading() + ); +#endif } // updatePhysics //----------------------------------------------------------------------------- diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 2ea84565b..d7f0b2cc4 100755 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -29,7 +29,6 @@ float KartModel::UNDEFINED = -99.9f; /** The constructor reads the model file name and wheel specification from the * kart config file. - * \param lisp Lisp object of the kart config file. */ KartModel::KartModel() { @@ -104,16 +103,14 @@ void KartModel::loadModels() for(unsigned int i=0; i<4; i++) { if(m_wheel_graphics_position[i].getX()==UNDEFINED) - m_wheel_graphics_position[i].setX( ( i==1||i==3) - ? -0.5f*m_kart_width - : 0.5f*m_kart_width ); - if(m_wheel_graphics_position[i].getY()==STKConfig::UNDEFINED) - m_wheel_graphics_position[i].setY((i<2) ? 0.5f*m_kart_length - :-0.5f*m_kart_length); - if(m_wheel_graphics_position[i].getZ()==STKConfig::UNDEFINED) + { + m_wheel_graphics_position[i].setX( ( i==1||i==3) + ? -0.5f*m_kart_width + : 0.5f*m_kart_width ); + m_wheel_graphics_position[i].setY( (i<2) ? 0.5f*m_kart_length + : -0.5f*m_kart_length); m_wheel_graphics_position[i].setZ(0); - if(m_wheel_physics_position[i].getX()==UNDEFINED) - m_wheel_physics_position[i] = m_wheel_graphics_position[i]; + } } // Load the wheel models. This can't be done early, since the default @@ -176,6 +173,35 @@ void KartModel::loadWheelInfo(const lisp::Lisp* const lisp, wheel->get("physics-position", m_wheel_physics_position[index] ); } // loadWheelInfo +// ---------------------------------------------------------------------------- +/** Sets the default position for the physical wheels if they are not defined + * in the data file. The default position is to have the wheels at the corner + * of the chassis. But since the position is relative to the center of mass, + * this must be specified. + * \param center_shift Amount the kart chassis is moved relative to the center + * of mass. + * \param wheel_radius Radius of the physics wheels. + */ +void KartModel::setDefaultPhysicsPosition(const Vec3 ¢er_shift, + float wheel_radius) +{ + for(unsigned int i=0; i<4; i++) + { + if(m_wheel_physics_position[i].getX()==UNDEFINED) + { + m_wheel_physics_position[i].setX( ( i==1||i==3) + ? -0.5f*m_kart_width + : 0.5f*m_kart_width + +center_shift.getX( )); + m_wheel_physics_position[i].setY( (0.5f*m_kart_length-wheel_radius) + * ( (i<2) ? 1 : -1) + +center_shift.getY()); + m_wheel_physics_position[i].setZ(0); + } // if physics position is not defined + } + +} // setDefaultPhysicsPosition + // ---------------------------------------------------------------------------- /** Rotates and turns the wheels appropriately, and adjust for suspension. * \param rotation How far the wheels should rotate. diff --git a/src/karts/kart_model.hpp b/src/karts/kart_model.hpp index 89e5d898b..560717564 100755 --- a/src/karts/kart_model.hpp +++ b/src/karts/kart_model.hpp @@ -113,6 +113,6 @@ public: void adjustWheels(float rotation, float steer, const float suspension[4]); void resetWheels(); - + void setDefaultPhysicsPosition(const Vec3 ¢er_shift, float wheel_radius); }; // KartModel #endif diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index d21ce4c71..e1e8b6a5e 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -138,13 +138,15 @@ void KartProperties::load(const std::string &filename, const std::string &node, if(!dont_load_models) { m_kart_model.loadModels(); - if(m_gravity_center_shift.getX()==UNDEFINED) + if(m_gravity_center_shift.getX()==UNDEFINED) + { m_gravity_center_shift.setX(0); - if(m_gravity_center_shift.getY()==UNDEFINED) m_gravity_center_shift.setY(0); - // Default: center at the very bottom of the kart. - if(m_gravity_center_shift.getZ()==UNDEFINED) + // Default: center at the very bottom of the kart. m_gravity_center_shift.setZ(m_kart_model.getHeight()*0.5f); + } + m_kart_model.setDefaultPhysicsPosition(m_gravity_center_shift, + m_wheel_radius); // Useful when tweaking kart parameters if(user_config->m_print_kart_sizes) printf("%s:\twidth: %f\tlength: %f\theight: %f\n",getIdent().c_str(),