Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6954881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:39:53+00:00 2026-05-27T14:39:53+00:00

I’m looking at this code from Game Physics Engine Development for a BVH traversal

  • 0

I’m looking at this code from Game Physics Engine Development for a BVH traversal algorithm, specifically getPotentialContacts and getPotentialContactsWith at the end of the file.

By the looks of this algorithm, it’ll compare an initial pair of siblings, but it won’t look for collisions within each descendant.

I can’t see how this would work on a graph like this one, where dotted lines represent branches, solids are leaf nodes, and the tree depths are represented by spectrum colors (red, orange, yellow, green):

BVH problem

What is it that I’m not understanding here? Do I need another algorithm to find all the contacts within a tree?

I also tried traversing down each of the leafs, but then I end up detecting the collisions twice in many cases — so that’s not it either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:39:54+00:00Added an answer on May 27, 2026 at 2:39 pm

    I was having the same problem with this function… so I tried a few approaches and I ended up with this:

      private  int getPotentialContactsWith(
             BVHNode other,
            Vector<PotentialContact> contacts,boolean descend) {
    
          int count=0;
          //System.out.println(id+" comparando com "+other.id+" contacts.size:"+contacts.size());
          checks++;
          // Early out if we don't overlap or if we have no room
          // to report contacts
    
          if ((descend) && (!isLeaf())) {
             count += children[0].getPotentialContactsWith(
                   children[1], contacts,descend);
          }
    
          if ((descend) && (!other.isLeaf())) {
             count += other.children[0].getPotentialContactsWith(
                    other.children[1], contacts,descend);
           }
    
    
            if(!overlaps(other)) return 0;
    
    
    
    
          // If we're both at leaf nodes, then we have a potential contact
          if (isLeaf() && other.isLeaf())
          {
              if (!alreadyInside(body,other.body,contacts)){
                  PotentialContact contact=new PotentialContact(body,other.body);
                  contacts.add(contact);} else {errors++;}
              return 1;
          }
    
    
          // Determine which node to descend into. If either is
          // a leaf, then we descend the other. If both are branches,
          // then we use the one with the largest size.
          if (other.isLeaf() ||
              (!isLeaf() && volume.getSize() >= other.volume.getSize()))
          {
              // Recurse into ourself
              count += children[0].getPotentialContactsWith(
                  other, contacts,false
                  );
    
              // Check we have enough slots to do the other side too
                  count += children[1].getPotentialContactsWith(
                      other, contacts,false );
          }
          else
          {
              // Recurse into the other node
              count += getPotentialContactsWith(
                  other.children[0], contacts,false);
    
              // Check we have enough slots to do the other side too
                  count += getPotentialContactsWith(
                      other.children[1], contacts,false
                      );
    
          }
    
    
          return count;
        }
    

    ////
    About the code:
    Well, its in java but I guess its easy to translate or understand what it is doing.
    I created the function “alreadyInside” to check if I already added the potential contact and I was increasing the variable errors if I did, so far this code is not adding any repeated potential contact (errors=0), so I will problably drop this function to optimize the code.
    Also, I added the “descend” parameter, which is a flag which tells when to go further down in the structure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.