You blew my mind just by this 23:16 Didn't know that was posible. Holy moly. I had never used the | operator that way. Very muchas gracias, you are the best.
@javidx9
5 жыл бұрын
lol thanks Yoomar, its surprising when people give feedback of things theyve not seen before, makes it all worthwhile!
@epsilonadept7301
4 жыл бұрын
I never looked at the operator in such way to be able to literally assign two values to a variable!
@Gargantupimp
5 жыл бұрын
This is fantastic. As a 2D amateur game developer I find these algorithms very tricky and even wanted to use box 2D to avoid thinking about them. I appreciate your lessons. Please teach a complete series on collision even about broad and narrow phase and about concave collision too.
@javidx9
5 жыл бұрын
lol thanks Apricot, one step at a time :D
@kalebbruwer
4 жыл бұрын
Gotta love how you wrote "Convex polygon" entirely out of concave polygons
@fuuryuuSKK
2 жыл бұрын
any concave polygon can be separated into convex polygons
@brainloading5543
7 ай бұрын
@@fuuryuuSKK **summons fractals**
@horowirtz9415
3 ай бұрын
A fractal isn't a polygon
@theycallmerye3
2 ай бұрын
the first 2 "O"s are convex on the outside.
@brdevll
Ай бұрын
@@theycallmerye3 so.... if you ignore half of the vertices they are convex, I see..
@O5MO
3 жыл бұрын
From this video i understood better what the dot product is than from other videos especially on this topic.
@gdclemo
4 жыл бұрын
There's another easy way to check for the collision of two convex 2D polygons; replace one polygon with a point, and the other polygon with the morphological dilation of one polygon by the other. Then the intersection test can be reduced to a point-in-polygon test. The morphological dilation of two convex polygons can be easily created by taking all the edges of both polygons and then sorting them into clockwise order by angle, then reconnecting them in that order. I don't remember the name of this technique but it works very well.
@nebojsazakic
5 жыл бұрын
Optimal is a boolean. More optimal and the most optimal are just optimal. Thanks for the video.
@quillaja
5 жыл бұрын
Have you looked at the GJK algorithm at all? It's a very nice algorithm which can operate on convex polygons, lines, points, and even mathematically 'perfect' shapes (like a circle, ellipse, etc)... any non-concave shape that can implement a "support function" that provides the "farthest point in a given direction". Essentially the algorithm "subtracts" one shape from the other and determines if the resulting shape (minkowski difference (sum)) intersects with the origin. If so, the shapes intersect. The end result of the GJK is also a convenient starting place for the Expanding Polytrope Algorithm (EPA) for collision resolution.
@lucaxtal
5 жыл бұрын
Really great explanation and clean code.
@viniciusschadeck4992
Жыл бұрын
my brain is hurting... i not sure if it is because i'am programming on javascript, and trying to understand and convert to it, or the math is enought to brick my mind already LOL i got all lines from both my polygons, but going forwards looks impossible rightnow... i will try make it 1:1 first... those really heavy math part are tricking me, if i not wrong your video from line to circle detection was easier to reproduce LOL Just update here, it worked! i not know exactly how it work, dude i have a totally different language and code base, mine structure uses lines not points and i adapted to run all lines and only get startpoint of those... also i did only one function and then make another function to call it with reverse polygon paramters soo it test both ways... in the end it worked!!! man i hope this not burn down cpus when people play my game, looks like a lot of tests per logic cicle, also i need to check circle with polygons and line with polygons too now LOL it will be another day
@Urre5
5 жыл бұрын
Superb video as always! Isn't it called "separating axis theorem" rather than "separated" though? Since you're looking for the separating axis, the axis isn't separated.
@badwrong
3 жыл бұрын
For some reason I can't get the overlap value to work. When I debug the value I'm getting for overlap its always a negative number if overlap isn't happening or its 0 if they are overlapping.
@TheGios100
5 жыл бұрын
Hey Javidx9 do you have any youtube channel that you recommend?
@shrutichakraborty1309
4 жыл бұрын
Is it possible to use this theorem to find the area of intersection between two shapes?
@giancarloandrebravoabanto7091
5 жыл бұрын
welcome to the matrix
@villelind7875
5 жыл бұрын
Do a mario kart tutorial :)
@javidx9
5 жыл бұрын
Checking out my psuedo 3d planes tutorial would be a good start! 😉
@villelind7875
5 жыл бұрын
Thanks! :)
@matanmigdal7108
5 жыл бұрын
any gjk and epa tutorial?
@avvvqvvv99
5 жыл бұрын
is a concave shape possible by thinking of it as being made of convex shapes?
@bubuche1987
5 жыл бұрын
Yes, and it's the approach generally used (=split the concave into convexes). However, it's not trivial to split it. Long times ago, I tried to tesselate doom sectors. Basically, a doom sector is defined by a set of lines. Each line has two side, and each side tells which sector it is facing. This define the shape, and it can not only be convex, but also concave, or with holes, or be in multiple pieces not connected at all etc. Three connected points with a valid angle may still not form a valid triangle. You can have a triangle with a "nick" on a side (ok, it's not a triangle. It's to hlpe you visualize it. Draw a triangle ABC, put a "tooth" on the side CA -> When you go from A to B and from B to C, everything seem fine. To find that you cannot make a triangle from ABC, you'll have to go farther. And the tooth can come from actually very far in the polygon. The other case. Take your triangle with a nick (ABC, a nick on CA). Pull the nick to A, so you split the triangle in two. Still AB BC looks ok, and now there isn't even a nick to detect. It's easier to draw than to describe. I had to tacle with this kind of problems XD Note that once you have a tesselation of your not-convex polygon, it's easy to group triangles into convex polygons (=it is easy to detect if adding a triangle to an existing convex polygon would make it not convex).
@avvvqvvv99
5 жыл бұрын
@@bubuche1987 great comment, thanks let me just get a sheet of paper and try to understand it
@bubuche1987
5 жыл бұрын
Here is an image I made some time ago jme-hub-cdn-jmonkeyengineor.netdna-ssl.com/uploads/default/original/2X/7/74d15c97e38c725b6b2ab8495ce304d8c462c2d0.png If you want I'll make a picture tomorrow to illustrate my message. But it is really not a big deal. About the "nick" problem : take the image on the first column, third row. If you follow red arrows you may consider that it is a valid triangle (the angle is ok). But it isn't. Or if you look at the third column, first row : everything seem fine from the point of view of the red arrows, but it isn't.
@bubuche1987
5 жыл бұрын
@@avvvqvvv99 Ok, I tried to do something i.imgur.com/7pc185O.png The first is the "triangle with a nick" (a tooth, I don't know the english word). The second (the very big one) is to illustrate that the "nick" can comes from very far in the polygon. If you iterate on sides, it's not enough to just check the next side, or even n next sides. The last image (two triangles connected) is a degenerated form of the tooth. Because now there isn't any tooth at all, there is not point in the "triangle formed by A B C". There is no point to trigger a "ABC contains an other point, it's not a valid triangle". Still, it's not a valid triangle. I hope it helps to understand my first post.
@mistervoldemort7540
5 жыл бұрын
How about making a game within a game. Just kidding
@javidx9
5 жыл бұрын
Gameception, you gotta go deeper
@ApertureCombine
5 жыл бұрын
It's insane how much this channel aligns with my personal interests. Synthesizers, mazes, 3d rendering, splines, line of sight, and now collision detection are all things I've done short projects with just for fun in python. Seeing them here and reading the code helps me both get better with C++ and further my knowledge on these topics. Your explanations are also incredibly useful (particularly of all the math which is often glossed over), so thank you so much. :)
@javidx9
5 жыл бұрын
lol Aperture thank you very much!
@punkisinthedetails1470
4 жыл бұрын
It's nice to see them in C++ after py overload
@punkisinthedetails1470
4 жыл бұрын
after watching countless well meaning but lightweight channels finally found THE channel.
@delofon
4 жыл бұрын
Aperture Combine... OH NO
@Mannershark
5 жыл бұрын
For the diagonals method: What if you have a large first polygon, with a small second polygon inside it, where the second polygon is placed such that it does not intersect any of the diagonals of the first polygon. Then, it will report them as not intersecting, even though the second polygon is completely contained. The diagonals method is good to avoid objects from colliding, since it will always find cases where edges are intersecting. For small fast moving objects there may be issues though.
@mohammedj2941
4 жыл бұрын
Isn't it perhaps straightforward though to avoid this problem by checking if any vertex is inside the other polygon?
@JamesSmith-fg8hp
4 жыл бұрын
@@mohammedj2941 In this case the pulling-out algorithm will behave fairly unpredictable. Imagine that you already have one shape inside another after an update of a window. In what direction should you pull the inner shape? It is doable, but it doesn't look like an easily-maintainble approach to this specific problem.
@tungdoan380
4 жыл бұрын
for your case the maximal project on arbitrary edge of large object will also contain the maximal project of small object. So it contains the other (special kind of intersection)
@omarator
4 жыл бұрын
You could always do a fast bounding sphere test small and if the circle/sphere is fully contained in the bigger one then use the SAT otherwise use DIAG. You can also use this test for early broad phase.
@guy-dev
3 жыл бұрын
Hey Javidx, I don't use C++ (I'm mainly a Java dev) but I want you to know that your videos help me out so much as an aspiring game developer. You basically single handedly got me out of tutorial hell and taught me so many useful game development skills, and I am very grateful for your videos.
@ДенисОлегович-ф8д
5 жыл бұрын
Super! Thanks for explanation! You are the best coder in KZitem!
@javidx9
5 жыл бұрын
Glad I can help buddy!
@victornaut
3 жыл бұрын
This has got to be the best explanation of any subject I've came across in my entire lifetime.
@zanzaraloggan3713
5 жыл бұрын
you're like the Daniel Shiffman of C++ :D
@5daydreams
4 жыл бұрын
No, Shiffman is javidx9 of js
@neillunavat
3 жыл бұрын
@@5daydreams hehe. Javidx9 is bob ross of c++
@VanillaMidgetSSBM
5 жыл бұрын
It's been a whole....Month or so, BUT NEVERTHELESS I'm glad we got Collisions out of the way so now we can make cool stuff! *Also first*
@javidx9
5 жыл бұрын
Two weeks!
@hugobreno1816
5 жыл бұрын
definitely you are the best bro. Keep it on.
@javidx9
5 жыл бұрын
Thanks Hugo, I will!
@seebaastian
5 жыл бұрын
As always you did a very clever explanation. Are you a teacher? because you have a very good way to explain to the other mortals like me how things must be done. I'm not a native english speaker but I can understand you very well because your pronunciation is very accurate and your pace is perfect. Keep like that and thank you so much!
@javidx9
5 жыл бұрын
Hi Sebastian, Im not a teacher but I have taught in the past, mainly to non native english speakers, so I guess I adapted. Thanks man!
@prank855
5 жыл бұрын
Will you be going over stuff like quad-trees or other optimization techniques?
@javidx9
5 жыл бұрын
Hi Prankster, maybe, but probably not in the context of collision detections. I do like a good quad tree though :D
@Ganerrr
4 жыл бұрын
welp, time to start learning about dot products because this is like wizardry, like i know how this works and such but my methods take like a page of trig just... bruh it's so CLEAN why are you so good at code
@davidecalaminici2937
3 жыл бұрын
Great stuff, really! it's possible to scale the polygons? You can rotate the and move the polygon, but it's possibile to scale those? Could you please update the function adding the scaling capability? I tried this way "s1.o.push_back({ 30.0f * cosf(fTheta * i) * scaleFactor, 30.0f * sinf(fTheta * i)*scaleFactor })" but i'm not an expert in math... Moreover, the update position part and the collision part should take care of the scaling too.
@Hsubetakevol
5 жыл бұрын
Sir, I can't program in c++ (yet), but your videos are very useful for other programming languages too. Because of your didactic skills, I can translate it to the programming languages I'm familiar with. Awesome. Thank you.
@javidx9
5 жыл бұрын
Thats great to hear! I do try and write the code to be as accessible as I can, and people do have success taking the ideas and using other languages. Thanks!
@toxiccan175
5 жыл бұрын
Not sure why this has dislikes. Maybe somebody lost their hands and can't follow along... :'(
@javidx9
5 жыл бұрын
lol thanks Toxic, I dont mind so much, people can dislike things for all sorts of reasons :D
@thefoolishgmodcube2644
5 жыл бұрын
Don't worry, it's just one lone troller
@ratchet1freak
5 жыл бұрын
diagonals isn't perfect, if a smaller polygon is fully inside the triangle formed by 2 diagonals and the side. So it is not a perfect overlap test. Another good collision test for convex shapes is the jgk algorithm. Often very poorly described though.
@javidx9
5 жыл бұрын
Hi Ratchet, true about the small shapes, but it has to get inside first, and the diagonals of the smaller shape would not allow that to happen.
@BanzayIkoyama
5 жыл бұрын
@@javidx9 Assuming your small shapes move slower per frame than their size of course. Otherwise they can just jump in. An edge case to be sure, but a case nevertheless. Edit: Also let's not forget that depending on the application you may not actually want to displace the objects based on whether they overlap or not, just know whether they actually overlap or not. So it can also fail there.
@SleepyHarryZzz
5 жыл бұрын
@@BanzayIkoyama heh, "edge" case. Nice.
@ratchet1freak
5 жыл бұрын
yeah but tunneling is an issue and is easier when you only need to pass a single line. SAT and JGK both don't allow that kind of overlap
@javidx9
5 жыл бұрын
Lol you are quite right of course, if the step per frame permitted this. You can mitigate against this with a more sophisticated trajectory system like I did with the balls collisions examples though. However none of these systems are infallible.
@chriswinslow
5 жыл бұрын
I’m don’t know about others here but I can listen to this all day. Well done for this top video. You’d make such a good teacher and any pupils would be so lucky to have you teaching them coding.
@javidx9
5 жыл бұрын
Thanks Chris, Im trying a bit harder with vocal clarity this year so Im pleased its being picked up on!
@TheSharkasmCrew
8 ай бұрын
Thank you greatly for the video and code samples. I tried implementing these algos into my own system, and while the simple detection versions of SAT and diagonals worked perfectly, I was seeing some buggy behaviour when using the statically resolved versions of both. After trying many things, I tried normalizing the projection axis in SAT and that instantly solved the problem (my overlap values were way over inflated). The code sample says the normalization is optional, so I'm not sure if I have something else off in my code, but I just thought I'd drop that here in case anyone else has been going through the same thing.
@abhay_more
8 ай бұрын
Yeah, I went through the same experience, and this was actually helpful. However, for me, the second version, static diagonal intersection resolution worked just as shown in the video. What specific behavior did you encounter for the 2nd one?
@kaede_elfen
5 жыл бұрын
You are a blessing from god to all programmers, all your videos has really great explanation and quality. You are the best coder I've seen and will be the best coder I will ever see. Thanks for this video but I wonder something, I know it's really complex but are you willing to make a "dynamic resolution" tutorial for convex polygons?
@javidx9
5 жыл бұрын
Thanks you k4dir, that means a lot! Im thinking about doing dynamic responses, I may do a crude version for my top down car game, and then I would likely extend it to include angular momentum and velocities, but its gets complex fast!
@minhcaohuu3691
3 жыл бұрын
thanks bro ;))) (nice stickman 8:04 btw)
@binary_gaming113
5 жыл бұрын
Good video. Will you also do concave polygons?
@javidx9
5 жыл бұрын
Thanks Erazor, maybe, the naive approach is to partition your concave object into groups of convex objects and do the same.
@stumbling
5 жыл бұрын
"the naive approach is to partition your concave object into groups of convex objects and do the same." Ah, that was going to be my naive question. :)
@Otakutaru
3 жыл бұрын
I think, depending on the number of collisions vs number of polys, you'd want one algorythm over the other. SAT exits early if there's no collision, DIAG exits early if there's collision. So, DIAG will exert maximum load when there aren't any collisions, and reduce the number of needed checks as new collisions occur (nice byproduct in my opinion, very useful since that saved time can be used to actually resolve the collision).
@cheako91155
5 жыл бұрын
GJK: kzitem.info/news/bejne/squm16lnsZdofKQ
@teeboh99
3 жыл бұрын
I can’t believe I’m only just finding your channel. I’ve been the type to just have a go at something without doing any research first (which can be fun at first, but quickly becomes tedious) thank you for making these videos, I really appreciate them
@hexhackbangla8368
5 жыл бұрын
thanks a lot , i was searching for this kind of video
@javidx9
5 жыл бұрын
Hey no problem noman, thanks!
@floriansteinmann5419
3 жыл бұрын
can u pls also make one for 3d games?
@ragedprogrammer3952
3 ай бұрын
Im using this SAT algorithm to detect the collision before mapping it to screen space, so I have a [-1,1] x Axis and [-1,1] y Axis. And some of my figures are negative x or negative y or both, or both positive, however this algorithm is only working when the collisions occur in the positive subspace (all of the intercepted polygon points are x positive and y positive) Do you know why this happen? Or How can I fix it?
@JackTheSpades
4 жыл бұрын
About the only problem I can see with the static diagonal approach is if you tried to put the pentagon between the square and triangle and then use the triangle to push it into the square. If I understood things right, it would resolve the pentagon/triangle first, pushing the pentagon into the square and then resolve the pentagon/square pushing the pentagon out of (and back into) the triangle. A possible solution from the top of my head would be use two loops of intersection checks. One forward and one backwards, thus swapping the pushing priority. So first T pushes P into S, then S pushes P back into T. Now the backwards check has P pushing T away.
@DeafMan1983
10 ай бұрын
Wait, are you a real Flash Programmer with flacc ( successor of gcc with Flash ) I remember that Nape Physic Box2d. Is it correct or wrongly? Because I feel like you were developed Physics 2D collision at Flash Player 9 or 10 ? Right? I never forget that like triangle, quad, circle etc...
@marmoripelaao9830
4 жыл бұрын
Haha, a couple of months ago I thought like: I need nothing like this. However, now I am VERY glad that I found the video again. Thanks!
@Saleca
18 күн бұрын
In sat if theres only 2 shapes we can check only the one with less sides, or not? If there is no overlap we are good, i am assuming if a triangle doest overlap a dodecahedron the latter wont overlap the first unlike with the diagonal algo as you prooved you need tou check both
@ibemper1850
4 жыл бұрын
i was looking for a collision detection for my game, and I came up with a one that is complicated and in theory should work, but in code it doesn't. thank you for introducing me to AABB
@klaus-udokloppstedt6257
Ай бұрын
little optimization for the diagonal method: instead using an additional center point to build the diagonals, one can use one of the polygon corners. this reduces the required intersection calculations by the number of edges of both polygons.
@yosworld-v6v
Жыл бұрын
Hi javidx. This video is very useful to me. But there is problem you didn't mentioned in this video. And the problem is collision detection in high speeds will break up. Becuse speed is teleporting and not walking so it might not touch the other object and walk through it. This problem can be solved by splitting the steps. But how much must i split it ?? For the best experience i must split it to one pixel. Like if my speed was 10 i will make it walk 1 pixel each time using for loops. So by this i will check for collision 10 times each time i walk. This might reduce the fps and the performance. So i asking you if there is any other solution other than splitting. Like an algorithm to check if this object will collide in future or will collide if it walks in this way.
@Johannes00
3 жыл бұрын
Jurassic Park: Trespasser, used an invisible square box for player movement. It was attached at the base of the character model, rolling around every which way based on the terrain underneath it. Wonky!
@5daydreams
2 жыл бұрын
Looking at the source code I can see that the collision check runs once for each polygon, but... I think I am not yet sure why?? I have rewatched the bit where javidx9 adds the code, but he glossses over it, I think? Or I cant pinpoint where in the video does he explain why to loop over both polygons :c
@carlphilippgaebler5704
3 жыл бұрын
I won't write a formal proof of the diagonals method... but consider: For two convex polygons to intersect, one of them must have a vertex inside the other polygon. They can't intersect otherwise. So... the moment the vertex enters the other polygon... the diagonal FROM that vertex must now intersect the edge that the vertex just crossed.
@abandoned7501
5 жыл бұрын
1:02 pacman
@TheMerioz
Жыл бұрын
wow that's is really helpful. I am actually working on a robotics projects and this video is really to the point. I was just wondering if this code can be used with matlab.
@racorescript
5 жыл бұрын
Hey man. Great video as usual! In case you are suffering of some kind of lack of inspiration for future videos, please let me suggest you a topic :) What about a video to explain a good algorithm for bounding boxes occlusion culling done on the CPU side? I'm currently working on a project where I'm using occlusion queries on the GPU. They work well but, as you surely know, the query result becomes available only after a few frames and it causes sometimes objects to appear on the screen with a little delay (especially if they move fast). A nice prepass done by the CPU to compute which AABB are visible before to actually render the objects would solve lot of my problems (even better if the alghoritm can run at a decent speed, say... less than 5 msec). I think this would be a good topic for a future video and it may also be a nice addition to your 3D engine... right? :P Joking aside, please forgive if I allow myself to give you a suggestion, but, judging by your past videos, you look like the perfect guy to explain such a complex topic with your usual clarity and effectiveness. Keep up the good work.
@javidx9
5 жыл бұрын
Hi and thanks Razie, Im always open to suggestions! Im hoping to expand on the 3D engine a bit, I had not considered BB occlusion culling, so I'll look into it!
@racorescript
5 жыл бұрын
@@javidx9 Hey javidx! Thank you for answering. It´s a nice topic still with no clear solution. I hope you'll find it interesting. Enjoy
@TheWeirdo879
4 жыл бұрын
I've discovered a problem with the diagonal method. If you have a shape completely inside of another much larger shape, it's possible for them to not detect any collision. If a shape can't get inside of another this isn't a problem, but it is important to note that method isn't perfect. On another note I think I've come up with another. You could measure the angle of every vertex on one shape with the every the angle of every vertex on another shape. If the angle from every vertex on shape A to one angle on shape B is between the angles to the two connected vertexes on shape A, then that vertex on shape B is inside of shape A. Using actual angles involving trig functions seems too inefficient, but calculating the slope seems easy enough. I'll have to do some math or run some tests to see if it's worth doing at all.
@delofon
3 жыл бұрын
So sad that this is just static SAT. If only this implementation had some more obvious ways of pulling the contact points just to combat me being brain dead :(
@TimothyChapman
4 жыл бұрын
What would happen if you had two polygons that clearly overlapped, but none of the vertices of any polygon was inside the other polygon?
@xeridea
2 жыл бұрын
I've got my pentagon, and I'm going to try and crash it into the quadrilateral. Likely this statement would only be interesting to a programmer.
@xM0nsterFr3ak
5 жыл бұрын
hey you could use this in your top-down city based car crime game... i wonder where i got that idea from ;)
@munteanionut3993
5 жыл бұрын
This channel is really cool !!
@javidx9
5 жыл бұрын
Thanks Muntean!
@KDSBestGameDev
2 жыл бұрын
Die diagonals isn't robust. Since you can hide a polygon fully in the other one, where no diagonal will hit it.
@baphnie
3 жыл бұрын
8:15... the light is transmitted globally in a single direction... along the side of the triangle, right? You wouldn’t have the second blue dot then.
@AndroidsReview
4 жыл бұрын
Is it improove perfomance if for each polygon create box that contains this polygon in any rotation in it, and first check is this boxses intersects, and if true only then check intersection with polygons?
@ИапГоревич
Жыл бұрын
I really thought about SAT in 9 grade! It is so intuitive, but i did not know, how to proof the statement
@PumpReactivationProject
5 жыл бұрын
Wooow this tutorial is so informative and so easy to understand. Thank you for that!
@javidx9
5 жыл бұрын
Im pleased you found it accessible PRP! Cheers!
@cursedfox4942
Жыл бұрын
damn guess ill go have to look at the theroms this is a bit high level and in c++ instead of c but i already kno that since i watch you all the time but i know c and I get the concept but am not sure of c code
@captainbanglawala2031
2 ай бұрын
I don't understand how the line segment intersection test code works. Is it magic?!
@stenacher
4 жыл бұрын
Unfortunately, Diag method is not really working for long rectangle forms.
@skylersmith8696
4 жыл бұрын
"I'm no good at drawing straight things on the screen" Me tooooooo!
@SonictheHedgehogInRealLife
4 жыл бұрын
Y’all draw gay things instead on screen
@jumhig
4 жыл бұрын
I think you can do concave poly collisions by breaking the concave poly into 2 or more convex polygons.
@miguelmejia3235
4 жыл бұрын
This is amazing! Also, I lost it at 36:04
@fj12n3
3 жыл бұрын
Dude you are such an amazing person, thank you for making all these insanely high quality videos!
@tanan8116
5 жыл бұрын
I wish I could like this video thrice
@tanan8116
3 жыл бұрын
@@delofon Thrice is an actual word, plus, triple doesn't actually fit in the sentence. Same way as you wouldn't say "I wish I could like this video double", you don't say "I wish I could like this video triple".
@zleapingbear
5 жыл бұрын
Great video. Helpful. Also, thats a fast video output currently :)
@javidx9
5 жыл бұрын
Thanks zleapingbear, yeah went well this one XD
@zleapingbear
5 жыл бұрын
@@javidx9 thats always good. Just a tough about the diagonals methode, Would it not be a bit more computional optimize to do the same line intersection, but with edges only? (so all edges of P vs all edges of Q) Also, using edges i guess would allow you to test concave polygons with the same algorithm. (for intersection only, not the "move back" function)
@EmmittBrownBTTF1
5 жыл бұрын
Can a concave polygons be converted to convex polygons by drawing lines from vertices with theta>180 to neighbouring vertices until all divisions are convex.?
@javidx9
5 жыл бұрын
There are a few techniques to do it, ultimately if you represent the structure as triangles then all the primitives are convex
@PleegWat
4 жыл бұрын
I think your diagonals approach can return a false negative (incorrectly not detect a collision) if a smaller shape is entirely contained within one 'pie section' of a bigger one (between an edge and its two diagonals).
@javidx9
4 жыл бұрын
You are correct Pleeg, but you could argue they must have previously collided to be in such a state. Though this depends entirely on the rest of your set up of course.
@delofon
3 жыл бұрын
I have implemented ShapeOverlap_SAT_Static, but shapes upon colliding are displaced way farther than they should. Multiplying the displacement vector by fElapsedTime looks like a workaround, but if there is something crazy like 257-gon then it is not: without fElapsedTime, collisions with 257-gon work great, with fElapsedTime, the displacement is very slow. Help! Additional info: this was programmed on C# with MonoGame framework.
@delofon
3 жыл бұрын
Fixed: apparently, the axisProj *must* be normalized. Weird that I didn't think of that first, but what's even more weird is that everything worked perfectly in the video (which is probably why I didn't think of normalizing the axisProj in the first place. Oh well)
@federicocaputo3989
2 жыл бұрын
8:34 love how he draws the other vertex that generated the parallel line as a different point when mathematically they are the same
@Saleca
18 күн бұрын
Well spotted 😅
@NeilRoy
5 жыл бұрын
I always use an even simpler method to test for AABB in 2D, and that is not to test if they overlap, but instead, to test if they do NOT overlap like this... if (Px+w < Qx) no overlap, return false for collision if (Px > Qx+w) no overlap, return false for collision if (Py+h < Qy) no overlap, return false for collision if (Py > Qy+w) no overlap, return false for collision That's it! IF all of these tests fail, than we absolutely have a collision and can deal with it. But these tests will return false the moment any one of them test positive as it will be impossible for there to be a collision in any of these four cases. Much simpler than testing for overlap.
@javidx9
5 жыл бұрын
Hi Neil, yeah there are loads of early rejection optimisations I think its important for programmers to try and implement for lots of algorithms.
@123eee555
5 жыл бұрын
Awesome video! Thanks so much! The math of this had been giving my trouble for a while.
@javidx9
5 жыл бұрын
Hey no problem Nimbiz, thanks!
@JakeND
10 ай бұрын
Gotta love that the video has 20k more likes than it has views
@pjh777
5 жыл бұрын
Just to add that 'diagonals algorithm' won't detect a collision if you place a smaller polygon in a bigger one in such a way that it doesn't intersect any of the 'diagonal' lines
@javidx9
5 жыл бұрын
Hi Pjh, the smaller one would need to enter the larger one first, and its diagonals would stop that from happening
@pjh777
5 жыл бұрын
@@javidx9 For small 'deltas' that's true - ie where the delta is small compared to polygon size, but with delta's of the same order of magnitude as the polygons the smaller one can get in the bigger on in a single jump. So yes in your example where the movement is small compared to the size of the polygon there is not problem, but for a small 'bullet' polygon moving a distance greater than its size per frame it can jump inside. SAT catches fully enclosed polygons every time though.
@javidx9
5 жыл бұрын
lol, im having this conversations in two places at once XD You are quite correct, this would be an issue, but personally, I would never use this approach for fast projectiles like bullets, I'd just do a ray intersection.
@CyberMew
3 жыл бұрын
I wished this was available back in 2010..
@ScibbieGames
5 жыл бұрын
You seriously upload everything I need, every time.
@mjdev-i1p
5 жыл бұрын
I cant believe how you manage to put not only so muc effort but also so much value in each video. Sir you have my gratitude and respect. Please keep up the good work. 😊
@javidx9
5 жыл бұрын
HI Marko, thank you for such kind words, they are much appreciated, I will!
@Shadow-bc5nr
2 жыл бұрын
Thanks alot for creating this video!
@darkfrei2
9 ай бұрын
0:00 -- all this polygons are concave
@tobeypeters
5 жыл бұрын
Not perfect ... But, still wonderful. Saw the pentagon poke its corner in a pixel or so.
@javidx9
5 жыл бұрын
Thanks Tobey, the errant pixel is due to rounding error when quantising to the screen, the actual objects in the geometry domain have certainly not penetrated each other, I dont believe they can by definition. Still a good observation none-the-less. I shall be less lazy next time when extrapolating screen coordinates from floating point data :D
@alexkuzmenko8958
Жыл бұрын
still waiting for the second part...
@gabigagu6599
2 жыл бұрын
Hey javidx9, I love your videos but I have a question: I implementer the SAT in my project and it wont work. I replaced the Polygons multiple times but I cant figure out why the function returns always false.
@satarimar
5 жыл бұрын
very nice as usual! there's one computationally simpler method. simply build planes from polygon edges and then test all the vertices of the other polygon to each plane. if all vertices are in front of the plane, there's no overlap (do this for both polygons). the only problem is that this requires consistent winding. I've modified your code to replace plain SAT with this method (had to flip winding for triangle and n-gon): gist.github.com/kmar/92f5e813253bfac8f2979231b6af9980
@javidx9
5 жыл бұрын
Thanks satarimar, I like that there are a variety of techniques. It would be interesting to try them all side by side. Each has advantages and disadvantages so choosing the right one is important.
@satarimar
5 жыл бұрын
@@javidx9 when I think about it, the (signed) distance from a plane is actually pretty much what you get in SAT by projecting along edge normal. it's possible that those methods would actually boil down to same thing. Oh and the planes can be precomputed and transformed along with poly's vertices, so the normalization in inner loop could be skipped. Anyway, thanks for your videos, it's always a source of inspiration, looking at certain problems from a different perspective, learning something new and also food for thought.
@benstech726
3 жыл бұрын
For aabb approach easiest method I found is getting min of both cubes' maximums and max of both cubes' minimums. If cube min < cube max the. Collision exists and the mins and maxes per axis gives the overlapping area. So min(cube1Max, cube2Max) max(cube2Min, cube2Max
@JackieSL9
5 жыл бұрын
What kind ofmonster dislikes these vids?! Thanks Javid for another great video.
@javidx9
5 жыл бұрын
Cheers bari!
@bpark10001
3 жыл бұрын
Do you want to address a more challenging, but related problem? Do tool path calculation (find vector trajectory of the center of a circle that maintains contact with CAD elements as it traces around them. CAD elements include line segments of width W, arcs of width W, and polygons (may be concave). CAD elements may be overlapping or disconnected. "Clean" CAD files (with elements perfectly connected) cause the most trouble!
@jursamaj
2 жыл бұрын
2:05 Just a note: if knowing that 2 shapes *don't* intersect is sufficient (not distance between them) then the AABB check is still useful and fast. In most applications, even for shapes that aren't axis aligned rectangles, your shape storage probably has their AABBs anyway (altho you don't do this in your examples). If the AABBs intersect, then you can go on to use a deeper method to find out if the shapes actually collide. For very simple shapes (few edges) pretty much any test method will be about equal. For larger number of edges, there is a pretty standard method called GJK, which is highly efficient. I can see this being a good exercise for a budding programmer. But ultimately, the game dev is probably wasting their time by not using a library for this.
@NeZversSounds
3 жыл бұрын
This gave me many ideas for making my own simple collision libraries. I've been wondering for a long time what's behind the old top-down GTA collision solving with rotation.
@dercoder2057
5 жыл бұрын
Hey javidx9, I have a question. At minute 26:40, the displacement of the object is calculated. Actually, the moving object would have to stop at the same place as before the colliding (It would be no gentle but a jerky motion). However, it moves so very smooth and fluid over the edge. Can you explain that to me. Yours sincerely Lukas
Пікірлер: 277