Added callback function to Raycast, which is used to determine when a ray should stop.

This commit is contained in:
unknown
2012-03-15 16:52:54 +01:00
parent f73b2a479b
commit d9192270b6
3 changed files with 12 additions and 4 deletions

View File

@ -96,7 +96,7 @@ namespace PolyVox
{
public:
///Constructor
Raycast(VolumeType<VoxelType>* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result);
Raycast(VolumeType<VoxelType>* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function<bool(const typename VolumeType<VoxelType>::Sampler& sampler)> funcIsPassable);
///Sets the start position for the ray.
void setStart(const Vector3DFloat& v3dStart);
@ -109,6 +109,8 @@ namespace PolyVox
private:
RaycastResult& m_result;
polyvox_function<bool(const typename VolumeType<VoxelType>::Sampler& position)> m_funcIsPassable;
void doRaycast(float x1, float y1, float z1, float x2, float y2, float z2);
VolumeType<VoxelType>* m_volData;

View File

@ -32,12 +32,13 @@ namespace PolyVox
/// \param result An instance of RaycastResult in which the result will be stored.
////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType>
Raycast<VolumeType, VoxelType>::Raycast(VolumeType<VoxelType>* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result)
Raycast<VolumeType, VoxelType>::Raycast(VolumeType<VoxelType>* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function<bool(const typename VolumeType<VoxelType>::Sampler& sampler)> funcIsPassable)
:m_result(result)
,m_volData(volData)
,m_sampVolume(volData)
,m_v3dStart(v3dStart)
,m_v3dDirectionAndLength(v3dDirectionAndLength)
,m_funcIsPassable(funcIsPassable)
{
}
@ -139,7 +140,7 @@ namespace PolyVox
for(;;)
{
if(m_sampVolume.getVoxel().getDensity() > VoxelType::getThreshold())
if(!m_funcIsPassable(m_sampVolume))
{
m_result.foundIntersection = true;
m_result.intersectionVoxel = Vector3DInt32(i,j,k);