From d9192270b603228c5d57a207b854a36d795d930c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Mar 2012 16:52:54 +0100 Subject: [PATCH] Added callback function to Raycast, which is used to determine when a ray should stop. --- library/PolyVoxCore/include/PolyVoxCore/Raycast.h | 4 +++- library/PolyVoxCore/include/PolyVoxCore/Raycast.inl | 5 +++-- tests/TestRaycast.cpp | 7 ++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index b559834a..cb559ec2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h @@ -96,7 +96,7 @@ namespace PolyVox { public: ///Constructor - Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result); + Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function::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::Sampler& position)> m_funcIsPassable; + void doRaycast(float x1, float y1, float z1, float x2, float y2, float z2); VolumeType* m_volData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl index 11a14cb1..a2e12668 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl @@ -32,12 +32,13 @@ namespace PolyVox /// \param result An instance of RaycastResult in which the result will be stored. //////////////////////////////////////////////////////////////////////////////// template< template class VolumeType, typename VoxelType> - Raycast::Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result) + Raycast::Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function::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); diff --git a/tests/TestRaycast.cpp b/tests/TestRaycast.cpp index e523da4a..39d53705 100644 --- a/tests/TestRaycast.cpp +++ b/tests/TestRaycast.cpp @@ -33,6 +33,11 @@ freely, subject to the following restrictions: using namespace PolyVox; +bool isPassableByRay(const SimpleVolume::Sampler& sampler) +{ + return sampler.getVoxel().getDensity() < Density8::getThreshold(); +} + void TestRaycast::testExecute() { const int32_t uVolumeSideLength = 32; @@ -67,7 +72,7 @@ void TestRaycast::testExecute() for(int ct = 0; ct < 1000000; ct++) { RaycastResult result; - Raycast raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result); + Raycast raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay); raycast.execute(); if(result.foundIntersection) {