Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PolytopeIntersector.cpp #1345

Merged
merged 1 commit into from
Dec 24, 2024
Merged

Conversation

jamierobertson1
Copy link
Contributor

In the PolytopeIntersector constructor with screen coordinates, the eyespace polytope should also be placed in the polytope stack before the worldspace polytope (In the same way as in the LineSegmentIntersector constructor).

Pull Request Template

Description

Change is to to also add the eyespace polytope to the polytope stack before the worldspace polytope

Fixes #
The omission meant that intersections were not calculated properly for nodes under MatrixTransforms.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Can be tested by modifying the vsgintersection example default box creation to be under a MatrixTransform as follows:
(wont work without the change)

    if (scene->children.empty())
    {
        vsg::GeometryInfo info;
        info.cullNode = true;
        info.dx.set(100.0f, 0.0f, 0.0f);
        info.dy.set(0.0f, 100.0f, 0.0f);
        info.dz.set(0.0f, 0.0f, 100.0f);
        auto box = builder->createBox(info, stateInfo);
        auto transform = vsg::MatrixTransform::create();
        transform->matrix = vsg::translate(vsg::dvec3(1000.0, 1000.0, 1000.0));
        transform->addChild(box);
        scene->addChild(transform);
    }

Tested on windows

In the PolytopeInterctor constructor with screen coordinates, the eyespace polytope should have been placed in the polytope stack before the worldspace polytope (as per LineSegmentIntersector constructor).

The omission meant that intersections were not calculated properly for nodes under transforms.
@robertosfield
Copy link
Collaborator

I am starting my code review so first step was to confirm the bug and then use the PR to fix the bug, but I've fallen on the first hurdle in not being able to recreate the bug yet. I used your suggest code change, with a small tweak to allow me to toggle on/off the use of the MatrixTransform using the --mt command line option. The changes I made to the vsgintersection are:

$ git diff
diff --git a/examples/utils/vsgintersection/vsgintersection.cpp b/examples/utils/vsgintersection/vsgintersection.cpp
index 8dd028b1..17fab22a 100644
--- a/examples/utils/vsgintersection/vsgintersection.cpp
+++ b/examples/utils/vsgintersection/vsgintersection.cpp
@@ -296,7 +296,21 @@ int main(int argc, char** argv)
         info.dx.set(100.0f, 0.0f, 0.0f);
         info.dy.set(0.0f, 100.0f, 0.0f);
         info.dz.set(0.0f, 0.0f, 100.0f);
-        scene->addChild(builder->createBox(info, stateInfo));
+
+        if (arguments.read("--mt"))
+        {
+            auto box = builder->createBox(info, stateInfo);
+            auto transform = vsg::MatrixTransform::create();
+            transform->matrix = vsg::translate(vsg::dvec3(1000.0, 1000.0, 1000.0));
+            transform->addChild(box);
+            scene->addChild(transform);
+
+            vsg::info("Used transform");
+        }
+        else
+        {
+            scene->addChild(builder->createBox(info, stateInfo));
+        }
     }
 
     // create the viewer and assign window(s) to it

I can get intersections reported and shapes inserted at the correct places when I use --mt and when I don't, this is with VSG master. Thoughts?

@robertosfield robertosfield merged commit ffa0edc into vsg-dev:master Dec 24, 2024
8 checks passed
@robertosfield
Copy link
Collaborator

I wasn't testing the PolytopeIntersector when I running vsgintersection --mt, now I have tested it correcly I can reproduce the issue and the PR fixes it so I have gone ahead a merged :-)

Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants