Added bouncing to rubber ball (though it's imho not
yet smooth enough). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9313 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
994ea9578a
commit
bf90805448
@ -68,7 +68,7 @@ RubberBall::RubberBall(Kart *kart) : Flyable(kart, PowerupManager::POWERUP_RUBBE
|
||||
// target:
|
||||
m_aiming_at_target = false;
|
||||
m_wrapped_around = false;
|
||||
|
||||
m_previous_height = 0.0f;
|
||||
} // RubberBall
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -156,7 +156,6 @@ void RubberBall::update(float dt)
|
||||
|
||||
// FIXME: do we want to test if we have overtaken the target kart?
|
||||
|
||||
#if 0
|
||||
LinearWorld *world = dynamic_cast<LinearWorld*>(World::getWorld());
|
||||
|
||||
float target_distance =
|
||||
@ -165,16 +164,19 @@ void RubberBall::update(float dt)
|
||||
float x = target_distance - m_distance_along_track;
|
||||
if(x<0)
|
||||
x+=track_length;
|
||||
|
||||
// A formula to determine height depending on distance to target
|
||||
float height = 0.5f*sqrt(x)*fabsf(sinf(10.0f*log(0.005f*(x+5.0f))));
|
||||
// Stephen_irc:: float height = 0.5*x^0.333*fabsf(sinf(15*log(sqrt(x+5))));
|
||||
static float prev_height = 0;
|
||||
float average_height = 0.5f*prev_height + height1*0.5f;
|
||||
const float weight = 0.7f;
|
||||
float average_height = weight*m_previous_height + (1-weight)*height;
|
||||
m_previous_height = height;
|
||||
#if 0
|
||||
printf("ball z %f dt %f x %f h %f, ah %f\n",
|
||||
next_xyz.getZ(),dt,
|
||||
x, height1, average_height);
|
||||
prev_height = height1;
|
||||
next_xyz.setY(getHoT() + average_height);
|
||||
#endif
|
||||
next_xyz.setY(getHoT() + average_height);
|
||||
|
||||
setXYZ(next_xyz);
|
||||
} // update
|
||||
|
@ -45,6 +45,13 @@ private:
|
||||
* point we aimed at and have to aim at the next point. */
|
||||
float m_distance_along_track;
|
||||
|
||||
/** Since the distance between target and ball can vary a bit,
|
||||
* using it to determine height on a formula is not smooth (e.g.
|
||||
* ball can actually go up a bit during one frame while actually
|
||||
* going down). Therefore we use a weighted average of previous
|
||||
* height newly determined height. */
|
||||
float m_previous_height;
|
||||
|
||||
/** True if the ball just crossed the start line, i.e. its
|
||||
* distance changed from close to length of track in the
|
||||
* previous time step to a bit over zero now. */
|
||||
|
Loading…
Reference in New Issue
Block a user