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
21 21
22#include <glm/gtx/transform.hpp>22#include <glm/gtx/transform.hpp>
23 23
24#include <GeometryUtil.h>
24#include <SharedUtil.h>25#include <SharedUtil.h>
25 26
26#include <MetavoxelMessages.h>27#include <MetavoxelMessages.h>
@@ -1095,30 +1096,6 @@ VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int> · 1068 unmodified lines
1095 _materials(materials) {1096 _materials(materials) {
1096}1097}
1097 1098
1098static 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
1122bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,1099bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
1123 const glm::vec3& direction, float& distance) const {1100 const glm::vec3& direction, float& distance) const {
1124 float highest = _size - 1.0f;1101 float highest = _size - 1.0f;