Updated documentation, removed commented out code.

This commit is contained in:
hiker 2014-09-12 08:37:03 +10:00
parent d79a5aaf01
commit bf135095d8
5 changed files with 36 additions and 8 deletions

View File

@ -531,13 +531,9 @@ bool PhysicalObject::castRay(const btVector3 &from, const btVector3 &to,
Log::warn("PhysicalObject", "Can only raycast against 'exact' meshes.");
return false;
}
Vec3 dxyz(m_init_xyz);
//bool result = m_triangle_mesh->castRay(from-dxyz, to-dxyz, hit_point,
bool result = m_triangle_mesh->castRay(from, to, hit_point,
material, normal,
interpolate_normal);
// if(result)
// *hit_point += (btVector3)dxyz;
return result;
} // castRay

View File

@ -272,7 +272,7 @@ btVector3 TriangleMesh::getInterpolatedNormal(unsigned int index,
// ----------------------------------------------------------------------------
/** Casts a ray from 'from' to 'to'. If a triangle of this mesh was hit,
* xyz and material will be set.
* \param from/to The from and to position for the raycast/
* \param from/to The from and to position for the raycast.
* \param xyz The position in world where the ray hit.
* \param material The material of the mesh that was hit.
* \param normal The intrapolated normal at that position.
@ -302,9 +302,11 @@ bool TriangleMesh::castRay(const btVector3 &from, const btVector3 &to,
trans_to.setOrigin(to);
btTransform world_trans;
world_trans.setIdentity();
// If there is a body, take the current transform from the body.
if(m_body)
world_trans = m_body->getWorldTransform();
else
world_trans.setIdentity();
btCollisionWorld::ClosestRayResultCallback result(from, to);
@ -338,7 +340,6 @@ bool TriangleMesh::castRay(const btVector3 &from, const btVector3 &to,
// If this is a rigid body, m_collision_object is NULL, and the
// rigid body is the actual collision object.
btCollisionWorld::rayTestSingle(trans_from, trans_to,
// m_body ? m_body : m_collision_object,
m_collision_object ? m_collision_object : m_body,
m_collision_shape, world_trans,
ray_callback);

View File

@ -63,9 +63,16 @@ public:
btVector3 getInterpolatedNormal(unsigned int index,
const btVector3 &position) const;
// ------------------------------------------------------------------------
/** In case of physical objects of shape 'exact', the physical body is
* created outside of the mesh. Since raycasts need the body's world
* transform, the body can be set using this function. This will also
* cause the body not to be freed (since it will be freed as part of
* the physical object). */
void setBody(btRigidBody *body)
{
assert(!m_body);
// Mark that the body should not be deleted when this object is
// deleted, since the body is managed elsewhere.
m_free_body = false;
m_body = body;
}

View File

@ -80,7 +80,10 @@ void TerrainInfo::update(const btTransform &trans, const Vec3 &offset)
const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh();
tm.castRay(from, to, &m_hit_point, &m_material, &m_normal,
/*interpolate*/true);
// Now also raycast against all track objects (that are driveable).
// Now also raycast against all track objects (that are driveable). If
// there should be a closer result (than the one against the main track
// mesh), its data will be returned.
World::getWorld()->getTrack()->getTrackObjectManager()
->castRay(from, to, &m_hit_point, &m_material,
&m_normal, /*interpolate*/true);

View File

@ -125,6 +125,25 @@ void TrackObjectManager::update(float dt)
} // update
// ----------------------------------------------------------------------------
/** Does a raycast against all driveable objects. This way part of the track
* can be a physical object, and can e.g. be animated. A separate list of all
* driveable objects is maintained (in one case there were over 2000 bodies,
* but only one is driveable). The result of the raycast against the track
* mesh are the input parameter. It is then tested if the raycast against
* a track object gives a 'closer' result. If so, the parameters hit_point,
* normal, and material will be updated.
* \param from/to The from and to position for the raycast.
* \param xyz The position in world where the ray hit.
* \param material The material of the mesh that was hit.
* \param normal The intrapolated normal at that position.
* \param interpolate_normal If true, the returned normal is the interpolated
* based on the three normals of the triangle and the location of the
* hit point (which is more compute intensive, but results in much
* smoother results).
* \return True if a triangle was hit, false otherwise (and no output
* variable will be set.
*/
void TrackObjectManager::castRay(const btVector3 &from,
const btVector3 &to, btVector3 *hit_point,
const Material **material,
@ -147,6 +166,8 @@ void TrackObjectManager::castRay(const btVector3 &from,
interpolate_normal))
{
float new_distance = new_hit_point.distance(from);
// If the new hit is closer than the current hit, save
// the data.
if (new_distance < distance)
{
*material = new_material;