#include "IntersectableWrapper.h" #include "Mesh.h" #include "Triangle3.h" namespace GtpVisibilityPreprocessor { AxisAlignedBox3 TriangleIntersectable::GetBox() const { return mItem.GetBoundingBox(); } int TriangleIntersectable::CastRay(Ray &ray) { float nearestT = MAX_FLOAT; float t; Vector3 nearestNormal; if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) nearestT = ray.intersections[0].mT; const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal); nearestT = t; if ((hitCode == Ray::INTERSECTION) && (ray.GetType() == Ray::LOCAL_RAY)) { if (!ray.intersections.empty()) { ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal, this, 0); } else { ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal, this, 0)); } return 1; } return 0; } int TriangleIntersectable::NumberOfFaces() const { return 1; } Vector3 TriangleIntersectable::GetNormal(const int idx) const { return mItem.GetNormal(); } int TriangleIntersectable::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) { // random barycentric coordinates float a = RandomValue(0,1); float b = RandomValue(0,1); float c = RandomValue(0,1); const float sum = a + b + c; // scale so we get vaccumated value of 1 if (sum) { a /= sum; b /= sum; c /= sum; } //cout << "a: " << a << " b: " << b << " c: " << c << " sum: " << sum << endl; point = mItem.mVertices[0] * a + mItem.mVertices[1] * b + mItem.mVertices[2] * c; normal = mItem.GetNormal(); return 0; } int TriangleIntersectable::GetRandomVisibleSurfacePoint(Vector3 &point, Vector3 &normal, const Vector3 &viewpoint, const int maxTries) { return GetRandomSurfacePoint(point, normal); } }