Jump to content
  • Advertisement
Sign in to follow this  
WilkinzMicawber

Box 2d Normal Vector for the surface of impact?

This topic is 857 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

As far as I can tell from online tutorials, the normal vector returned from a collision in box2d is the shortest direction for the colliding object to go to no longer penetrate the object it ran into. What I need is the normal vector of the surface it ran into, which is the direction the wall is pointing. For example, if I run into a vertical wall from the left, the normal vector I would expect would be <-1,0>. Is there a way to access this vector?

 

My ultimate goal is to reflect a raycast so I can map the path a projectile will take with no friction. Do raycasts allow reflections in box2d/farseer? I know many physics engines do, but I don't see that capability in Farseer.

Edited by WilkinzMicawber

Share this post


Link to post
Share on other sites
Advertisement

1. Yes, and generally that would be the normal vector for every physics engine. However, it may be inverted if the wall is not treated as the first object in a collision internally. This is solved by flipping the normal. IIRC in B2D it can be acessed by requesting a world manifold from a contact.

 

2. Yes, a world has an interface for ray casts and AABB queries, and the former returns the surface normal if the ray/segment hits your vertical wall.

Edited by Irlan Robson

Share this post


Link to post
Share on other sites

Ah, so the normal value in the return of a raycast is the surface normal, not the intersection normal? I had assumed that the normal returned was the collision normal for the ray.

Edited by WilkinzMicawber

Share this post


Link to post
Share on other sites

Yes.

 

For example, if a segment hits a face of a box, then the ray cast callback will be notified with the box, the face normal, and the intersection fraction which you can derive the intersection point from using linear interpolation:

 

p = (1.0 - fraction) * p1 + fraction * p2.

Edited by Irlan Robson

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!