at least dir fix works.
This commit is contained in:
@@ -209,28 +209,28 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool rayCast(const Vec3f& origin, const Vec3f& direction, float maxDist, Vec3f& hitColor) {
|
bool rayCast(const Vec3f& origin, const Vec3f& direction, float maxDist, Vec3f& hitColor) {
|
||||||
direction.normalized();
|
Vec3f dir = direction.normalized();
|
||||||
if (abs(direction.length()) < EPSILON) return false;
|
if (abs(dir.length()) < EPSILON) return false;
|
||||||
|
|
||||||
Vec3f invDir = direction.safeInverse();
|
Vec3f invDir = dir.safeInverse();
|
||||||
Vec3T currentVoxel = origin.floorToT();
|
Vec3T currentVoxel = origin.floorToT();
|
||||||
|
|
||||||
if (direction.x == 0 || direction.y == 0 || direction.z == 0) {
|
if (dir.x == 0 || dir.y == 0 || dir.z == 0) {
|
||||||
return specialCases(origin, direction, maxDist, hitColor);
|
return specialCases(origin, dir, maxDist, hitColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inGrid(currentVoxel)) {
|
if (!inGrid(currentVoxel)) {
|
||||||
std::pair<float,float> re = rayBoxIntersect(origin, direction);
|
std::pair<float,float> re = rayBoxIntersect(origin, dir);
|
||||||
float tEntry = re.first;
|
float tEntry = re.first;
|
||||||
float tExit = re.second;
|
float tExit = re.second;
|
||||||
if (tEntry < EPSILON || tExit < EPSILON) return false;
|
if (tEntry < EPSILON || tExit < EPSILON) return false;
|
||||||
float tStart = std::max(0.0f, tEntry);
|
float tStart = std::max(0.0f, tEntry);
|
||||||
if (tStart > maxDist) return false;
|
if (tStart > maxDist) return false;
|
||||||
Vec3f gridOrig = origin + direction * tStart;
|
Vec3f gridOrig = origin + dir * tStart;
|
||||||
currentVoxel = gridOrig.floorToT();
|
currentVoxel = gridOrig.floorToT();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3i8 step = Vec3i8(direction.x >= 0 ? 1 : -1, direction.y >= 0 ? 1 : -1, direction.z >= 0 ? 1 : -1);
|
Vec3i8 step = Vec3i8(dir.x >= 0 ? 1 : -1, dir.y >= 0 ? 1 : -1, dir.z >= 0 ? 1 : -1);
|
||||||
Vec3f tMax;
|
Vec3f tMax;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (step[i] > 0) {
|
if (step[i] > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user