Circle object in Irrlicht?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Circle object in Irrlicht?

Post by Scarabol »

Hey guys,

is there a circle object like line2d or point2d available?

I need to detect, if a line intersects with a 2d circle. Any ideas?

MfG
Scarabol
Irrlicht 1.7.2
Eclipse
Boost
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You can use line2d::getClosestPoint and give it the center of your circle. Then subtract the result from the center and you get a vector from the center to the closest point on the line. Then you can check if that lines length is shorter than the circle radius in which case it collides.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

Yeah right great! thx

But this method dont tell me the collision point(s).

MfG
Scarabol
Irrlicht 1.7.2
Eclipse
Boost
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

If you copy getClosestPoint from line2d.h and kick out out the 't' checks then it will no longer just return the closest point on the line-segment, but the closest point on the (infinite) line (let's call it X). X, the circle-center and each of the collision points form 2 right-angled triangles. You know the distance of X to the circle-center and the distance of the center to the collision points (the circle radius). So with A²+B²=C² you can get the length of the 3rd side of that triangle. That's the length you will have to add to X toward both directions of the line to get the collision-points.

But maybe take a look on the net, could be there's easier solutions for that (I was too lazy to google that now).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply