From 191d04ec02f1472221d6afad159bea0d2b067dd7 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 2 Oct 2012 17:26:25 +0200 Subject: [PATCH] Split the raycast funtion into two versions. --- .../PolyVoxCore/include/PolyVoxCore/Raycast.h | 28 ++++++++++--------- tests/TestRaycast.cpp | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index e645dcbf..ddb9c36a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h @@ -132,24 +132,19 @@ namespace PolyVox typedef MyRaycastResults::MyRaycastResult MyRaycastResult; template - MyRaycastResult raycast(VolumeType* volData, /*const*/ Vector3DFloat/*&*/ v3dStart, const Vector3DFloat& v3dDirectionAndLength, Callback& callback) + MyRaycastResult raycastWithEndpoints(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dEnd, Callback& callback) { VolumeType::Sampler sampler(volData); //The doRaycast function is assuming that it is iterating over the areas defined between //voxels. We actually want to define the areas as being centered on voxels (as this is - //what the CubicSurfaceExtractor generates). We add (0.5,0.5,0.5) here to adjust for this. - v3dStart = v3dStart + Vector3DFloat(0.5f, 0.5f, 0.5f); - - //Compute the end point - Vector3DFloat v3dEnd = v3dStart + v3dDirectionAndLength; - - float x1 = v3dStart.getX(); - float y1 = v3dStart.getY(); - float z1 = v3dStart.getZ(); - float x2 = v3dEnd.getX(); - float y2 = v3dEnd.getY(); - float z2 = v3dEnd.getZ(); + //what the CubicSurfaceExtractor generates). We add 0.5 here to adjust for this. + float x1 = v3dStart.getX() + 0.5f; + float y1 = v3dStart.getY() + 0.5f; + float z1 = v3dStart.getZ() + 0.5f; + float x2 = v3dEnd.getX() + 0.5f; + float y2 = v3dEnd.getY() + 0.5f; + float z2 = v3dEnd.getZ() + 0.5f; int i = (int)floorf(x1); int j = (int)floorf(y1); @@ -216,6 +211,13 @@ namespace PolyVox return MyRaycastResults::Completed; } + + template + MyRaycastResult raycastWithDirection(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, Callback& callback) + { + Vector3DFloat v3dEnd = v3dStart + v3dDirectionAndLength; + return raycastWithEndpoints(volData, v3dStart, v3dEnd, callback); + } } #include "PolyVoxCore/Raycast.inl" diff --git a/tests/TestRaycast.cpp b/tests/TestRaycast.cpp index ca79af7e..de658fee 100644 --- a/tests/TestRaycast.cpp +++ b/tests/TestRaycast.cpp @@ -95,7 +95,7 @@ void TestRaycast::testExecute() // Cast a large number of random rays for(int ct = 0; ct < 1000000; ct++) { - MyRaycastResult result = raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, myFunctor); + MyRaycastResult result = raycastWithDirection(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, myFunctor); if(result == MyRaycastResults::Interupted) {