Тёмный

Programming Balls #2 Circles V Edges Collisions C++ 

javidx9
Подписаться 316 тыс.
Просмотров 51 тыс.
50% 1

Better Balls! This video continues looking a a circle physics based engine, and implements a more accurate method for tracking time during the simulation, and implements arbitrary edge objects that can be used to displace and deflect balls. All using the olcConsoleGameEngine at the command prompt.
Source: github.com/OneLoneCoder/Javid...
Blog: www.onelonecoder.com
Twitter: @javidx9
Twitch: javidx9
Discord: / discord

Наука

Опубликовано:

 

17 фев 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 91   
@jddk795
@jddk795 5 лет назад
This two part series about collision detection helped me a lot to improve my own collision algorithm, and understand its behavior (and bugs!!) better. The concepts covered here are directly applicable in 3D. Thanks a million, Jx9, for a series with great entertainment and learning value!
@javidx9
@javidx9 5 лет назад
Hi JD DK, thanks buddy, Its a great pleasure to hear the videos being appreciated!
@thelastdankbender4353
@thelastdankbender4353 4 года назад
This is one of the best programming tutorials I've ever seen. Excellent explanation partnered with well paced delivery. Even though it's half an hour long, it felt like 15 minutes. Well done.
@javidx9
@javidx9 4 года назад
Thanks Dankbender! :D
@danielharding3688
@danielharding3688 6 лет назад
Your videos have been blowing me away the last couple of months! Seriously amazing, thank you for making these!!
@javidx9
@javidx9 6 лет назад
Thanks Daniel - I will!
@FanbientofAmbient
@FanbientofAmbient 6 лет назад
I truly enjoy your videos. Working through these little coding examples helps me understand and break down how relatively simple coding problems like this tend to be solved. Keep up the great work! :D
@javidx9
@javidx9 6 лет назад
Hi Chad, thanks so much. It means a lot to hear that!
@chrismingay6005
@chrismingay6005 4 года назад
I've been a hobbyist on and off game developer for like 20 years now (oof) and have never quite managed to get my head around "proper" collision detection, I've read guides, I've watched videos, I've even bought books but nothing seemed to stick and I would resort to what I was comfortable with harking back to the days I messed around with Klik & Play. Honestly these two videos have helped me so much to finally get it and I look forward to using what I've learnt here with games in the future, thank you.
@aryesegal1988
@aryesegal1988 6 лет назад
Yey! Thanks for this, javid! :] Didn't finished watchin', but looks awesome so far. I enjoy physics simulations. thanks for sharing with us! :]
@javidx9
@javidx9 6 лет назад
No problem! Its a simple simulation but useful for platform games.
@FredM80
@FredM80 6 лет назад
Excellent as usually ! It reminds me "the incredible machine" too.
@spjewkes
@spjewkes 6 лет назад
That looks very cool, David. It’s starting to remind me of an old DOS game called The Incredible Machine.
@javidx9
@javidx9 6 лет назад
Yes! They look like conveyor belts. I used to love that game!
@ui6144
@ui6144 6 лет назад
thank you for generously sharing your knowledge. you are a gift, man!
@javidx9
@javidx9 6 лет назад
Hi iii, Thanks man! I believe people who are privileged/fortunate enough to have been educated well, are obliged to educate and help others.
@daveyhu
@daveyhu 4 года назад
the actual collision checking bit starts at 19:34
@linowmik
@linowmik 5 лет назад
looks very fun!
@javidx9
@javidx9 5 лет назад
It is!
@eqpurple9011
@eqpurple9011 Год назад
Nicely done! Have you thought about consolidating your other collision routines into this too? (box->box, cirlce->box, polygon->polygon etc.) ? :)
@johnjackson9767
@johnjackson9767 6 лет назад
Very nice!
@javidx9
@javidx9 6 лет назад
Thanks John!
@ynxinl2555
@ynxinl2555 4 года назад
thanks buddy, your video cure my insomnia, no offence :D
@zleapingbear
@zleapingbear 6 лет назад
Really love these videos, and especially the olc engine. These Ball videos got me thinking (and wishing) Will you at Any point cover gpu usage for multi threads, one example could be this Ball engine, but with a lot more balls and thus collisions in play? Or the game of life x huuuuuge could be an example. A multi threads and a gpu (maybe same) video would be extreemly welcommed. Regardless, thanks for the video.
@javidx9
@javidx9 6 лет назад
Thanks leapingbear! I will likely do a video on multi-threading soon (and you've put using balls as an example in my head now), but probably not using the GPU - It's a fascinating topic, but difficult to put into context in a single video, since I try to show everything.
@zleapingbear
@zleapingbear 6 лет назад
javidx9 hehe, glad to do a bit of brain worm job there. Well, Any video on multi threads would be awesome, so i will look forward to that!!!
@jonnylaw4569
@jonnylaw4569 3 года назад
So if I wanted to make the ball array able to have balls be removed as well, would I just send the balls through a for loop to reset the ID based on their position in the array? (Remaking this in java because I'm more comfortable in java than I am c++) Ex : Balls.get(3).remove(); for (int I =0; i
@sotirissalloumis6129
@sotirissalloumis6129 4 года назад
Thanks
@MissNorington
@MissNorington Год назад
I have a feeling something is off with float fIntendedDistance. It is calculated but never used. At the same time, ball.fSimTimeRemaining gets reduced by a scalar value between 0 and 1. I believe ball.fSimTimeRemaining is the actual time left and not a scalar. We need to get rid of the 4 subdivisions of time (which doesn't make any sense other than wasting CPU), and somehow combine that with the ball.fSimTimeRemaining to subdivide ball speeds to not exceed some limit (smallest radius used, or something like that). One ball might travel too fast so it should get more CPU time, while others that travel slowly can get away with one update.
Год назад
Hi. Awesome videos. I'm trying to stop "spasming" in balls. I see yours does too. Any ideas how to approach this? Can see in 1:30 they kind of twitching. For me its even worse as they pile up it gets very bad. I think it's due to gravity, but struggle to solve.
@will-ob7pr
@will-ob7pr Год назад
The equation he is using preserves momentum. Gravity is adding momentum to the system even with ground added you will get constant bounce without gravity nothing will come to a stop on the surfaces. What you need is a inelastic collision rule. Id say off the top of my head when you check for collisions between balls and the walls or ground ect. You should probably check the relative velocity's between the balls to each other if it is a very small difference and they are very close only apply the static check then set both ball or particles velocitys to be equal to each other. Ignore the bounce effect application. A more real inelastic collision is done by using momentum two objects combining into one (or sticking together will both have the velocity after collision for ball1 and ball2 = (v1 * m1 + v2 * m2) / (m1 + m2) so for example if you have ball1 moving with 1000 mass at 9 pixels per second = 9000 momentum + ball2 with mass 2000 at 0 pixels per second then 2000 * 0 = 0 so 9000 = 9000+0 then 3 pixels per second is found by 9000 total momentum divided by 3000 total mass and both objects will have that total speed in the direction of travel.
@MissNorington
@MissNorington Год назад
At 4:23 a ray (velocity) is used to intersect each other object's position, but what if those other objects are moving?
@georgeytg
@georgeytg 4 года назад
I know this is an old video, but at 22:32, fEdgeLength is supposed to be the length of the line, aka distance between edge and start points. So why isn't there a sqrt? Or am I getting this wrong and it's not the length of the line?
@andrewscott5960
@andrewscott5960 4 года назад
I was wondering the same thing. I think that it's because it gets normalized by dividing by the same value in the next line of code to get it between 0 and 1. If you have two vectors that start at (0,0) and your edge goes to (6,0) and your ball is at (3,2), the dot product is (6*3)+(0*2) = 18. Dividing by the line length (6) gives you (3), the point that the ball casts onto the edge, but dividing by 6^2 or 36 gives a normalized value of the total length of the line, (0.5). Hope that made sense.
@gnosetech5381
@gnosetech5381 3 года назад
this could help for water simulation flow (using micro balls as H2O molecules :) ), like in Algodoo, thnx for the great work...
@JaySiggz
@JaySiggz 6 лет назад
Could you please please please do a video on handling ball rotation post collisions as well as rolling on surfaces. I've been trying to find some help on this for a long time now and there just doesn't seem to be enough resources to help with it.
@javidx9
@javidx9 6 лет назад
Hi Joe, this is a good idea - I would like to do a video about angular velocity and momentum probably starting with balls, but moving to convex polygons.
@JaySiggz
@JaySiggz 6 лет назад
@@javidx9 thanks that would be so helpful. I'd finally be able to fix the rotation issues I have.
@alexsandergutierrezgoncalves
@alexsandergutierrezgoncalves 2 года назад
I really like to see math and physics in this kind of subject, that's how I learned Pythagoras' theorem, is it possible to make a rollercoaster game simulation with the math shown in the video?
@javidx9
@javidx9 2 года назад
I suppose a 2d roller coaster should be quite possible yes.
@meeharbin4205
@meeharbin4205 6 лет назад
The balls in the program I coded, couldnt pile on top of one another without flying everywhere. Iv made a temporary solution which is to lower the strength of gravity and to loop through the collision method twice. But even with that solution if i hit the balls with a ball too hard they fly everywhere and im also stuck using low gravity strength. I suspect its do do with balls constantly bouncing and colliding with each other, but i dont know how fix that without comprimising other features. Plz help, if you have come across this b4 thnx.
@javidx9
@javidx9 6 лет назад
You may need to have many iterations of collision if your dt is too large. At all costs, you must avoid the solid bodies overlapping each other. This may take several passes of the static collision part first. Also double check your displacement, ideally you want to displace balls so they just about touch. Ive seen when the simulation gets out of control, but consider that this is the result of positive feedback in your simulation, i.e. there must be something there that makes it worse each frame.
@meeharbin4205
@meeharbin4205 6 лет назад
Yeh, I found a better solution which was to do exactly as you said to iterate collision many times. However I found the main problem which was that when they pile on top of each other, the bottom ones keep intersecting despite the amount of iterations of the collsion method i put in. The bottom ones also seem to sink through the floor and pop back into the screen. All methods work if the balls are not on top of each other.
@uploadschedule
@uploadschedule Год назад
I feel like his average program is 100 times better than the best program ive ever written
@user-te4rk1td9j
@user-te4rk1td9j 7 месяцев назад
I tried to recreate it on python with tkinter but I have problem with balls sometimes being prone to "orbit" around each other when collision happens, as they go into static collision and try to push each other away but instead acting like magnets. Not sure how to fix that but great tutorial nevertheless E: I was dumb and put function call in the ball class and so it was called every single frame by every single ball instance. Now looks better but smaller balls still start to orbit around bigger ball, especially when there's multiple collision
@ZeonLP
@ZeonLP 6 лет назад
noice
@javidx9
@javidx9 6 лет назад
lol, thanks, and congratulations! you win the award for fastest youtube comment ever!
@BrekMartin
@BrekMartin 6 лет назад
Dammit! Don’t you have to watch the vid first? :D
@5cover
@5cover 4 года назад
i dont get it. Is it nice or noise
@raymondstpaul4913
@raymondstpaul4913 5 лет назад
Question how would you do this in a 3D manner?
@javidx9
@javidx9 5 лет назад
For the most part, it is simply adding a third component Z. Detecting collisions between spheres is easy enough, but the deflection angle can take a bit of thinking about
@user-ub1qz1fc9o
@user-ub1qz1fc9o 2 года назад
Hello, I saw on github that the lua version of olcPixelGameEngine has been implemented, but I didn't find lua version , where can I see the lua code?
@compositeembryo7186
@compositeembryo7186 Год назад
hey jx9, bit late to the party, but are you going to add the ability for balls to roll down slopes instead of bouncing like they do in the video?
@solarcode1841
@solarcode1841 Год назад
Setting vx and vy to 0 when creating the fake ball should solve it.
@alfredoinsigne
@alfredoinsigne 3 года назад
I would like someone who can analyze the effect of a punch of boxer on the opponent and scoring thanks
@ValeriCFBG
@ValeriCFBG 3 года назад
Interesting approach. But I think we can drop edge collisions all together..As you described the line with a radius I thought you would define two points (line) and create circles with some radius (r) at every point across the line. These circles would have a flag that disables collision displacement, so that they don't fly off when a ball hits them. The thick line, produced as a result, will have almost solid color, due to circle outlines touching/almost touching (not tested it). It is a pretty memory intensive approach, but I thought you are going with it. Anyway, great video!
@huyvole9724
@huyvole9724 6 лет назад
Oh my god
@javidx9
@javidx9 6 лет назад
Is this a good comment? or a bad comment? :D
@huyvole9724
@huyvole9724 6 лет назад
In University, you are master of Physic?
@javidx9
@javidx9 6 лет назад
Hey Huy võ lê thanks, but no. The physics here are pretty basic, turning the physics into code is harder. I like that obeying the simple laws of physics yields such a rich and complex simulation in this instance.
@john314
@john314 6 лет назад
I am a new subscriber and I love your videos! Question: Could you perhaps explain AI? It is okay if you can't but I would like to know how it works.
@javidx9
@javidx9 6 лет назад
Hi John, Cheers! AI is a big topic. I think I would need an AI project over several videos to even explain the basics - I actually have a background in AI so maybe I should do something...
@john314
@john314 6 лет назад
Okay, Thanks!
@rallokkcaz
@rallokkcaz 6 лет назад
Hey man! I'm just wondering where you learned all this stuff, is it self taught? Did you ever have a mentor?
@rallokkcaz
@rallokkcaz 6 лет назад
Your videos have opened my eyes to so many problems I've had programming. Especially with Audio and Video Games.
@javidx9
@javidx9 6 лет назад
Im self taught. Started when i was 9. Not many mentors around then. Lol 😂
@will-ob7pr
@will-ob7pr Год назад
@@javidx9 i figured awesome.
@naturegamming4348
@naturegamming4348 6 лет назад
how to programm 3D game like gta
@javidx9
@javidx9 6 лет назад
That's a really big question. There's a reason GTA takes 3-4 years development with a team of 100+ people and a budget of many millions of dollars. If we scale your question back a bit, say "How do we make a 3D game?", that's a lot more achievable. I will be making a video about 3D this year, but ultimately you need to understand vectors and matrices, some physics, and to make it look really pretty, some image processing. In short, 3D games require knowledge in several disciplines, before you even start writing code.
@artemisDev
@artemisDev 3 года назад
rockstar would've released rdr2 far sooner if these videos released before
@nolanmattson4313
@nolanmattson4313 6 лет назад
Do you have an episodes on rpgs.
@javidx9
@javidx9 6 лет назад
Hi Nolan, i dont have yet but it is coming very soon. Not next video but maybe one after.
@fghghhn5875
@fghghhn5875 2 года назад
Implemented with Python
@akarshrastogi3682
@akarshrastogi3682 6 лет назад
Is the O n^2 checking every ball ball against every ball algo working so well??
@javidx9
@javidx9 6 лет назад
Hi akarsh, dont forget that ball vs ball check is incredibly simple to do, so in this unique scenario its quite effective. There are as you mention spatial partitioning systems, but the overhead of searching may work against you for a simple setup such as this.
@akarshrastogi3682
@akarshrastogi3682 6 лет назад
javidx9 Alright, thanks for the great videos and insight you have. Please do upload/ recommend a video that utilizes quad-tree, spatial HashMap implementations etc so that we can almost make our own box2D
@javidx9
@javidx9 6 лет назад
No worries. Quad trees are definitely coming up!
@user-sw7yi9fx9b
@user-sw7yi9fx9b 6 лет назад
Why not create a vector type, and not duplicate vector code over and over? It will even be more readable
@javidx9
@javidx9 6 лет назад
If i wrapped up a vector in a type, I'd still need to interact with the type? I think I dont understand. :(
@user-sw7yi9fx9b
@user-sw7yi9fx9b 6 лет назад
I mean, math vector, not std::vector. You could have reused some code then, instead of writing those long lines for distance computation, when you could just write distance(ball.p, target.p);
@javidx9
@javidx9 6 лет назад
You're correct, I should wrap up a vector, and would do if I was working on a project, (i like glm as it happens). But I know there will be people watching this video that may benefit from seeing how the maths is implemented, and how it interacts with the algorithms.
@jonnylaw4569
@jonnylaw4569 4 года назад
i feel kinda bad now, i was re-watching this video again bc i was programming this in a different language and was listening to the concepts, and saw that i apparently disliked the video... i changed it to a like, but still
@bigmofo1122
@bigmofo1122 6 лет назад
LOL. Peoples screaming about using new while proposing a solution just as bad.
@5cover
@5cover 4 года назад
why are you using c-style casts. I think you can replace (float)x by static_cast(x)
@javidx9
@javidx9 4 года назад
its less to type and achieves the same goal?
@onuberonly7846
@onuberonly7846 6 лет назад
WARNING WARNING !!! Don't do this tutorial while you'er high!!
@rallokkcaz
@rallokkcaz 6 лет назад
K Parks Non-warning: please do it high haha.
@darkhunter777
@darkhunter777 6 лет назад
Надо было бильярд делать хД
@game_developer_7382
@game_developer_7382 4 года назад
ага)))
@code-dredd
@code-dredd 5 лет назад
Why don't you organize your code into functions?... All that scrolling for things that should be in their own smaller functions in many cases... _why_ ?
@yashenkin
@yashenkin 5 лет назад
don't use raw pointers, don't use delete operator manually. use smart pointers instead!. just smart pointers operator "new" and never explicit "delete" -- memory leak-freedom in C++. )))
Далее
Programming Balls #3 Aluminium Foil Balls!
0:46
Просмотров 17 тыс.
Programming Balls #1 Circle Vs Circle Collisions C++
32:29
All about MEMORY // Code Review
33:42
Просмотров 160 тыс.
ASMR Programming - Spinning Cube - No Talking
20:45
Просмотров 3,8 млн
Designing a Physics Engine in 5 minutes
7:37
Просмотров 151 тыс.
Programming & Using Splines - Part#1
23:56
Просмотров 92 тыс.
Procedural Generation: Programming The Universe
41:57
Просмотров 203 тыс.
Programming Perlin-like Noise (C++)
27:54
Просмотров 103 тыс.
Line Of Sight or Shadow Casting in 2D
50:23
Просмотров 142 тыс.
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
Просмотров 331 тыс.