SFML community forums

Help => General => Topic started by: eniddelemaj on October 06, 2016, 09:15:24 pm

Title: diagonal line with collisiondetection
Post by: eniddelemaj on October 06, 2016, 09:15:24 pm
hey ,

i know how to use the getglobalbounds and intersects functions to simulate a collision
with to objects.an example would be pong. but it does only work
with straight sides not diagonal. as you know there is an invisible rectangle around the
entity and when its diagonal , there is too much space between the rectangle and the entity so
the hitbox is invalid.
now i want to make a collision detection which supports diagonal "hitboxes" too.
i looked for pixel collision detection but i read, that it isnt much effective.
are there any other ways to solve this? i didnt really found much on google about this.
thank you for your help:)
Title: Re: diagonal line with collisiondetection
Post by: DarkRoku12 on October 06, 2016, 09:54:04 pm
Global/local bounds are only the smallest RECTANGLE that can hold the shape.

If you want to implement a well defined collision system you are looking for a physics library.
If easy to set up Box2D with SFML.

Title: Re: diagonal line with collisiondetection
Post by: TCVM on October 07, 2016, 06:00:27 am
Box2d is way too powerful if you just need rotated rectangle collision, and no physics. The Seperating Axis Therom is what you are looking for. This is a good guide on how to implement it:http://www.dyn4j.org/2010/01/sat/ (http://www.dyn4j.org/2010/01/sat/)
Title: Re: diagonal line with collisiondetection
Post by: DarkRoku12 on October 07, 2016, 03:10:30 pm
Box2d is way too powerful if you just need rotated rectangle collision, and no physics.

Could be, but IMHO i find more practical learn to implement a well-known physics library that you can use in several projects than implementing an algorithm that only tells you if two shapes collides but no the point of impact and you need to debug your algorithm in severals test case before you can use it on real code to prevent odd/buggy behaviors.

Example of this: Several projects use Box2D to implement ray casting to render lights.
Title: Re: diagonal line with collisiondetection
Post by: eniddelemaj on October 07, 2016, 04:26:12 pm
okay these information helped!:)
thank you very much guys