Added support for steering animations. Note: since there is

currently no model with animations, there are no visible
changes atm.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3371 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-04-07 13:43:18 +00:00
parent d0fc9b1179
commit 574ebfa94d
5 changed files with 65 additions and 46 deletions

@ -1009,14 +1009,7 @@ void Kart::endRescue()
void Kart::loadData()
{
//float r [ 2 ] = { -10.0f, 100.0f } ;
m_kart_properties->getKartModel()->attachModel(&m_animated_node);
//m_kart_properties->getKartModel()->attachModel(&m_node);
m_animated_node->setLoopMode(true);
m_animated_node->setFrameLoop(1,14);
m_animated_node->setAnimationSpeed(15);
createPhysics();
// Attach Particle System
@ -1070,8 +1063,8 @@ void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
auto_skid = m_controls.m_steer*30.0f*((AUTO_SKID_VISUAL - m_skidding) / 0.8f); // divisor comes from max_skid - AUTO_SKID_VISUAL
else
auto_skid = m_controls.m_steer*30.0f;
kart_model->adjustWheels(m_wheel_rotation, auto_skid,
wheel_z_axis);
kart_model->update(m_wheel_rotation, auto_skid,
getSteerPercent(), wheel_z_axis);
Vec3 center_shift = getGravityCenterShift();
float X = m_vehicle->getWheelInfo(0).m_chassisConnectionPointCS.getZ()

@ -36,6 +36,7 @@
class SkidMarks;
class Item;
class Smoke;
class ssgTransform;
class Nitro;
class SFXBase;
class btUprightConstraint;

@ -50,6 +50,10 @@ KartModel::KartModel()
m_wheel_filename[2] = "wheel-rear-right.3ds";
m_wheel_filename[3] = "wheel-rear-left.a3ds";
m_mesh = NULL;
m_af_left = -1;
m_af_straight = -1;
m_af_right = -1;
m_animation_speed = 15;
} // KartModel
// ----------------------------------------------------------------------------
@ -59,7 +63,12 @@ KartModel::KartModel()
*/
void KartModel::loadInfo(const lisp::Lisp* lisp)
{
lisp->get("model-file", m_model_filename);
lisp->get("model-file", m_model_filename );
lisp->get("animation-left", m_af_left );
lisp->get("animation-straight", m_af_straight );
lisp->get("animation-right", m_af_right );
lisp->get("animation-speed", m_animation_speed);
loadWheelInfo(lisp, "wheel-front-right", 0);
loadWheelInfo(lisp, "wheel-front-left", 1);
loadWheelInfo(lisp, "wheel-rear-right", 2);
@ -78,8 +87,9 @@ KartModel::~KartModel()
*/
void KartModel::attachModel(scene::IAnimatedMeshSceneNode **node)
{
*node = irr_driver->addAnimatedMesh(m_mesh);
m_node = *node = irr_driver->addAnimatedMesh(m_mesh);
m_node->setAnimationSpeed(1500);
m_node->setLoopMode(false);
for(unsigned int i=0; i<4; i++)
{
m_wheel_node[i] = irr_driver->addMesh(m_wheel_model[i]);
@ -139,9 +149,8 @@ void KartModel::loadModels(const std::string &kart_ident)
{
m_z_offset = m_kart_height*0.5f;
}
} // load
// ----------------------------------------------------------------------------
/** Loads a single wheel node. Currently this is the name of the wheel model
* and the position of the wheel relative to the kart.
@ -206,11 +215,12 @@ void KartModel::setDefaultPhysicsPosition(const Vec3 &center_shift,
// ----------------------------------------------------------------------------
/** Rotates and turns the wheels appropriately, and adjust for suspension.
* \param rotation How far the wheels should rotate.
* \param steer How much the front wheels are turned for steering.
* \param visual_steer How much the front wheels are turned for steering.
* \param steer The actual steer settings.
* \param suspension Suspension height for all four wheels.
*/
void KartModel::adjustWheels(float rotation, float steer,
const float suspension[4])
void KartModel::update(float rotation, float visual_steer,
float steer, const float suspension[4])
{
float clamped_suspension[4];
@ -233,7 +243,7 @@ void KartModel::adjustWheels(float rotation, float steer,
// core::vector3df wheel_rear (RAD_TO_DEGREE(-rotation), 0, 0);
core::vector3df wheel_rear (-rotation, 0, 0);
core::vector3df wheel_steer(0, -steer, 0);
core::vector3df wheel_steer(0, -visual_steer, 0);
core::vector3df wheel_front = wheel_rear+wheel_steer;
for(unsigned int i=0; i<4; i++)
@ -247,25 +257,37 @@ void KartModel::adjustWheels(float rotation, float steer,
m_wheel_node[2]->setRotation(wheel_rear );
m_wheel_node[3]->setRotation(wheel_rear );
if(m_af_left<0) return; // no animations defined
#ifdef FIXME
sgCopyVec3(wheel_front[3], m_wheel_graphics_position[0].toFloat());
wheel_front[3][2] += clamped_suspension[0];
m_wheel_transform[0]->setTransform(wheel_front);
// Update animation if necessary
// -----------------------------
// FIXME: this implementation is currently very simple, it will always
// animate to the very left or right, even if actual steering is only
// (say) 50% of left or right.
int end;
static int last_end=-1;
if(steer<0.0f) end = m_af_left;
else if(steer>0.0f) end = m_af_right;
else end = m_af_straight;
sgCopyVec3(wheel_front[3], m_wheel_graphics_position[1].toFloat());
wheel_front[3][2] += clamped_suspension[1];
m_wheel_transform[1]->setTransform(wheel_front);
// No changes to current frame loop
if(end==last_end) return;
sgCopyVec3(wheel_rot[3], m_wheel_graphics_position[2].toFloat());
wheel_rot[3][2] += clamped_suspension[2];
m_wheel_transform[2]->setTransform(wheel_rot);
sgCopyVec3(wheel_rot[3], m_wheel_graphics_position[3].toFloat());
wheel_rot[3][2] += clamped_suspension[3];
m_wheel_transform[3]->setTransform(wheel_rot);
#endif
} // adjustWheels
int begin = (int)m_node->getFrameNr();
last_end = end;
// Handle reverse animation, which are done by setting
// the animation speed to a negative number.
if(begin<end)
{
m_node->setFrameLoop(begin, end);
m_node->setAnimationSpeed(m_animation_speed);
}
else
{
m_node->setFrameLoop(begin, end);
m_node->setAnimationSpeed(-m_animation_speed);
}
} // update
// ----------------------------------------------------------------------------
/** Puts all wheels in the default position. Used when displaying the karts
@ -273,9 +295,6 @@ void KartModel::adjustWheels(float rotation, float steer,
*/
void KartModel::resetWheels()
{
for(unsigned int i=0; i<4; i++)
{
const float suspension[4]={0,0,0,0};
adjustWheels(0, 0, suspension);
}
const float suspension[4]={0,0,0,0};
update(0, 0, 0.0f, suspension);
} // reset

@ -37,9 +37,20 @@ using namespace irr;
class KartModel
{
private:
/** The frames in which the animation points to the left, straight
* ahead, and to the right. */
int m_af_left, m_af_straight, m_af_right;
/** Animation speed. */
float m_animation_speed;
/** The mesh of the model. */
scene::IAnimatedMesh *m_mesh;
/** This is a pointer to the scene node of the kart this model belongs
* to. It is necessary to adjust animations. */
scene::IAnimatedMeshSceneNode *m_node;
/** Value used to indicate undefined entries. */
static float UNDEFINED;
@ -77,9 +88,6 @@ private:
of wheels in bullet is too large and looks strange). 1=no change, 2=half the amplitude */
float m_dampen_suspension_amplitude[4];
/** The transform for the wheels, used to rotate the wheels and display
* the suspension in the race. */
float m_kart_width; /**< Width of kart. */
float m_kart_length; /**< Length of kart. */
float m_kart_height; /**< Height of kart. */
@ -122,8 +130,8 @@ public:
/** Returns the amount a kart has to be moved down so that the bottom of
* the kart is at z=0. */
float getZOffset () const {return m_z_offset; }
void adjustWheels(float rotation, float steer,
const float suspension[4]);
void update(float rotation, float visual_steer,
float steer, const float suspension[4]);
void resetWheels();
void setDefaultPhysicsPosition(const Vec3 &center_shift, float wheel_radius);
}; // KartModel

@ -884,8 +884,6 @@ void Track::loadTrack(const std::string &filename)
getMusicInformation(filenames, m_music);
root->get("item", &m_item_style);
root->get("screenshot", &m_screenshot);
root->get("item", &m_item_style);
root->get("screenshot", &m_screenshot);
root->get("sky-color", &m_sky_color);
root->get("start-x", &m_start_x);
root->get("start-y", &m_start_y);