Jump to content
  • Advertisement
Sign in to follow this  
Bladelock

is there a hitTest function in Box2D for C++?

This topic is 2479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was looking at Box2D for a while, and I was just wondering if there was some "convenient" hitTest() function (which I remember I saw from ActionScript) that could be used in C++.

Or if not, what's the easiest way to determine collision detection?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

Hi, I was looking at Box2D for a while, and I was just wondering if there was some "convenient" hitTest() function (which I remember I saw from ActionScript) that could be used in C++.

Or if not, what's the easiest way to determine collision detection?

Thanks.


I think you can. I'm fairly certain you can in farseer, which is pretty much a port of box2d to C#. Maybe check in Fixture? I think that's where Raycast is, and they seem like they should be close to each other.

I would be more curious why you need to do this. The way Box2D is set up should give you access to all the hits that are found after it does it's collision test. Seems like you're probably using the API incorrectly if you have to check for hits again after you have tested for hits.

Share this post


Link to post
Share on other sites



I would be more curious why you need to do this. The way Box2D is set up should give you access to all the hits that are found after it does it's collision test. Seems like you're probably using the API incorrectly if you have to check for hits again after you have tested for hits.


So how would the simplest Box2D collision test look like in code (even in pseudocode)?

Share this post


Link to post
Share on other sites
The way Box2D works is, you set up your physical world, describe the properties of your physical objects and then add those objects to the world. The only thing you have to do after that is call the step function of the world at regular intervals to drive the simulation. Box2D performs all the collision detection for you. If you want to know when a collision happens (other than just witnessing it on the screen) you can set up one of more listeners. A listener is a class with a special function that is called every time an event, such as a collision, happens inside Box2D.

I hope this helps, and I hope I got it right, it's been a while since I used Box2D.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!