Fixed position of wheels (karts are not flying anymore),

and skid marks (which is mostly a result of wheels actually
touching the ground now).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14409 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2013-11-11 21:07:16 +00:00
parent 21b6656516
commit 48ac2fdebf
3 changed files with 78 additions and 22 deletions

View File

@ -1336,7 +1336,6 @@ void Kart::update(float dt)
m_shadow->enableShadow(); m_shadow->enableShadow();
m_shadow_enabled = true; m_shadow_enabled = true;
} }
//m_shadow->disableShadow();
} // update } // update
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -2354,6 +2353,12 @@ void Kart::setSuspensionLength()
{ {
m_default_suspension_length[i] = m_default_suspension_length[i] =
m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength; m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength;
m_default_suspension_length[i] =
getVehicle()->getRigidBody()->getWorldTransform().getOrigin().getY()-
m_vehicle->getWheelInfo(i).m_raycastInfo.m_contactPointWS.getY();
m_default_suspension_length[i] = ( m_vehicle->getWheelInfo(i).m_raycastInfo.m_hardPointWS
- m_vehicle->getWheelInfo(i).m_raycastInfo.m_contactPointWS).length()
- m_vehicle->getWheelInfo(i).m_chassisConnectionPointCS.getY();
} // for i } // for i
} // setSuspensionLength } // setSuspensionLength
@ -2395,20 +2400,27 @@ void Kart::applyEngineForce(float force)
void Kart::updateGraphics(float dt, const Vec3& offset_xyz, void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
const btQuaternion& rotation) const btQuaternion& rotation)
{ {
float wheel_up_axis[4]; float height_above_terrain[4];
float min_hat = 9999.9f;
for(unsigned int i=0; i<4; i++) for(unsigned int i=0; i<4; i++)
{ {
// Set the suspension length // Set the suspension length
wheel_up_axis[i] = m_default_suspension_length[i] height_above_terrain[i] =
- m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength; ( m_vehicle->getWheelInfo(i).m_raycastInfo.m_hardPointWS
- m_vehicle->getWheelInfo(i).m_raycastInfo.m_contactPointWS).length()
- m_vehicle->getWheelInfo(i).m_chassisConnectionPointCS.getY();
if(height_above_terrain[i] < min_hat) min_hat = height_above_terrain[i];
} }
m_kart_model->update(dt, m_wheel_rotation_dt, getSteerPercent(), wheel_up_axis, m_speed);
Vec3 center_shift = m_kart_properties->getGravityCenterShift(); float chassis_delta = 0;
if(min_hat > m_kart_model->getLowestPoint())
float kart_y_offset = m_kart_model->getWheelGraphicsRadius(0) {
- m_vehicle->getWheelInfo(0).m_wheelsRadius chassis_delta = min_hat - m_kart_model->getLowestPoint();
+ m_skidding->getGraphicalJumpOffset(); for(unsigned int i=0; i<4; i++)
height_above_terrain[i] -= chassis_delta;
}
m_kart_model->update(dt, m_wheel_rotation_dt, getSteerPercent(),
height_above_terrain, m_speed);
if ((m_controls.m_nitro || m_min_nitro_time > 0.0f) && isOnGround() && m_collected_energy > 0) if ((m_controls.m_nitro || m_min_nitro_time > 0.0f) && isOnGround() && m_collected_energy > 0)
{ {
@ -2496,7 +2508,10 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
// To avoid this, raise the kart enough to offset the leaning. // To avoid this, raise the kart enough to offset the leaning.
float lean_height = tan(fabsf(m_current_lean)) * getKartWidth()*0.5f; float lean_height = tan(fabsf(m_current_lean)) * getKartWidth()*0.5f;
center_shift.setY(kart_y_offset + lean_height); Vec3 center_shift = m_kart_properties->getGravityCenterShift();
center_shift.setY(m_skidding->getGraphicalJumpOffset() + lean_height
- m_kart_model->getLowestPoint() -chassis_delta );
float heading = m_skidding->getVisualSkidRotation(); float heading = m_skidding->getVisualSkidRotation();
Moveable::updateGraphics(dt, center_shift, Moveable::updateGraphics(dt, center_shift,
btQuaternion(heading, 0, m_current_lean)); btQuaternion(heading, 0, m_current_lean));

View File

@ -34,6 +34,8 @@
#include "utils/constants.hpp" #include "utils/constants.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
#include "IMeshManipulator.h"
#define SKELETON_DEBUG 0 #define SKELETON_DEBUG 0
float KartModel::UNDEFINED = -99.9f; float KartModel::UNDEFINED = -99.9f;
@ -276,7 +278,8 @@ KartModel* KartModel::makeCopy()
km->m_kart_width = m_kart_width; km->m_kart_width = m_kart_width;
km->m_kart_length = m_kart_length; km->m_kart_length = m_kart_length;
km->m_kart_height = m_kart_height; km->m_kart_height = m_kart_height;
km->m_kart_highest_point = m_kart_highest_point; km->m_kart_highest_point= m_kart_highest_point;
km->m_kart_lowest_point = m_kart_lowest_point;
km->m_mesh = m_mesh; km->m_mesh = m_mesh;
km->m_model_filename = m_model_filename; km->m_model_filename = m_model_filename;
km->m_animation_speed = m_animation_speed; km->m_animation_speed = m_animation_speed;
@ -393,6 +396,10 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models)
{ {
if(!m_wheel_model[i]) continue; if(!m_wheel_model[i]) continue;
m_wheel_node[i] = irr_driver->addMesh(m_wheel_model[i], node); m_wheel_node[i] = irr_driver->addMesh(m_wheel_model[i], node);
Vec3 wheel_min, wheel_max;
MeshTools::minMax3D(m_wheel_model[i], &wheel_min, &wheel_max);
m_wheel_graphics_radius[i] = 0.5f*(wheel_max.getY() - wheel_min.getY());
m_wheel_node[i]->grab(); m_wheel_node[i]->grab();
#ifdef DEBUG #ifdef DEBUG
std::string debug_name = m_wheel_filename[i]+" (wheel)"; std::string debug_name = m_wheel_filename[i]+" (wheel)";
@ -445,9 +452,26 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
irr_driver->grabAllTextures(m_mesh); irr_driver->grabAllTextures(m_mesh);
Vec3 kart_min, kart_max; Vec3 kart_min, kart_max;
MeshTools::minMax3D(m_mesh->getMesh(m_animation_frame[AF_STRAIGHT]), &kart_min, &kart_max); MeshTools::minMax3D(m_mesh->getMesh(m_animation_frame[AF_STRAIGHT]),
&kart_min, &kart_max);
#undef MOVE_KART_MESHES
#ifdef MOVE_KART_MESHES
// Kart models are not exactly centered.
scene::IMeshManipulator *mani =
irr_driver->getVideoDriver()->getMeshManipulator();
Vec3 offset_from_center = -0.5f*(kart_max+kart_min);
offset_from_center.setY(-kart_min.getY());
offset_from_center.setY(0);
core::matrix4 translate(core::matrix4::EM4CONST_IDENTITY);
translate.setTranslation(offset_from_center.toIrrVector());
mani->transform(m_mesh, translate);
MeshTools::minMax3D(m_mesh->getMesh(m_animation_frame[AF_STRAIGHT]),
&kart_min, &kart_max);
#endif
m_kart_highest_point = kart_max.getY(); m_kart_highest_point = kart_max.getY();
m_kart_lowest_point = kart_min.getY();
// Load the speed weighted object models. We need to do that now because it can affect the dimensions of the kart // Load the speed weighted object models. We need to do that now because it can affect the dimensions of the kart
for(size_t i=0 ; i < m_speed_weighted_objects.size() ; i++) for(size_t i=0 ; i < m_speed_weighted_objects.size() ; i++)
@ -733,7 +757,8 @@ void KartModel::OnAnimationEnd(scene::IAnimatedMeshSceneNode *node)
* \param suspension Suspension height for all four wheels. * \param suspension Suspension height for all four wheels.
* \param speed The speed of the kart in meters/sec, used for the speed-weighted objects' animations * \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, const float suspension[4], float speed) void KartModel::update(float dt, float rotation_dt, float steer,
const float height_above_terrain[4], float speed)
{ {
core::vector3df wheel_steer(0, steer*30.0f, 0); core::vector3df wheel_steer(0, steer*30.0f, 0);
@ -751,7 +776,8 @@ void KartModel::update(float dt, float rotation_dt, float steer, const float sus
} }
#endif #endif
core::vector3df pos = m_wheel_graphics_position[i].toIrrVector(); core::vector3df pos = m_wheel_graphics_position[i].toIrrVector();
pos.Y += suspension[i]; pos.Y = m_kart_lowest_point - height_above_terrain[i]
+ m_wheel_graphics_radius[i];
m_wheel_node[i]->setPosition(pos); m_wheel_node[i]->setPosition(pos);
// Now calculate the new rotation: (old + change) mod 360 // Now calculate the new rotation: (old + change) mod 360

View File

@ -190,10 +190,21 @@ private:
* to AF_DEFAULT the default steering animation is shown. */ * to AF_DEFAULT the default steering animation is shown. */
AnimationFrameType m_current_animation; AnimationFrameType m_current_animation;
float m_kart_width; /**< Width of kart. */ /** Width of kart. */
float m_kart_length; /**< Length of kart. */ float m_kart_width;
float m_kart_height; /**< Height of kart. */
float m_kart_highest_point; /**< Coordinate on up axis */ /** Length of kart. */
float m_kart_length;
/** Height of kart. */
float m_kart_height;
/** Largest coordinate on up axis. */
float m_kart_highest_point;
/** Smallest coordinate on up axis. */
float m_kart_lowest_point;
/** True if this is the master copy, managed by KartProperties. This /** True if this is the master copy, managed by KartProperties. This
* is mainly used for debugging, e.g. the master copies might not have * is mainly used for debugging, e.g. the master copies might not have
* anything attached to it etc. */ * anything attached to it etc. */
@ -205,7 +216,8 @@ private:
void loadNitroEmitterInfo(const XMLNode &node, void loadNitroEmitterInfo(const XMLNode &node,
const std::string &emitter_name, int index); const std::string &emitter_name, int index);
void loadSpeedWeightedInfo(const XMLNode* speed_weighted_node, const SpeedWeightedObject::Properties& fallback_properties); void loadSpeedWeightedInfo(const XMLNode* speed_weighted_node,
const SpeedWeightedObject::Properties& fallback_properties);
void OnAnimationEnd(scene::IAnimatedMeshSceneNode *node); void OnAnimationEnd(scene::IAnimatedMeshSceneNode *node);
@ -220,7 +232,7 @@ public:
void loadInfo(const XMLNode &node); void loadInfo(const XMLNode &node);
bool loadModels(const KartProperties &kart_properties); bool loadModels(const KartProperties &kart_properties);
void update(float dt, float rotation_dt, float steer, void update(float dt, float rotation_dt, float steer,
const float suspension[4], float speed); const float height_abve_terrain[4], float speed);
void setDefaultPhysicsPosition(const Vec3 &center_shift, void setDefaultPhysicsPosition(const Vec3 &center_shift,
float wheel_radius); float wheel_radius);
void finishedRace(); void finishedRace();
@ -292,9 +304,12 @@ public:
/** Returns the height of the kart. */ /** Returns the height of the kart. */
float getHeight () const {return m_kart_height; } float getHeight () const {return m_kart_height; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Coordoinate on up axis */ /** Highest coordinate on up axis */
float getHighestPoint () const { return m_kart_highest_point; } float getHighestPoint () const { return m_kart_highest_point; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Lowest coordinate on up axis */
float getLowestPoint () const { return m_kart_lowest_point; }
// ------------------------------------------------------------------------
/** Enables- or disables the end animation. */ /** Enables- or disables the end animation. */
void setAnimation(AnimationFrameType type); void setAnimation(AnimationFrameType type);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------