Skip to content

Commit

Permalink
fix ray grid traversal, fix ray aabb intersection.
Browse files Browse the repository at this point in the history
  • Loading branch information
relleums committed Jun 6, 2024
1 parent d2c22eb commit 446439d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
27 changes: 27 additions & 0 deletions libs/mli/src/mliRay.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,33 @@ CASE("ray inside aabb")
}
}

CASE("ray aabb actual test cases")
{
struct mliAABB aabb;
/*struct mliVec aabbextent;*/
struct mliRay ray;
/*struct mliVec vn, vf;*/
double near, far;
aabb.lower = mliVec_init(-5124735.0, -5120543.0, -5000.0);
aabb.upper = mliVec_init(5115265.0, 5119457.0, 5000.0);
/*aabbextent = mliVec_substract(aabb.upper, aabb.lower);*/
ray = mliRay_set(
mliVec_init(-15220843.0, -16454620.0, 0.0),
mliVec_init(0.678895, 0.734165, 0.010214));

mliRay_aabb_intersections(ray, aabb, &near, &far);
CHECK(!mliRay_aabb_intersections_is_valid_given_near_and_far(
near, far));
/*
vn = mliRay_at(&ray, near);
vf = mliRay_at(&ray, far);
fprintf(stderr, "n:%e, f:%e\n", near, far);
fprintf(stderr, "vn:(%f, %f, %f), vf:(%f, %f, %f)\n",
vn.x/aabbextent.x, vn.y/aabbextent.y, vn.z/aabbextent.z,
vf.x/aabbextent.x, vf.y/aabbextent.y, vf.z/aabbextent.z);
*/
}

CASE("mliHomTraComp, transform direction")
{
struct mliHomTraComp Tcomp;
Expand Down
5 changes: 1 addition & 4 deletions libs/mli/src/mliRay_AABB.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ int mliRay_aabb_intersections_is_valid_given_near_and_far(
if (t_far < 0) {
return 0;
}

/* if t_near > t_far, ray doesn't intersect AABB */
if (t_near > t_far) {
return 1;
return 0;
}

return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions libs/mli/src/mli_ray_grid_traversal.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ int mliAxisAlignedGrid_find_voxel_of_first_interaction(
mliRay_aabb_intersections_is_valid_given_near_and_far(
ray_parameter_near, ray_parameter_far);
if (has_intersection) {
struct mliVec inner =
mliRay_at(ray, ray_parameter_near);
struct mliVec inner;
inner = mliRay_at(ray, ray_parameter_near);
(*bin) = mliAxisAlignedGrid_get_voxel_idx(grid, inner);

if (bin->x >= grid->num_bins.x) {
Expand Down
2 changes: 1 addition & 1 deletion libs/mli/src/mli_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define MLI_VERSION_MAYOR 1
#define MLI_VERSION_MINOR 9
#define MLI_VERSION_PATCH 8
#define MLI_VERSION_PATCH 9

void mli_logo_fprint(FILE *f);
void mli_authors_and_affiliations_fprint(FILE *f);
Expand Down

0 comments on commit 446439d

Please sign in to comment.