Merge branch 'walldriving' of github.com:lurk26/stk-code into walldriving

This commit is contained in:
hiker
2014-07-24 21:38:33 +10:00
5 changed files with 29 additions and 30 deletions

View File

@@ -274,7 +274,7 @@ std::string ListWidget::getSelectionInternalName()
int selectionID = getSelectionID();
if (selectionID == -1 || selectionID >= (int)list->getItemCount())
return "";
CGUISTKListBox::ListItem& item = list->getItem(selectionID);
const CGUISTKListBox::ListItem& item = list->getItem(selectionID);
return item.m_internal_name;
}

View File

@@ -300,7 +300,7 @@ void Flyable::getLinearKartItemIntersection (const Vec3 &origin,
target_direction.rotate(inv_rotate.getAxis(), inv_rotate.getAngle());
// Now we try to find the angle to aim at to hit the target.
// Warning : Funky stuff going on below. To understand, see answer by
// Warning : Funky math stuff going on below. To understand, see answer by
// Jeffrey Hantin here :
// http://stackoverflow.com/questions/2248876/2d-game-fire-at-a-moving-target-by-predicting-intersection-of-projectile-and-u

View File

@@ -40,6 +40,8 @@ Plunger::Plunger(AbstractKart *kart)
{
const float gravity = 0.0f;
setDoTerrainInfo(false);
float forward_offset = 0.5f*kart->getKartLength()+0.5f*m_extend.getZ();
float up_velocity = 0.0f;
float plunger_speed = 2 * m_speed;
@@ -71,8 +73,9 @@ Plunger::Plunger(AbstractKart *kart)
&fire_angle, &up_velocity);
btTransform trans = kart->getTrans();
trans.setRotation(btQuaternion(btVector3(0, 1, 0), fire_angle));
btQuaternion q;
q = trans.getRotation()*(btQuaternion(btVector3(0, 1, 0), fire_angle));
trans.setRotation(q);
m_initial_velocity = btVector3(0.0f, up_velocity, plunger_speed);

View File

@@ -357,15 +357,23 @@ bool RubberBall::updateAndDelete(float dt)
// No need to check for terrain height if the ball is low to the ground
if(height > 0.5f)
{
float terrain_height = getMaxTerrainHeight(vertical_offset)
float tunnel_height = getTunnelHeight(next_xyz, vertical_offset)
- m_extend.getY();
if(height>terrain_height)
height = terrain_height;
// If the current height of ball (above terrain) is higher than the
// tunnel height then set adjust max height and compute new height again.
// Else reset the max height.
if (height > tunnel_height)
{
m_max_height = tunnel_height;
height = updateHeight();
}
else
m_max_height = m_st_max_height[m_type];
}
if(UserConfigParams::logFlyable())
Log::verbose("RubberBall", "newy2 %f gmth %f", height,
getMaxTerrainHeight(vertical_offset));
getTunnelHeight(next_xyz,vertical_offset));
next_xyz = next_xyz + getNormal()*(height);
m_previous_xyz = getXYZ();
@@ -419,24 +427,10 @@ void RubberBall::moveTowardsTarget(Vec3 *next_xyz, float dt)
angle += 2*M_PI;
else if(angle > M_PI)
angle -= 2*M_PI;
// If ball is close to the target, then explode
if (diff.length() < m_target->getKartLength())
hit((AbstractKart*)m_target);
// If the angle is too large, adjust next xyz
/*
if(fabsf(angle)>m_st_target_max_angle*dt)
{
core::vector2df old_2d(old_vec.getX(), old_vec.getZ());
if(old_2d.getLengthSQ()==0.0f) old_2d.Y = 1.0f;
old_2d.normalize();
old_2d.rotateBy( RAD_TO_DEGREE * dt
* (angle > 0 ? m_st_target_max_angle
: -m_st_target_max_angle));
next_xyz->setX(getXYZ().getX() + old_2d.X*dt*m_speed);
next_xyz->setZ(getXYZ().getZ() + old_2d.Y*dt*m_speed);
} // if fabsf(angle) > m_st_target_angle_max*dt
*/
//*next_xyz -= getNormal()*m_previous_height;
assert(!isnan((*next_xyz)[0]));
assert(!isnan((*next_xyz)[1]));
assert(!isnan((*next_xyz)[2]));
@@ -599,15 +593,16 @@ float RubberBall::updateHeight()
* \returns The distance to the terrain element found by raycast in the up
direction. If no terrain found, it returns 99990
*/
float RubberBall::getMaxTerrainHeight(const Vec3 &vertical_offset) const
float RubberBall::getTunnelHeight(const Vec3 &next_xyz, const float vertical_offset) const
{
const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh();
Vec3 to(getXYZ() + 10000.0f*getNormal());
Vec3 hit_point;
Vec3 from(next_xyz + vertical_offset*getNormal());
Vec3 to(next_xyz + 10000.0f*getNormal());
Vec3 hit_point;
const Material *material;
tm.castRay(getXYZ()+vertical_offset, to, &hit_point, &material);
tm.castRay(from, to, &hit_point, &material);
return (material) ? (hit_point - getXYZ()).length() : 99999.f;
return (material) ? (hit_point - next_xyz).length() : 99999.f;
} // getMaxTerrainHeight
// ----------------------------------------------------------------------------

View File

@@ -196,7 +196,8 @@ private:
void interpolate(Vec3 *next_xyz, float dt);
void moveTowardsTarget(Vec3 *next_xyz, float dt);
void initializeControlPoints(const Vec3 &xyz);
float getMaxTerrainHeight(const Vec3 &vertical_offset) const;
float getTunnelHeight(const Vec3 &next_xyz,
const float vertical_offset) const;
bool checkTunneling();
public:
RubberBall (AbstractKart* kart);