Writing a Physics Engine from scratch

Поделиться
HTML-код
  • Опубликовано: 14 апр 2022
  • Github github.com/johnBuffer/VerletSFML
    Music used pixabay.com/music/ambient-min...
  • НаукаНаука

Комментарии • 515

  • @PezzzasWork
    @PezzzasWork  2 года назад +271

    There is an error at 3:04 at line 41: it should be (radius - 50.0f).
    Thanks to those who pointed it out to me!

    • @PezzzasWork
      @PezzzasWork  2 года назад +20

      @Vitor m the dt is not needed because here « velocity » is in fact the distance traveled since the last update so it’s already equivalent to velocity * dt

    • @ziyadcodes
      @ziyadcodes 2 года назад +12

      Me after spending 4 hours of pure suffering to figure out the problem then figuring it out and being so proud of my self. Then moving both of my fingers up to see the comment section and realizing that the first comment is addressing the problem 😭😭😭😭😭😭😭😭😭. It's even worse when I realize that I have tests and that I should have spend that time studying 😭😭😭😭😭😭. Please edit the video to save people from suffering like that. Or maybe it's just me whose that stupid |(>_

    • @TetyLike3
      @TetyLike3 2 года назад

      @@ziyadcodes sorry not sorry ¯\_(ツ)_/¯

    • @wiking2888
      @wiking2888 2 года назад

      Thank you soooo much I finally have it working

    • @oamioxmocliox8082
      @oamioxmocliox8082 2 года назад

      ;)

  • @AngeTheGreat
    @AngeTheGreat 2 года назад +160

    I like how it really doesn't take much to create an amazing looking result (as long as you know what to actually implement of course). Nice video!

    • @PezzzasWork
      @PezzzasWork  2 года назад +18

      Thank you! And thank you for your videos as well, I found your channel very recently and I really like what you are doing! it seems that we have common interests :)

    • @PezzzasWork
      @PezzzasWork  2 года назад +10

      Waiting for your next video as well! (And btw the video on bloom was amazing)

    • @LineOfThy
      @LineOfThy 10 месяцев назад +3

      engine guy :D

  • @yell9140
    @yell9140 2 года назад +389

    My understanding of the code is currently too limited, but I will definitely learn and come back to this amazing video, I have always wanted to do things like that. Amazing work again Pezzza, wish you all the best.

    • @mickyr171
      @mickyr171 2 года назад +17

      I dont even know what language it is lol, i was thinking C++ but not 100%

    • @mickyr171
      @mickyr171 2 года назад +5

      Maybe rust

    • @PezzzasWork
      @PezzzasWork  2 года назад +53

      It’s indeed C++ :)

    • @mickyr171
      @mickyr171 2 года назад +8

      @@PezzzasWork thought so, I'm more a java/c# man myself, want to learn c++ but struggle to wrap my head around some of the functions

    • @PezzzasWork
      @PezzzasWork  2 года назад +31

      C++ is a big and complex language, it's not easy to get into it

  • @NotAFoe
    @NotAFoe 2 года назад +50

    Wow I love this kind of content so much, thanks pezzza!

  • @americanhuman1848
    @americanhuman1848 Год назад +16

    why struggle finding happiness when you can just watch this video? seriously its so relaxing and makes you feel like you have reached nirvana

  • @gaspardallimant1768
    @gaspardallimant1768 2 года назад +77

    How ?! It looks so easy to implement and the result is awesome ! Thank you so much, each of your videos is a bigger mindblowing for me than the previous one

    • @bigsmoke6414
      @bigsmoke6414 2 года назад +14

      I guess thats the Sebastian Lague Effect😉

    • @muuubiee
      @muuubiee 2 года назад +9

      I suspect this is just the art of having studied some mathematics (multivariable calculus and linear algebra is probably enough).
      With math knowledge you can just take the equation and implement it.

  • @carrymeorgg8512
    @carrymeorgg8512 2 года назад +48

    You inspired me to learn C++ after fearing its complexity for months. I finally was able to learn C++ because of you. Please make more videos like this in the future. I enjoyed the teaching style and learned a lot. Keep up the great work man.

    • @PezzzasWork
      @PezzzasWork  2 года назад +12

      Thank you so much for your message, it is so cool to read ! I hope you will enjoy the possibilities that c++ offers! It’s a complex but very powerful language

    • @nejsonsvejson9861
      @nejsonsvejson9861 Год назад +1

      Yeah, the hardest part of programming is overcoming the fear of complexity. It's what kept me away for years.

    • @MM2isBest
      @MM2isBest Месяц назад +1

      So did you learn it carry?

  • @dragonminz602
    @dragonminz602 2 года назад +23

    Beautiful work and thank you for showing how you did it. That was very interesting.
    Also very cool ending

  • @bird5790
    @bird5790 Год назад +2

    Please a part 2!
    this was by far the most interesting and ACTUALLY HELPFUL video i have seen in a while

  • @alliepiper4772
    @alliepiper4772 2 года назад +6

    This is really cool, I always learn something new watching your videos! Implementing collisions and constraints by simply updating positions and having an integration function that can figure out velocity/acceleration is powerfully clever. Great explanation at the beginning, and the surprise picture at the end was a nice touch.
    Looking forward to your next adventure :)

  • @SuboptimalEng
    @SuboptimalEng 2 года назад +33

    I'm really glad to have found your channel after Sebastian Lague made the ant simulation video. The stuff you make is amazing!

  • @general3978
    @general3978 2 года назад +10

    This video is a masterpiece in technical execution and artistry

  • @stylextv
    @stylextv 2 года назад +276

    The colored circles at the end turning into your logo was pretty bad ass. How was it done though? Running the simulation to see where each object ends up then running the simulation again and coloring each object based on its final resting point?

    • @themikek99
      @themikek99 2 года назад +15

      Maybe it's reversed? B)

    • @khatharrmalkavian3306
      @khatharrmalkavian3306 2 года назад +77

      @@themikek99 Possibly, but Verlet integration is lossy when you add collision handling, so it would have to be a different process in order to be reversible.
      I think Stylex may have the right idea there. The process is entirely deterministic, so with the same conditions you'll always get the same outcome. You could run the simulation once, take note of where each object ends up, then color them accordingly, and re-run the sim to get the logo.

    • @gytiskau1865
      @gytiskau1865 2 года назад +56

      @@khatharrmalkavian3306 You could also bake the whole simulation, color the outcome and replay

    • @ducking_fonkey
      @ducking_fonkey 2 года назад +2

      He probably read the image data and the. assigned the objects for some of the pixels and then gave them the velocity to make them move in the right way.

    • @GG64du02
      @GG64du02 2 года назад +3

      If he did not do it in reserve i am interested on how he pulled it off....

  • @spencer__
    @spencer__ Год назад +1

    No idea how you made a physics programming video both beatiful and relaxing. Amazing work.

  • @sushismitcher225
    @sushismitcher225 5 месяцев назад +1

    Wow!
    Incredible. I can't believe how elegantly and simply you set up the code for a complex-looking and incredible result. I also can't believe how you fit this into a 9min video. You're incredible.

  • @alexhooper27
    @alexhooper27 2 года назад +1

    I always finish your videos in awe. This is what I aspire to be able to do with my knowledge of math and coding.

  • @user-tr2hc2xx3b
    @user-tr2hc2xx3b 2 года назад

    Wow, looks so simple and elegant! Great job, looking forward to more videos like this one!

  • @movingheadmau8128
    @movingheadmau8128 2 года назад +1

    Always love watching your videos for the cool content you tackle :)

  • @nothingnothing1799
    @nothingnothing1799 2 года назад +12

    I love the inclusion of the code itself seeing what it does is cool but being able to see how it was made is very cool imo

  • @cirogarcia8958
    @cirogarcia8958 2 года назад +29

    It's amazing! You just taught me in less than 10 minutes what I wasn't able to learn on my own in weeks!
    Do you plan on uploading more videos like this in the future? It would be amazing to see how you deal with problems like tunnelling and static collision shapes

  • @eboatwright_
    @eboatwright_ 2 года назад +3

    This is amazing! Thank you so much for your help! I've always wanted to make a physics engine, and I'll definitely implement this in Rust! :D

  • @singularityoptimist
    @singularityoptimist 2 года назад

    Excellent work and a beautiful result

  • @sierpinskibrot
    @sierpinskibrot 2 года назад

    Phenomenal work ur doing here man

  • @mementomori7160
    @mementomori7160 2 года назад +1

    I'm glad I subscribed to you, this vid made me really interested in making my own physic engine

  • @kikawet
    @kikawet 2 года назад +2

    I loved the video and really respect this channel! if you do a version with continuous collision detection then there is nothing more to expect from you!

  • @gigaprofisi
    @gigaprofisi Год назад

    will never regret subscribing to this amazing and talented channel

  • @valet_noir
    @valet_noir 2 года назад

    Love ur content, great to see a "behind the simulation" video ! Amazing :D

  • @dandymcgee
    @dandymcgee 2 года назад

    Very cool demonstration. Great work.

  • @JosephCatrambone
    @JosephCatrambone 2 года назад

    Good choice of music. Nicely demoed. Solid video.

  • @rtsa4633
    @rtsa4633 Год назад

    This video is gold and I will definitely have to come back to it in the future if I build something like this

  • @newcooldiscoveries5711
    @newcooldiscoveries5711 Год назад

    Unreal! Very Enjoyable! Thank You!

  • @akosszabo3163
    @akosszabo3163 2 года назад +2

    Your work is very impressive. Thanks for the video. It motivated me to implement this on the language I know the most, so I implemented it in Java. Finally after a couple of hours it worked fine. I implemented all the functions you demonstrated. Functions can be initiated from the menu. Additionally based on the chain example I implemented a rigid body. The last function will be the magic. You can open a picture and cut a part of it and that will appear as your logo did. I will share it as soon as it is done. So thanks again, nice job!

  • @aleksandarstankovic4476
    @aleksandarstankovic4476 Год назад

    This video greatly benefits my coding skills! Thank you for the explenation!

  • @Reditect
    @Reditect Год назад +2

    Amazing! I've been trying to understand the programming behind physics and make my own 2D and 3D game engines. Visually appealing and informative video. Thanks. :)

  • @SpartanG318
    @SpartanG318 2 года назад +1

    I find you right that moment and i am a software engineer in trainee... i can understand the code a bit and on the other hand i sit here and think, i know nothing about physics and simulations. Pretty mind blowing your work. This Bonus at the end.... HOW?? Thanks man, i cant stop to smile. :)

  • @NimsoStudios
    @NimsoStudios 2 года назад +4

    Bravo my friend, Bravo!
    An excellent look at the basic Velocity per frame physics engine and just how powerful circle collisions can be.
    I spent a moment trying to figure out why the velocity was updating before realising you were actually calculating it each step rather than keeping it persistent throughout.
    I'm going to play a little with the idea of calculating Velocity before applying motion to it, in 3D though since I work a lot on 3D character control systems and write the motion custom.
    This has been visually the nicest way to show the beauty of a physics engine.

    • @PezzzasWork
      @PezzzasWork  2 года назад +1

      Thank you very much! This should be directly transposable to 3D. I think it’s a good fit for what you are trying to do!

    • @NimsoStudios
      @NimsoStudios 2 года назад +1

      @@PezzzasWork I do plenty of platformer gameplay systems, but usually keep velocity persistent rather than calculate immediately before applying the new step.
      Definitely something I want to try out, might end up making some cool stuff out of it too.

  • @LogInValid
    @LogInValid 2 года назад

    This makes me want to go back to school and learn programming. Simply Amazing!

  • @pelicannot.
    @pelicannot. 2 года назад +10

    i love this channel :D

  • @GradientAscent_
    @GradientAscent_ 2 года назад

    Love these endings, keep it up

  • @redspyro4750
    @redspyro4750 Год назад

    I don't even know much about code, so this is already very helpful! And by helpful I mean I will probably keep rewatching this every time I want to do physics simulation.

  • @Rentaro_dev
    @Rentaro_dev 2 года назад

    Nice video man! A wiki article and your video helped me very much.

  • @xvitxr
    @xvitxr Год назад +1

    bro, this video is a masterpiece, my dream is to be a developer like you.
    i saw all your past and recent videos and every one of them are amazing!
    please, PLEASE keep the good work

  • @NoxiusVI
    @NoxiusVI Год назад

    Amazing tutorial! Worked really well even when using a different language!

  • @sanderbos4243
    @sanderbos4243 2 года назад

    Amazing tutorial, and the ending was such a twist!

  • @caoduythanh1453
    @caoduythanh1453 2 года назад

    what a master piece!

  • @duongquanghuy4387
    @duongquanghuy4387 2 года назад

    The ending got me. Nice work!

  • @NeverForgetNasa
    @NeverForgetNasa 2 года назад

    Oh my god, that is so beautiful.

  • @busy_beaver
    @busy_beaver 2 года назад

    Thanks for this great video!

  • @Chareidos
    @Chareidos 2 года назад

    lol...
    was gonna write so many questions in another video, asking how to get there...
    now I found this clip before I would have sent that long comment!
    This is a clip to start with, I guess.
    Thank you for enabling me to at least try.
    Subscribed!
    Maybe you link this video clip in the notifications of other stuff you uploaded!

  • @Katniss218
    @Katniss218 Год назад +1

    The end was really cool!

  • @williambarajas8090
    @williambarajas8090 2 года назад

    yes!!!!!!! love the video please make more of them!!!

  • @DevashishGuptaOfficial
    @DevashishGuptaOfficial 2 года назад

    This video made my day!

  • @glumpfi
    @glumpfi 2 года назад +1

    :O Especially the end blew me away!

  • @starship9874
    @starship9874 2 года назад

    This is the most underrated coding channel ever. Your videos are so high quality

  • @softpaw6234
    @softpaw6234 2 года назад +1

    These simulations would have made great screensavers back when we needed those

  • @henwill8
    @henwill8 2 года назад

    Wow it literally felt like magic how it just simply worked with such little effort and code

  • @yudhistira7231
    @yudhistira7231 2 года назад

    Awesome dudeee, I never get bored watching your videos. A subscriber btw, keep it up!🏃

  • @devmarboy4045
    @devmarboy4045 Год назад +1

    this is so sick, can’t wait to get as advanced as u lol

  • @Hailfire08
    @Hailfire08 2 года назад

    Awesome video!!!

  • @WDGSWhatDoesGodSay
    @WDGSWhatDoesGodSay 2 года назад +9

    OMG I have been trying to figure out how to make a physics "engine" like this from scratch.

    • @WDGSWhatDoesGodSay
      @WDGSWhatDoesGodSay 2 года назад +1

      Can you make the .cpp files available in the description or tell me where I can find them. THANKYOU!!!

  • @osartur
    @osartur 2 года назад +10

    You must have worked really hard to get where you are. You are really good at what you do

    • @osartur
      @osartur 2 года назад +7

      I used a translator so I don't know if what I said was strange 😁

    • @wilykary
      @wilykary 2 года назад +1

      @@osartur nah not at all

    • @TetyLike3
      @TetyLike3 2 года назад

      @@osartur the only problem with that sentence was the punctuation lol

    • @pineapplerindm
      @pineapplerindm Год назад

      @@TetyLike3 i dont see anything wrong with the punctuation

  • @rodakdev
    @rodakdev 2 года назад +3

    That chicken has glasses for a reason! So cool!

  • @nikbivation
    @nikbivation Год назад

    thank you for this!

  • @prometheusli101
    @prometheusli101 2 года назад

    amazing effect

  • @PatrickHoodDaniel
    @PatrickHoodDaniel 7 дней назад

    My cat was very interested in the chain!

  • @markwinfield845
    @markwinfield845 9 месяцев назад

    Great video, I am subscribing.

  • @michaberkowicz8239
    @michaberkowicz8239 2 года назад +7

    That ending was..... unexpected

  • @Radu
    @Radu 2 года назад

    Nice ending! It's the reason I subscribed :-)

  • @mariusvanc
    @mariusvanc 2 года назад +10

    5:40 I was thinking the "perfect" solution to this would be, aside from sub-stepping, to add a bit of friction every time there is a collision, this would settle the objects quicker so they don't vibrate while stationary. Just multiply the vectors by 0.99 or something like that.

    • @kiranroye6498
      @kiranroye6498 17 часов назад

      i tried that out and it pretty much worked, but it still wound up "vibrating". still went from ~30 fps to ~200, so a massive improvement

  • @jacktapping9290
    @jacktapping9290 2 года назад

    beautiful

  • @lorenzoassiro8532
    @lorenzoassiro8532 2 года назад

    Wow this code is mind blowing🤯

  • @user-lp8pq4en5u
    @user-lp8pq4en5u Год назад

    excellent!!!!

  • @Archangel2x
    @Archangel2x 2 года назад

    The ending logo showing up was like magic.

  • @brecoldyls
    @brecoldyls Год назад +1

    Can’t wait for part 2: Writing a Physics Engine in Scratch

  • @NStripleseven
    @NStripleseven 2 месяца назад

    The concept of Verlet integration is actually super cool IMO, because it means momentum changes from collisions/etc are handled more or less automatically.

  • @simonsvoboda8849
    @simonsvoboda8849 5 месяцев назад

    I'm so glad youtube recommended this video to me. How did I not know about this??

  • @and_I_am_Life_the_fixer_of_all
    @and_I_am_Life_the_fixer_of_all 2 года назад

    that ending felt like an assembly theory flex before its time, wow.

  • @leod6011
    @leod6011 10 месяцев назад

    Cheers to that bro

  • @mr.milindsingh7671
    @mr.milindsingh7671 Месяц назад

    This was fantastic. I loved the way you simply coded this complex looking problem. I was wondering what would it take if I wanted to add friction forces among particles.

  • @Sam-hu3xt
    @Sam-hu3xt Год назад

    Three words: epic!

  • @raushankumar2336
    @raushankumar2336 2 года назад

    I can't understand how thing is being applied, but i loved it especially the bonus clip 🔥
    I have to learn alot to achieve this, nevermind i will do that

  • @odedkadshai
    @odedkadshai 2 года назад

    felt like magic show

  • @MrWandalen
    @MrWandalen 2 года назад

    I love this

  • @artemonstrick
    @artemonstrick 2 года назад

    Fantastic

  • @VincePhoenix
    @VincePhoenix 2 года назад

    Impressive !

  • @xintreavideo
    @xintreavideo 2 года назад

    Cool! It's view so easy...

  • @HyperHrishiHD
    @HyperHrishiHD Год назад

    You scared away half of the people away with the equation as the first thing in the video.
    But I’m all here for it

  • @ArashRabbani
    @ArashRabbani Год назад

    the jaw dropping last scene!!!

  • @mctuble
    @mctuble Год назад

    Just using the colors makes this so much better lol.

  • @mariovelez578
    @mariovelez578 2 года назад

    nice physics baking at the end 😎

  • @unknown-bx8my
    @unknown-bx8my 2 года назад

    awesome😍

  • @browntowncurry8674
    @browntowncurry8674 2 года назад +1

    Absolutely AMAZING! I will try and replicate in C# now.

    • @Tarou9000
      @Tarou9000 2 года назад

      I'll try to do it in scratch

    • @imukai
      @imukai 2 года назад

      I was having the same idea since I'm rooted in C# myself. Did you get it done? Share?

  • @ziggyzoggin
    @ziggyzoggin Месяц назад

    Thank you for this, I used it to make a 4D gravity simulation in Godot 4!

  • @expressoaddict
    @expressoaddict Год назад

    That ending was lit.

  • @poulpemalade4483
    @poulpemalade4483 Год назад +2

    I don't understand how you achieved the last one and that bug me a lot ! . Anyway, this is truly amazing ! I learned so much from it. Thank you !

    • @peterfordham3562
      @peterfordham3562 9 месяцев назад +1

      It deterministic, and done in two passes.

    • @whimbur
      @whimbur 9 месяцев назад +2

      The calculatoions are completely deterministic, meaning that it has no randomness involved. You can run the program once w/out color, and then apply the colors to each object; then just run it again but with the new colors applied and voilà

  • @vinaciotm
    @vinaciotm 10 месяцев назад

    THANKS A LOT!!! PLEASE, PART 2
    some ideas: (I really excited about)
    rotation/angle, applyForce, applyImpulse, box shape, custom shape(polygon, array of Vec2 stroke and fill

  • @Tann114
    @Tann114 2 года назад

    awesome

  • @MrNucleosome
    @MrNucleosome 2 года назад

    THANK YOU

  • @jellybean2427
    @jellybean2427 Год назад

    You saved my life

  • @Synthetic_geth
    @Synthetic_geth 2 года назад

    Clean