History

use common findRayTriangleIntersection

ZappoMan committed 11 years ago

Commit d6985941 parent 8dd1a284 files · +25 −70Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 4 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+1−24
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121
2222 #include <glm/gtx/transform.hpp>
2323
24+#include <GeometryUtil.h>
2425 #include <SharedUtil.h>
2526
2627 #include <MetavoxelMessages.h>
@@ -1095,30 +1096,6 @@ VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int> · 1068 unmodified lines
10951096 _materials(materials) {
10961097 }
10971098
1098−static bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
1099− const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
1100− glm::vec3 firstSide = v0 - v1;
1101− glm::vec3 secondSide = v2 - v1;
1102− glm::vec3 normal = glm::cross(secondSide, firstSide);
1103− float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
1104− if (dividend > 0.0f) {
1105− return false; // origin below plane
1106− }
1107− float divisor = glm::dot(normal, direction);
1108− if (divisor > -EPSILON) {
1109− return false;
1110− }
1111− float t = dividend / divisor;
1112− glm::vec3 point = origin + direction * t;
1113− if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
1114− glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
1115− glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
1116− distance = t;
1117− return true;
1118− }
1119− return false;
1120−}
1121−
11221099 bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
11231100 const glm::vec3& direction, float& distance) const {
11241101 float highest = _size - 1.0f;