Removed hardcoded 'up' direction for the raycast for terrain detection.

This commit is contained in:
hiker
2014-01-30 17:08:39 +11:00
parent 8313bcb0d2
commit 9db2d405ef
3 changed files with 32 additions and 9 deletions

View File

@@ -409,7 +409,7 @@ void Kart::reset()
}
m_terrain_info->update(getXYZ());
m_terrain_info->update(getTrans());
// Reset is also called when the kart is created, at which time
// m_controller is not yet defined, so this has to be tested here.
@@ -1191,14 +1191,13 @@ void Kart::update(float dt)
new RescueAnimation(this, /*is_auto_rescue*/true);
}
btTransform trans=getTrans();
// Add a certain epsilon (0.3) to the height of the kart. This avoids
// problems of the ray being cast from under the track (which happened
// e.g. on tux tollway when jumping down from the ramp, when the chassis
// partly tunnels through the track). While tunneling should not be
// happening (since Z velocity is clamped), the epsilon is left in place
// just to be on the safe side (it will not hit the chassis itself).
Vec3 pos_plus_epsilon = trans.getOrigin()+btVector3(0,0.3f,0);
Vec3 epsilon(0,0.3f,0);
// Make sure that the ray doesn't hit the kart. This is done by
// resetting the collision filter group, so that this collision
@@ -1209,7 +1208,8 @@ void Kart::update(float dt)
old_group = m_body->getBroadphaseHandle()->m_collisionFilterGroup;
m_body->getBroadphaseHandle()->m_collisionFilterGroup = 0;
}
m_terrain_info->update(pos_plus_epsilon);
m_terrain_info->update(getTrans(), epsilon);
if(m_body->getBroadphaseHandle())
{
m_body->getBroadphaseHandle()->m_collisionFilterGroup = old_group;

View File

@@ -45,18 +45,33 @@ TerrainInfo::TerrainInfo(const Vec3 &pos)
m_material = NULL;
update(pos);
} // TerrainInfo
//-----------------------------------------------------------------------------
/** Update the terrain information based on the latest position.
* \param Position from which to start the rayast from.
*/
void TerrainInfo::update(const Vec3& pos)
void TerrainInfo::update(const Vec3 &from)
{
m_last_material = m_material;
btVector3 to(pos);
to.setY(-100000.f);
btVector3 to(from);
to.setY(-10000.0f);
const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh();
tm.castRay(pos, to, &m_hit_point, &m_material, &m_normal);
tm.castRay(from, to, &m_hit_point, &m_material, &m_normal);
} // update
//-----------------------------------------------------------------------------
/** Update the terrain information based on the latest position.
* \param Position from which to start the rayast from.
*/
void TerrainInfo::update(const btTransform &trans, const Vec3 &offset)
{
m_last_material = m_material;
btVector3 from = trans(offset);
btVector3 to(0, -10000.0f, 0);
to = trans(to);
const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh();
tm.castRay(from, to, &m_hit_point, &m_material, &m_normal);
} // update
// -----------------------------------------------------------------------------

View File

@@ -21,6 +21,7 @@
#include "utils/vec3.hpp"
class btTransform;
class Material;
/** This class stores information about the triangle that's under an object, i.e.:
@@ -44,10 +45,17 @@ public:
TerrainInfo(const Vec3 &pos);
virtual ~TerrainInfo() {};
virtual void update(const Vec3 &pos);
bool getSurfaceInfo(const Vec3 &from, Vec3 *position,
const Material **m);
virtual void update(const btTransform &trans, const Vec3 &offset);
virtual void update(const Vec3 &from);
// ------------------------------------------------------------------------
/** Simple wrapper with no offset. */
virtual void update(const btTransform &trans)
{
update(trans, Vec3(0,0,0));
}
// ------------------------------------------------------------------------
/** Returns the height of the terrain. we're currently above */
float getHoT() const {return m_hit_point.getY(); }