Skip to content

Commit

Permalink
Fix example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Aug 7, 2020
1 parent 8f8ce22 commit 65d776e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ nanort::Ray<float> ray;
ray.min_t = 0.0f;
ray.max_t = 1.0e+30f;

// Returns nearest hit point(if exists)
nanort::TriangleIntersection<float> isect;

// Store nearest hit point to `isect` and returns true if the hit point found.
BVHTraceOptions trace_options; // optional
bool hit = accel.Traverse(ray, triangle_intersecter, trace_options);
bool hit = accel.Traverse(ray, triangle_intersecter, &isect, trace_options);
```
Application must prepare geometric information and store it in linear array.
Expand Down Expand Up @@ -157,7 +159,8 @@ for (int y = 0; y < height; y++) {
ray.dir[2] = dir[2];
nanort::TriangleIntersector<> triangle_intersecter(mesh.vertices, mesh.faces, /* stride */sizeof(float) * 3);
bool hit = accel.Traverse(ray, trace_options, triangle_intersector);
nanort::TriangleIntersection<> isect,
bool hit = accel.Traverse(ray, triangle_intersector, &isect, trace_options);
if (hit) {
// Write your shader here.
float3 normal;
Expand Down
14 changes: 12 additions & 2 deletions nanort.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,10 @@ class BVHAccel {
///
/// @param[in] ray Input ray
/// @param[in] intersector Intersector object. This object is called for each possible intersection of ray and BVH during traversal.
/// @param[out] isect Intersection point information(filled when any hit point was found)
/// @param[out] isect Intersection point information(filled when closest hit point was found)
/// @param[in] options Traversal options.
///
/// @return true if any hit point found
/// @return true if the closest hit point found.
///
template <class I, class H>
bool Traverse(const Ray<T> &ray, const I &intersector, H *isect,
Expand Down Expand Up @@ -953,6 +953,9 @@ class TriangleMesh {
const size_t vertex_stride_bytes_;
};

///
/// Stores intersection point information for triangle geometry.
///
template <typename T = float>
class TriangleIntersection {
public:
Expand All @@ -964,6 +967,13 @@ class TriangleIntersection {
unsigned int prim_id;
};

///
/// Intersector is a template class which implements intersection method and stores
/// intesection point information(`H`)
///
/// @tparam T Precision(float or double)
/// @tparam H Intersection point information struct
///
template <typename T = float, class H = TriangleIntersection<T> >
class TriangleIntersector {
public:
Expand Down

0 comments on commit 65d776e

Please sign in to comment.