Smooth skidding rotation when entering a cannon.

This commit is contained in:
hiker
2017-03-14 12:51:10 +11:00
parent 0bd459c2aa
commit e5eb40b773
3 changed files with 24 additions and 6 deletions

View File

@@ -27,9 +27,22 @@
#include "LinearMath/btTransform.h"
/** The constructor for the cannon animation.
* \param kart The kart to be animated.
* \param ipo The IPO (blender interpolation curve) which the kart
* should follow.
* \param start_left, start_right: Left and right end points of the line
* that the kart just crossed.
* \param end_left, end_right: Left and right end points of the line at
* which the kart finishes.
* \param skid_rot Visual rotation of the kart due to skidding (while this
* value can be queried, the AbstractkartAnimation constructor
* resets the value to 0, so it needs to be passed in.
*/
CannonAnimation::CannonAnimation(AbstractKart *kart, Ipo *ipo,
const Vec3 &start_left, const Vec3 &start_right,
const Vec3 &end_left, const Vec3 &end_right )
const Vec3 &end_left, const Vec3 &end_right,
float skid_rot)
: AbstractKartAnimation(kart, "CannonAnimation")
{
m_curve = new AnimationBase(ipo);
@@ -126,10 +139,10 @@ CannonAnimation::CannonAnimation(AbstractKart *kart, Ipo *ipo,
m_curve->getDerivativeAt(0, &tangent);
// Get the current kart orientation
Vec3 forward = m_kart->getTrans().getBasis().getColumn(2);
forward.normalize();
Vec3 v1(tangent), v2(forward);
v1.setY(0); v2.setY(0);
m_delta_heading = shortestArcQuatNormalize2(v1, v2);
m_delta_heading = shortestArcQuatNormalize2(v1, v2)
* btQuaternion(Vec3(0,1,0), skid_rot);
// The previous call to m_curve->update will set the internal timer
@@ -171,7 +184,6 @@ void CannonAnimation::update(float dt)
&tangent);
// Get the current kart orientation
Vec3 forward = m_kart->getTrans().getBasis().getColumn(2);
forward.normalize();
// Heading
// -------

View File

@@ -64,7 +64,8 @@ protected:
public:
CannonAnimation(AbstractKart *kart, Ipo *ipo,
const Vec3 &start_left, const Vec3 &start_right,
const Vec3 &end_left, const Vec3 &end_right);
const Vec3 &end_left, const Vec3 &end_right,
float skid_rot);
virtual ~CannonAnimation();
virtual void update(float dt);

View File

@@ -27,6 +27,7 @@
#include "io/xml_node.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/cannon_animation.hpp"
#include "karts/skidding.hpp"
#include "modes/world.hpp"
@@ -142,6 +143,10 @@ void CheckCannon::trigger(unsigned int kart_index)
AbstractKart *kart = World::getWorld()->getKart(kart_index);
if(kart->getKartAnimation()) return;
// The constructor AbstractKartAnimation resets the skidding to 0. So in
// order to smooth rotate the kart, we need to keep the current visual
// rotation and pass it to the CannonAnimation.
float skid_rot = kart->getSkidding()->getVisualSkidRotation();
new CannonAnimation(kart, m_curve->clone(), getLeftPoint(), getRightPoint(),
m_target_left, m_target_right);
m_target_left, m_target_right, skid_rot);
} // CheckCannon