diff --git a/data/stk_config.xml b/data/stk_config.xml index 3499cd8f1..17434528f 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -394,12 +394,12 @@ exp-spring-response="false" max-force="12000"/> - + diff --git a/lib/bullet/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp b/lib/bullet/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp index e958702d5..3a5335b88 100644 --- a/lib/bullet/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp +++ b/lib/bullet/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp @@ -118,7 +118,7 @@ void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedT btQuaternion steeringOrn(up,steering);//wheel.m_steering); btMatrix3x3 steeringMat(steeringOrn); - btQuaternion rotatingOrn(right,-wheel.m_rotation); + btQuaternion rotatingOrn(right,0); btMatrix3x3 rotatingMat(rotatingOrn); btMatrix3x3 basis2( @@ -345,17 +345,7 @@ void btRaycastVehicle::updateVehicle( btScalar step ) fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj; btScalar proj2 = fwd.dot(vel); - - wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelsRadius); - wheel.m_rotation += wheel.m_deltaRotation; - - } else - { - wheel.m_rotation += wheel.m_deltaRotation; - } - - wheel.m_deltaRotation *= btScalar(0.99);//damping of rotation when not in contact - + } } diff --git a/lib/bullet/src/BulletDynamics/Vehicle/btWheelInfo.h b/lib/bullet/src/BulletDynamics/Vehicle/btWheelInfo.h index 6677ceb1f..b04a0ac97 100644 --- a/lib/bullet/src/BulletDynamics/Vehicle/btWheelInfo.h +++ b/lib/bullet/src/BulletDynamics/Vehicle/btWheelInfo.h @@ -67,8 +67,6 @@ struct btWheelInfo btScalar m_wheelsDampingRelaxation;//const btScalar m_frictionSlip; btScalar m_steering; - btScalar m_rotation; - btScalar m_deltaRotation; btScalar m_rollInfluence; btScalar m_maxSuspensionForce; @@ -99,8 +97,6 @@ struct btWheelInfo m_frictionSlip = ci.m_frictionSlip; m_steering = btScalar(0.); m_engineForce = btScalar(0.); - m_rotation = btScalar(0.); - m_deltaRotation = btScalar(0.); m_brake = btScalar(0.); m_rollInfluence = btScalar(0.1); m_bIsFrontWheel = ci.m_bIsFrontWheel; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 686bb27e0..a3049f4aa 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -142,8 +142,6 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id, // Set position and heading: m_reset_transform = init_transform; m_speed = 0.0f; - m_wheel_rotation = 0; - m_wheel_rotation_dt = 0; m_kart_model->setKart(this); @@ -347,7 +345,6 @@ void Kart::reset() m_node->setScale(core::vector3df(1.0f, 1.0f, 1.0f)); m_collected_energy = 0; m_has_started = false; - m_wheel_rotation = 0; m_bounce_back_time = 0.0f; m_brake_time = 0.0f; m_time_last_crash = 0.0f; @@ -385,22 +382,6 @@ void Kart::reset() { m_vehicle->reset(); } - // Randomize wheel rotation if needed - if (m_kart_properties->hasRandomWheels() && m_vehicle && m_kart_model) - { - scene::ISceneNode** graphic_wheels = m_kart_model->getWheelNodes(); - // FIXME Hardcoded i < 4 comes from the arrays in KartModel - for (int i = 0; i < m_vehicle->getNumWheels() && i < 4; i++) - { - // Physics - btWheelInfo& wheel = m_vehicle->getWheelInfo(i); - wheel.m_rotation = btScalar(rand() % 360); - // And graphics - core::vector3df wheel_rotation(wheel.m_rotation, 0, 0); - if (graphic_wheels[i]) - graphic_wheels[i]->setRotation(wheel_rotation); - } // for wheels - } // if random wheel rotation setTrans(m_reset_transform); @@ -618,17 +599,12 @@ void Kart::createPhysics() // All wheel positions are relative to the center of // the collision shape. wheel_pos[index].setX(x*0.5f*kart_width); - float radius = getKartProperties()->getWheelRadius(); // The y position of the wheels (i.e. the points where // the suspension is attached to) is just at the // bottom of the kart. That is half the kart height - // down. The wheel radius is added to the suspension - // length in the physics, so we move the connection - // point 'radius' up. That means that if the suspension - // is fully compressed (0), the wheel will just be at - // the bottom of the kart chassis and touch the ground - wheel_pos[index].setY(- 0.5f*kart_height + radius); - wheel_pos[index].setZ((0.5f*kart_length - radius)* z); + // down. + wheel_pos[index].setY(- 0.5f*kart_height); + wheel_pos[index].setZ((0.5f*kart_length-0.25f)* z); } else @@ -683,7 +659,6 @@ void Kart::createPhysics() // Add wheels // ---------- - float wheel_radius = m_kart_properties->getWheelRadius(); float suspension_rest = m_kart_properties->getSuspensionRest(); btVector3 wheel_direction(0.0f, -1.0f, 0.0f); @@ -702,7 +677,8 @@ void Kart::createPhysics() btWheelInfo& wheel = m_vehicle->addWheel( wheel_pos[i]+cs, wheel_direction, wheel_axle, suspension_rest, - wheel_radius, tuning, is_front_wheel); + m_kart_model->getWheelGraphicsRadius(i), + 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(); @@ -1180,11 +1156,6 @@ void Kart::update(float dt) m_kart_properties->getChassisAngularDamping()); } - //m_wheel_rotation gives the rotation around the X-axis - m_wheel_rotation_dt = m_speed*dt / m_kart_properties->getWheelRadius(); - m_wheel_rotation += m_wheel_rotation_dt; - m_wheel_rotation = fmodf(m_wheel_rotation, 2*M_PI); - if(m_kart_animation) m_kart_animation->update(dt); @@ -2601,7 +2572,9 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz, } } - m_kart_model->update(dt, m_wheel_rotation_dt, getSteerPercent(), m_speed); + // m_speed*dt is the distance the kart has moved, which determines + // how much the wheels need to rotate. + m_kart_model->update(dt, m_speed*dt, getSteerPercent(), m_speed); // If the kart is leaning, part of the kart might end up 'in' the track. // To avoid this, raise the kart enough to offset the leaning. diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 4411e618e..5d4a3d962 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -188,12 +188,6 @@ private: /** Handles all slipstreaming. */ SlipStream *m_slipstream; - /** Rotation compared to the start position, same for all wheels */ - float m_wheel_rotation; - - /** Rotation change in the last time delta, same for all wheels */ - float m_wheel_rotation_dt; - /** The skidmarks object for this kart. */ SkidMarks *m_skidmarks; diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 4896d629e..7b3496828 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -654,6 +654,15 @@ void KartModel::loadWheelInfo(const XMLNode &node, */ void KartModel::reset() { + for (unsigned int i = 0; i < 4; i++) + { + m_wheel_rotation[i] = btScalar(rand() % 360); + m_wheel_rotation_dt[i] = 0.0f; + core::vector3df wheel_rotation(0, 0, 0); + if (m_wheel_node[i]) + m_wheel_node[i]->setRotation(wheel_rotation); + + } update(0.0f, 0.0f, 0.0f, 0.0f); // Stop any animations currently being played. @@ -784,7 +793,7 @@ void KartModel::setDefaultSuspension() * \param speed The speed of the kart in meters/sec, used for the * speed-weighted objects' animations */ -void KartModel::update(float dt, float rotation_dt, float steer, float speed) +void KartModel::update(float dt, float distance, float steer, float speed) { core::vector3df wheel_steer(0, steer*30.0f, 0); @@ -802,6 +811,10 @@ void KartModel::update(float dt, float rotation_dt, float steer, float speed) } } #endif + //m_wheel_rotation gives the rotation around the X-axis + m_wheel_rotation_dt[i] = distance / m_wheel_graphics_radius[i]; + m_wheel_rotation[i] += m_wheel_rotation_dt[i]; + m_wheel_rotation[i] = fmodf(m_wheel_rotation[i], 2 * M_PI); core::vector3df pos = m_wheel_graphics_position[i].toIrrVector(); @@ -811,7 +824,7 @@ void KartModel::update(float dt, float rotation_dt, float steer, float speed) // Now calculate the new rotation: (old + change) mod 360 float new_rotation = m_wheel_node[i]->getRotation().X - + rotation_dt * RAD_TO_DEGREE; + + m_wheel_rotation_dt[i] * RAD_TO_DEGREE; new_rotation = fmodf(new_rotation, 360); core::vector3df wheel_rotation(new_rotation, 0, 0); // Only apply steer to first 2 wheels. diff --git a/src/karts/kart_model.hpp b/src/karts/kart_model.hpp index 249ea51a7..8fc52814e 100644 --- a/src/karts/kart_model.hpp +++ b/src/karts/kart_model.hpp @@ -185,6 +185,14 @@ private: of wheels in bullet is too large and looks strange). 1=no change, 2=half the amplitude */ float m_dampen_suspension_amplitude[4]; + /** Rotation compared to the start position, same for all wheels */ + float m_wheel_rotation[4]; + + /** Rotation change in the last time delta, same for all wheels */ + float m_wheel_rotation_dt[4]; + + + /** Which animation is currently being played. This is used to overwrite * the default steering animations while being in race. If this is set * to AF_DEFAULT the default steering animation is shown. */ @@ -232,7 +240,7 @@ public: void loadInfo(const XMLNode &node); bool loadModels(const KartProperties &kart_properties); void setDefaultSuspension(); - void update(float dt, float rotation_dt, float steer, + void update(float dt, float distance, float steer, float speed); void finishedRace(); scene::ISceneNode* diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 8f4091b63..1aab033fb 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -70,7 +70,7 @@ KartProperties::KartProperties(const std::string &filename) m_nitro_max_speed_increase = m_nitro_duration = m_nitro_fade_out_time = m_suspension_stiffness = m_wheel_damping_relaxation = m_wheel_base = m_wheel_damping_compression = m_friction_slip = m_roll_influence = - m_wheel_radius = m_chassis_linear_damping = m_max_suspension_force = + m_chassis_linear_damping = m_max_suspension_force = m_chassis_angular_damping = m_suspension_rest = m_max_speed_reverse_ratio = m_rescue_vert_offset = m_collision_terrain_impulse = m_collision_impulse = m_restitution = @@ -298,7 +298,10 @@ void KartProperties::load(const std::string &filename, const std::string &node) // moved to be on the corner of the shape. In order to retain the same // steering behaviour, the wheel base (which in turn determines the // turn angle at certain speeds) is shortened by 2*wheel_radius - m_wheel_base = fabsf(m_kart_model->getLength() - 2*m_wheel_radius); + // Wheel radius was always 0.25, and is now not used anymore, but in order + // to keep existing steering behaviour, the same formula is still + // used. + m_wheel_base = fabsf(m_kart_model->getLength() - 2*0.25f); // Now convert the turn radius into turn angle: for(unsigned int i=0; iget("damping-relaxation", &m_wheel_damping_relaxation ); wheels_node->get("damping-compression", &m_wheel_damping_compression); - wheels_node->get("radius", &m_wheel_radius ); } if(const XMLNode *speed_weighted_objects_node = root->getNode("speed-weighted-objects")) @@ -687,7 +689,6 @@ void KartProperties::checkAllSet(const std::string &filename) CHECK_NEG(m_time_reset_steer, "turn time-reset-steer" ); CHECK_NEG(m_wheel_damping_relaxation, "wheels damping-relaxation" ); CHECK_NEG(m_wheel_damping_compression, "wheels damping-compression" ); - CHECK_NEG(m_wheel_radius, "wheels radius" ); CHECK_NEG(m_friction_slip, "friction slip" ); CHECK_NEG(m_roll_influence, "stability roll-influence" ); CHECK_NEG(m_chassis_linear_damping, "stability chassis-linear-damping" ); diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index bbb5adb82..760f94049 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -288,7 +288,6 @@ private: float m_max_suspension_force; float m_friction_slip; float m_roll_influence; - float m_wheel_radius; /** Parameters for the speed-weighted objects */ SpeedWeightedObject::Properties m_speed_weighted_object_properties; @@ -571,10 +570,6 @@ public: /** Returns roll influence. */ float getRollInfluence () const {return m_roll_influence; } - // ------------------------------------------------------------------------ - /** Returns wheel radius. */ - float getWheelRadius () const {return m_wheel_radius; } - // ------------------------------------------------------------------------ /** Return the additional Y offset added to the y position of the graphical * chassis. Useful for karts that don't have enough space for suspension diff --git a/src/physics/btKart.cpp b/src/physics/btKart.cpp index cf45fa27d..5da1c0fa6 100644 --- a/src/physics/btKart.cpp +++ b/src/physics/btKart.cpp @@ -112,7 +112,6 @@ void btKart::reset() { btWheelInfo &wheel = m_wheelInfo[i]; wheel.m_raycastInfo.m_suspensionLength = 0; - wheel.m_rotation = 0; updateWheelTransform(i, true); } m_visual_wheels_touch_ground = false; @@ -159,7 +158,7 @@ void btKart::updateWheelTransform(int wheelIndex, bool interpolatedTransform) btQuaternion steeringOrn(up,steering);//wheel.m_steering); btMatrix3x3 steeringMat(steeringOrn); - btQuaternion rotatingOrn(right,-wheel.m_rotation); + btQuaternion rotatingOrn(right,0); btMatrix3x3 rotatingMat(rotatingOrn); btMatrix3x3 basis2( @@ -235,7 +234,7 @@ btScalar btKart::rayCast(unsigned int index) updateWheelTransformsWS( wheel,false); - btScalar max_susp_len = wheel.getSuspensionRestLength()+wheel.m_wheelsRadius + btScalar max_susp_len = wheel.getSuspensionRestLength() + wheel.m_maxSuspensionTravel; // Do a slightly longer raycast to see if the kart might soon hit the @@ -266,7 +265,7 @@ btScalar btKart::rayCast(unsigned int index) wheel.m_raycastInfo.m_triangle_index = rayResults.m_triangle_index;; wheel.m_raycastInfo.m_groundObject = &getFixedBody(); - wheel.m_raycastInfo.m_suspensionLength = depth - wheel.m_wheelsRadius; + wheel.m_raycastInfo.m_suspensionLength = depth; //clamp on max suspension travel btScalar minSuspensionLength = wheel.getSuspensionRestLength() @@ -524,15 +523,8 @@ void btKart::updateVehicle( btScalar step ) btScalar proj2 = fwd.dot(vel); - wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelsRadius); - wheel.m_rotation += wheel.m_deltaRotation; - } else - { - wheel.m_rotation += wheel.m_deltaRotation; - } - //damping of rotation when not in contact - wheel.m_deltaRotation *= btScalar(0.99); + } } diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 8f04de77b..457b3b14c 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -2444,8 +2444,7 @@ bool Track::findGround(AbstractKart *kart) // length of the suspension with the weight of the kart resting on // it). On the other hand this initial bouncing looks nice imho // - so I'll leave it in for now. - float offset = kart->getKartProperties()->getSuspensionRest() + - kart->getKartProperties()->getWheelRadius(); + float offset = kart->getKartProperties()->getSuspensionRest(); t.setOrigin(hit_point+Vec3(0, offset, 0) ); kart->getBody()->setCenterOfMassTransform(t); kart->setTrans(t);