2D Physics Engine! // Code Review

preview_player
Показать описание


CHAPTERS
0:00 - Recap
1:14 - How to design an API
2:52 - 2D Physics Engine design
9:02 - Pointers and ownership semantics
13:00 - Using std::weak_ptr to be "safer"
14:39 - More physics
16:42 - Spatial partitioning for optimization
22:55 - Be careful when trying to optimize!
26:37 - Physics solvers
31:50 - Final thoughts and extra challenges

This video is sponsored by Brilliant.

#CodeReview
Рекомендации по теме
Комментарии
Автор

How on earth he can look at, understand, see what's wrong with and fix everything in seconds is amazing to me. I strive to be this good in the future.

ryans
Автор

Once again thanks a lot for the code review, I learned a lot ! I'll definetly try to improve it in the future :)
For the space partitionning, I mostly did it because our school told us it's a good idea to try it (to learn what it is, how it works etc), but it's true that i've never tried to test and measure if that brings performance improvements haha

Stowy
Автор

I'm not doing any game development. These videos are still very educational and I can't stop watching.

Dr-Zed
Автор

25:37 Oh damn, straight through the heart with that one!

SoDamnMetal
Автор

These video's are incredible Cherno! I'm studying CS & Game programming and its fascinating to see you dissect others projects/code & suggest improvements.
It really helps me think about my own implementations!

tyuchevv
Автор

A partitioning technique I've come to love is using a grid with BVHs. the grid takes care of the global partitioning and the BVHs take care of the local partitioning inside the cell. and a benefit of using the grid is that checking the "next" cell means that the "next" cell can avoid the previous cell check meaning that if you begin at some corner you can grow outward along the cells and perform only 4 checks per cell instead of 8

on-hvco
Автор

9:06 - I guess that RigidBody() situation is why some of us were taught to camelcase and include a verbs in function names. 😅

LULEIVON
Автор

The adding of the rigid body to the dynamic world would be done in the derived classes so they can set further properties on the rigid body before it is added to the world.

slygamer
Автор

One comment that could be added to the grid implementation, which is typically seen, is that you could totally avoid having the triple nested `std::vector`s by converting the 2D index into a 1D array index and vice versa.

zhivkobogdanov
Автор

I'd give a 9 or 9.5 for this. Very good code, much better than lots of dev mates I've worked with lol. Good series too

hbobenicio
Автор

Awesome trilogy! I'm amused with your annotation skills; could you share what software you are using @34:00 to draw the red annotations?

Moonz
Автор

"I'm banning myself from talking about anything except physics"
*2 seconds later*
"it's good that you have different classes for collision and solvers because it's always good to..."

saeedbarari
Автор

The full Knuth Quote, from The Art of Computer Programming is:

“The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.”

In full context, he’s actually getting at the worries you illustrate; it's just been co-opted by people who use it out of context (often to the opposite effect). This isn't the only misunderstood quote like that by a long-shot. “KISS” usually makes me furious, when I hear it from a manager.

SeanJMay
Автор

Be careful with using a grid system when calculating collisions. A large object can span even outside of the surrounding blocks. Look for example at the long horizontal bar in the demo.

bunpasi
Автор

Basically collisions are O(n^2) and sorting all the objects into a grid will be O(n)

nielsdaemen
Автор

As for the rating, I would say having a rubric would be great.

For example, points could be rewarded for having better memory management, or having better/more useful comments, etc.

bluesillybeard
Автор

I know NOTHING about game engines, and having watched your videos for a couple of weeks i feel like youre really knowledgeable and the person to ask. Was just wondering with your experience what you think is the "Easiest" Game engine to use to build games for a complete beginner to games development? I have programming experience just never worked in game dev. What do you think are the easiest to use game engines to build games for beginners like me? Anyway love the content.

vectoralphaSec
Автор

18:29 Even just a spatial hash grid would be pretty simple here.

Spartan
Автор

30:03 IMO a pointer type IS boolean by its very nature, at least in C++ and in C. This is because it either "points" (to something) or it doesn't point to anything (=nullptr). This is the traditional idiomatic way of using pointers in both of those languages, so the way you illustrated it can be done is the way to go! Many prefer to write stuff like "if (ptr != nullptr) ..." or even "if (flag == true) ...", but I would argue that those are tautologies that do nothing good while even reducing readability at the same time.

benhetland
Автор

What software do you use to zoom and annotate the screen when explaining things?
I know it was already asked and he mentioned it in some video, but I can't remember where.

shaiavraham