Made the minimum distance between interpolation control

points and the distance to target at which the rubber
ball starts aiming directly at the target configurable.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9550 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-08-18 03:31:52 +00:00
parent 017619744b
commit cb34118707
3 changed files with 32 additions and 10 deletions

View File

@ -18,6 +18,7 @@
<item name="rubber-ball" icon="rubber_ball-icon.png"
model="rubber_ball.b3d" speed="35.0" scale="1 1 1"
interval="1" max-height="4.0"
target-distance="50" min-interpolation-distance="30"
squash-slowdown="0.5" squash-duration="3" />
<item name="parachute" icon="parachute-icon.png"
model="parachute.b3d" />

View File

@ -25,8 +25,10 @@
#include "tracks/track.hpp"
float RubberBall::m_st_interval;
float RubberBall::m_st_min_interpolation_distance;
float RubberBall::m_st_squash_duration;
float RubberBall::m_st_squash_slowdown;
float RubberBall::m_st_target_distance;
RubberBall::RubberBall(Kart *kart)
: Flyable(kart, PowerupManager::POWERUP_RUBBERBALL, 0.0f /* mass */),
@ -48,7 +50,7 @@ RubberBall::RubberBall(Kart *kart)
computeTarget();
// Initialises the current graph node
// initialises the current graph node
TrackSector::update(getXYZ());
initializeControlPoints(m_owner->getXYZ());
@ -152,7 +154,7 @@ void RubberBall::getNextControlPoint()
int next = getSuccessorToHitTarget(m_last_aimed_graph_node, &dist);
float d = QuadGraph::get()->getDistanceFromStart(next)-f;
while(d<30 && d>0)
while(d<m_st_min_interpolation_distance && d>0)
{
next = getSuccessorToHitTarget(next, &dist);
d = QuadGraph::get()->getDistanceFromStart(next)-f;
@ -172,17 +174,27 @@ void RubberBall::getNextControlPoint()
*/
void RubberBall::init(const XMLNode &node, scene::IMesh *bowling)
{
m_st_interval = 1.0f;
m_st_squash_duration = 3.0f;
m_st_squash_slowdown = 0.5f;
m_st_interval = 1.0f;
m_st_squash_duration = 3.0f;
m_st_squash_slowdown = 0.5f;
m_st_target_distance = 50.0f;
m_st_min_interpolation_distance = 30.0f;
if(!node.get("interval", &m_st_interval))
printf("[powerup] Warning: no interval specific for rubber ball.\n");
printf("[powerup] Warning: no interval specified for rubber ball.\n");
if(!node.get("squash-duration", &m_st_squash_duration))
printf(
"[powerup] Warning: no squash-duration specific for rubber ball.\n");
"[powerup] Warning: no squash-duration specified for rubber ball.\n");
if(!node.get("squash-slowdown", &m_st_squash_slowdown))
printf(
"[powerup] Warning: no squash-slowdown specific for rubber ball.\n");
"[powerup] Warning: no squash-slowdown specified for rubber ball.\n");
if(!node.get("target-distance", &m_st_target_distance))
printf(
"[powerup] Warning: no target-distance specified for rubber ball.\n");
if(!node.get("min-interpolation-distance",
&m_st_min_interpolation_distance))
printf(
"[powerup] Warning: no min-interpolation-distance specified "
"for rubber ball.\n");
Flyable::init(node, bowling, PowerupManager::POWERUP_RUBBERBALL);
} // init
@ -302,7 +314,7 @@ float RubberBall::updateHeight()
if(distance<0)
distance+=World::getWorld()->getTrack()->getTrackLength();;
if(distance<50)
if(distance<m_st_target_distance)
{
// Some experimental formulas
m_current_max_height = 0.5f*sqrt(distance);
@ -353,7 +365,7 @@ void RubberBall::checkDistanceToTarget()
diff += world->getTrack()->getTrackLength();
}
if(diff < 50)
if(diff < m_st_target_distance)
{
m_aiming_at_target = true;
return;

View File

@ -41,6 +41,15 @@ private:
/** A class variable to store the default squash slowdown. */
static float m_st_squash_slowdown;
/** If the ball is closer than this distance to the target, it will
* start to aim directly at the target (and not interpolate anymore). */
static float m_st_target_distance;
/** Each control point chosen must be at least this far away from
* the previous one. This gives smooth 'overall' interpolation
* even if the quads should be close to each other. */
static float m_st_min_interpolation_distance;
/** A pointer to the target kart. */
const Kart *m_target;