- Видео 15
- Просмотров 81 693
Rust without rust
Великобритания
Добавлен 1 июн 2020
Yo, I do Rust.
Algorithms: Randomly Placing a Point Inside a Circle
#algorithms #maths #geometry #trigonometry #gamedev #coding #leetcodeproblems
Randomly placing a point inside a circle is a fairly simple, beautiful and clean problem. In this video, we're going to talk about it.
Demonstration link on GitHub: kul-sudo/circles
0:00 Introduction
0:19 1st Approach
1:00 2nd Approach
Randomly placing a point inside a circle is a fairly simple, beautiful and clean problem. In this video, we're going to talk about it.
Demonstration link on GitHub: kul-sudo/circles
0:00 Introduction
0:19 1st Approach
1:00 2nd Approach
Просмотров: 1 284
Видео
Dynamic Mazes Demonstration
Просмотров 370Месяц назад
#programming #algorithms In the last video, I showed 2 dynamic maze algorithms. Today, let's take a look at a dynamic mazes demonstration. Music: Noah Barger - Ballad The demonstration: kul-sudo/maze
Dynamic Mazes: Algorithms You've Never Seen
Просмотров 837Месяц назад
#programming #algorithms Maze generation is a fairly popular topic in the field of algorithms. Today, let's explore dynamic maze algorithms you haven't seen. Sound at the end: Noah Barger - Piano Tune.mp3 The demonstration: kul-sudo/maze 0:00 Basics and Terminology 0:40 1st Approach 1:53 2nd Approach
Evolution Simulator: It's More Like Earth
Просмотров 1,3 тыс.2 месяца назад
#gamedev #gamedev #2d #coding The evolution simulator I've made has always had few similarities with real-life evolution and too many abstractions. Now that carnivores, omnivores, and herbivores have been added, it's more like Earth. Sound at the end: Noah Barger - Piano Tune.mp3 The evolution simulator: kul-sudo/eportal
Quadtrees: Blazingly Fast Collision Detection
Просмотров 45 тыс.2 месяца назад
#gamedev #gamedevelopment #2d #coding Detecting collisions can be done by going through each object for each object, but that'd be fairly slow. A beautiful and efficient way is using quadtrees. Sound at the end: Noah Barger - Piano Tune.mp3 Demonstration link on GitHub: kul-sudo/quadtrees
Spatial Hashing: Instantly Finding the Closest Neighbor
Просмотров 25 тыс.3 месяца назад
#gamedev #gamedev #2d #coding There's a fairly easy way of finding the closest neighbor among thousands and thousands of objects almost instantly. Today I'll show it. Demonstration link on GitHub: kul-sudo/spatial_hashing
Evolution Simulator: Analysis
Просмотров 2803 месяца назад
#opensource #github #rustlang #programming #coding In the previous video I demonstrated an evolution simulator I was working on. In this video I'll analyse the overall evolution process and try to explain what happens for what reason. And here's the project itself on GitHub: kul-sudo/eportal
I Built an Evolution Simulator
Просмотров 1,2 тыс.4 месяца назад
#opensource #github #rustlang #programming #coding In this video I'll demonstrate an evolution project I'm working on. The great song at the end: Noah Barger - it's been a bit. And here's the project itself on GitHub: kul-sudo/eportal
Rust Vectors: How do they work?
Просмотров 3374 месяца назад
#rustlang #programming #coding #codingtutorial I think many people really misuse vectors, so in this video I'll show how they're implemented and their cons.
Enums in Rust: Almost Too Good?
Просмотров 5914 месяца назад
#rustlang #programming #enums #coding #codingtutorial I think many people heavily underuse enums in Rust, so in this video I'll talk about them.
Rust Tips to Boost your Skill
Просмотров 1,6 тыс.4 месяца назад
#rustlang #programming #coding #codingtutorial Today I'll share with you a few Rust tips that are important to know. I hope you enjoy the video!
Threads in Rust: Parallel Computing
Просмотров 2,2 тыс.5 месяцев назад
#rustlang #programming #async #coding #codingtutorial I think many people greatly underrate threads in Rust, so in this video I'll talk about them.
How to disarm Rust
Просмотров 3095 месяцев назад
#rustlang #programming #coding #codingtutorial Hello everyone. I decided to make a video about using `unsafe` in Rust, because most people don't seem to know the power of it and and that it isn't really a crime.
Rust for rookies
Просмотров 3075 месяцев назад
#rustlang #programming #coding #codingtutorial Hello everyone. Recently I've noticed that a lot of people want to learn Rust but don't know what it even is. In this video, I tried to explain that in simple worlds. I'm also working on integrating a donation system into my channel, so I'll probably do it by the next video.
The easiest Rust borrowing guide
Просмотров 5575 месяцев назад
#rustlang #programming #coding #codingtutorial Hey everyone. In this video, I tried to as simply as possible explain borrowing in Rust. I was watching a lot of videos about it when I was learning Rust and was never able to understand it, so I hope this video is especially helpful for beginners. Enjoy!
0:26 i see 2 balls intersecting 👀 Nice video, I'll have to try this out as a project soon.
Yeah, that was a glitch I've fixed already lol
Do you have a proof, why the last method works? I'm a math guy, so I'd like to know
I interpret that formula intuitively, but this proof should suffice: *Step 1:* The function determines the chance that a circle with the radius r is within a circle with the radius R. F(r) = (πr²)/(πR²)=r²/R² *Step 2:* ζ ∈ [0, 1] F(r) = ζ *Step 3:* r²/R² = ζ → r = R√ζ
hmm very cool but I don't get the last method
I didn't want the video to be engulfed by math; instead, I wanted to make it intuitively clear. Think of it this way: picking a random ring (radius) and then picking a random point on the ring. What happens next is an intuitive solution to the points grouping around the center. If you want a remote explanation of this intuitive solution, it's a way to prevent values close to the boundaries of random(0, 1). For instance, sqrt(0.01) is 0.1, which makes the position noticably closer to the middle ring.
Do you have a benchmark for both methods?
The second one's more consistent, but if the first one gets lucky and doesn't miss the circle, it'll be faster.
Could also use max(rand, rand)*max_r
Yeah I thought of that too because of a video I watched a few days ago on that topic!
If rand here is a macro for random(0, 1), then I could see it giving a rather unnaturally higher average. Perhaps you have an idea on why that'd be helpful, no joking.
@@rustwithoutrustsqrt(rand) and max(rand,rand) have the exact same probability distribution. i don't know if there's a reason to use one over the other in code, though.
never let bro work at a pizza place 😭
Nice
this feels christmasy somehow lol
@@alliesakat Because Noah Barger's music always improves whatever it touches
ok this is epic how the video syncs with the music at times, great editing
Yeeeeah! Big W to Noah Barger for the soundtrack.
Very nice
what kind of collision detection are you using? just checking if two bodies overlap/touch, or is it something else?
@@lanata64 Yes, whether they overlap.
@@rustwithoutrust i wonder if it'd be faster to do some sort of continuous/'event based' CD, and then lower the tick rate.
@@lanata64 Well, if an object moves, it can always potentially collide, so this is the most natural approach to check for a collision on every position change.
@@rustwithoutrust well yeah, but i was wondering if a continuous cd method that doesn't use 'overlap-checking' in the same way might be faster if you can lower the tick rate (since the max tolerable movement per tick could be far higher)
It could be expanded to use octrees for 3D environments :) I've implemented this during a research internship.
very insightful video
which one?
@@rustwithoutrust yes
One huge optimization is making your grid scale suit it's purpose. What's the smallest and largest item? Some game engines have a stroke with many large or small items.
This has nothing to do with hashing ... dude your chat-gpt hallucinated
Cool! I'd like to hear what you think about implementing QuadTrees implicitly using BTrees and Z-Order curves, if you've tested it or have a benchmark, the implementation might be much simpler and simplicity is definitely a plus! What happens is that each two bits in the Z-Order key will represent a position in a layer of the QuadTree. So you can use a modified QuadTree function (which generates the next z order index within a range) and iterate over a BTree, doing a new range search with the next valid index when the iterator falls outside of our query rectangle. It does improve data locality in memory and reduces allocations, and the branching factor of a BTree (rust uses 11) is better than that of a QuadTree (4), but it restarts the search from the root for every quadrant. I don't have a benchmark in hand, unfortunately.
Hey, I'll take a look at it and maybe do a video.
@@rustwithoutrust The k-dimensional data structures, like space filling indexes, can do queries for things that are not points: Rectangles (a, b, c, d) and (e, f, g, h) intersect if (0, 0, a, b) <= (e, f, g, h) <= (c, d, inf, inf) The collision problem which is hard in 2D becomes a simple range query in 4D space
Bro, how would you recommend to learn rust, I have tried plenty of times but I just can't get over it's syntax. I find golang syntax easy and works for me.
I think overcoming syntax mistakes takes making a couple of relatively big projects. What you could have even bigger problems with is the borrow checker, but most of the time fixing errors related to it includes changing the structure or the logic for it to be memory-safe; that also takes a couple of projects to overcome. But you aren't forced to use Rust, so if Go works for you, keep in mind it's garbage-collected, which is its disadvantage. The way I see it, if you need a company-level codebase that never segfaults and is easy to maintain for years, Rust is your option.
@@rustwithoutrust so what would you recommend ? I start with a rust book and build project after that :) ?
Yes, I recommend to read the official book and go through a few unofficial ones. But ultimately, you'll learn the most from building a project.
@@rustwithoutrust thank u so much !!
Awesome!
Thanks!
Cool video thank you
Glad you liked it!
YYYY
where can I find the code for this project?
the repo is in the description
Also if you just want which one is closer and don't need the specific distance you don't need to use a square root, just compare `dx^2+dy^2` as you'll just be comparing `r^2` which is fine - if you do need the distance you can then sqrt the `r^2` of the closest neighbour after. However, it doesn't really apply to this situation where you have few collisions if the size of cells are correct, the demonstration repo uses `.distance` which is far cleaner; just wanted to point it out as I do see a lot of people using sqrts for things where they aren't necessary, if you don't have too many entities to check you may be able to get away with not dealing with space partitioning and instead just remove square roots.
thumbnail is literally me when seeing a Rust without rust upload
real
Interval trees
6 years ago I did a physics collision system using quadtrees where I generified the node to have any number of leaves. Turns out adding way more leaves into a single node was tonnes faster, and reducing depth. I ended up with an optimal solution having just a depth of 2: chunks and cells. So my recommendation to have a super fast grid of bins would be to just have a hashmap of chunk coordinates to chunks, where each chunk is an array of cells. Its super simple to implement and very very fast, while retaining a lot of the space saving, since empty chunks can be removed from the hashmap.
That's cool. Thanks for sharing
this I understand. I did not get the quad tree. not the creators fault. im slow and not too bright.
probably would have been better to do this in either C++ or Python, as the Rust code is clearly not comprehensible.
that's C
Amazing thank you
hell yeah
As a physics engine developer, I want to point out that while QuadTrees and Octrees are often praised for their performance, they aren't always ideal for certain tasks, especially in physics engines that require advanced features like raycasting or shape/sphere casting. These data structures struggle with irregularly sized objects that exceed the size of a cell, and there's significant overhead when performing raycasting because of the DDA-style stepping required through the Quadtree or Octree cells. Physics engines like Bullet, Box2D, Jolt, and my own full-featured 3D physics engine KRAFT (written in Object Pascal) all use dynamic, self-balancing AABB BVH (Axis-Aligned Bounding Box Bounding Volume Hierarchies) trees for optimal performance. PhysX, on the other hand, relies on Sweep and Prune (S&P) for broad-phase pair management and also uses AABB BVH trees for efficient raycasting.
do you think quadtrees are optimal for those 2d collision demonstrations?
@@rustwithoutrust For 2D and 3D collision demos with almost similarly sized objects (for example particles), QuadTrees and Octrees are pretty solid and get the job done nicely 😊. They’re a good choice when everything’s about the same size, but for more complex physics, raycasting or different-sized objects, other approaches might work better 😉.
Hey, didn't expect to see you here! I wanted to thank you for your work on Kraft, it's been a pleasure to go through the source code and learn a thing or two! Why haven't you split up the source, since kraft.pas is a really long file? Are you aiming for having a unit-only physics engine?
@@BenjaminRosseaux Would there be a way to dynamically effect the radius of each object in the quad tree?
@@brickmasterhunt4561 Although it is possible to have objects with different radii in a Quadtree or Octree, this approach is not very optimal. The main issue is that objects would have to overlap into neighboring cells based on their new radius, complicating the structure. Additionally, neighboring cells would need to be constantly checked and updated based on the object's radius, increasing complexity and potentially leading to an O(n²) runtime in the worst case. This becomes particularly inefficient as the number of objects grows. Moreover, this approach introduces inefficiencies since Quadtrees and Octrees are designed more primarily for fixed bounding volumes, uniform element sizes, or otherwise purely static runtime lookups. Different radii and different object sizes (especially those larger than a Quadtree or Octree leaf cell) would negate the spatial partitioning benefits in the dynamic usage case. Alternatives like dynamic self-balancing AABB BVH/BIH trees or even loose Quadtrees/Octrees can handle varying object sizes and radii more efficiently.
this will be a great channel to follow as im making my own game engine haha, great content! I never thought of this approach, this is very nice :3
thanks!
Can you implement this on scratch so I can see this more clearly? When working on quad-trees, I noticed that it is impossible to make it work when you have a dense map of small and big objects I just don't understand 2:02 to the end
You can check out kul-sudo/quadtrees on GitHub for the implementation
Does blazingly fast refer to the algorithm or the video??
good question
[Edit] Correction: the number in the corner is processor time, not point count, as per 1:30 [Original post]1:35 FOUL! Your brute force implementation used 500,000 points, but your quadtree implementation used only 50,000. It's easy to get a massive speedup when you reduce the test size by 90%.
Excuse me, what? That is simply a lie without any base under it. Moreover, you can run it all yourself and see that difference.
@@rustwithoutrust I assumed the numbers on the corner of the screen are the particle counts. Is that not what they are?
It's said it's the processor time
@@ClokworkGremlin you should maybe watch the video you're commenting on? He literally says what the number is in the video.
@@rustwithoutrust Ah. I missed where that was mentioned at 1:30-1:31. How many points were in this test sample? I've found the overall gain varies wildly based on the density of points being tested. At 1,000 points, varying from 1 and 5 units in radius, across a 1,000x1,000 unit square, I have both a sparse grid-based system and a quadtree based system that run close to 20x as fast as the brute force solution. At 10,000 or more points under the same conditions, the brute force solution is no longer viable due to both time and memory constraints. Working on a bounds sorting solution now, to see how it compares. The dense grid works about the same as the sparse grid, but takes up considerably more memory.
what is that weird effect where it looks like text is jittering
blur
@@rustwithoutrustvery avant-garde 🧐
@leeroyjenkins0 Yeah, have you seen the subtitles? I've been grinding French and decided it'd be good to make French subtitles. If that's what you mean.
@rustwithoutrust oh! 😂 No sorry I just picked an artsy word for fun Best of luck with that! It really is a crazy language..! I happen to speak it fluently, it's very understandable! Other than working on common idioms. Some notes as an aside "here's the point" would probably be "en résumé" in this context, and often point would be more "argument" than "point" even if it's usually understood, especially in Canada I'd guess. "Move into the cell" would be more "Dans" than "dedans" if you specify the object of "what is it moving into" you don't use the "de" as that's what "de" is referring to. "Utile pour des collisions" would be more "utile pour les collisions" mostly because you're talking about "collisions" as a concept. Small details like that. Also, for this type of video you'd probably address the audience as a plurality so sticking more towards "vous" (not necessarily as the polite form, just addressing all viewers at once), but that's nuanced by the target audience, including the fact that "tu" is more prevalent in french Canadian. That aside neat bite-sized video ^^ Cheers!
I'll probably make French subtitles for all my videos, because that could be good practice for me. Moreover, I'm soon starting to read a book in French that'll definitely boost me and give me more understanding of those little things!
Wake me up when it’s oct trees
ok, no need for an alarm clock
@@rustwithoutrust lol. Definitely face palmed when reflecting on my own novice attempts at collision detection. Great video. Subscribed.
thanks! yeah, most of those ways aren't that obvious initially
octrees or octonion trees?
Octtree is exactly the same but in 3d. Instead of 4 leaves in node you have 8.
quadtrees make me happy
relatable
How well do quadtrees adapt to three dimensions? I have a project that handles hundreds of thousands of particle interactions in 3D space, the approach I used was fixed grid where particles only talk to other particles in their own or adjacent grid slots. But because the grid is fixed, it can still have fairly substantial performance slowdowns if the particles are forced to congregate.
You'd use octrees for that
sometimes you only need to sort bounding volume axis limits to get the collisions in O(n) time, faster than quadtrees.
The thing about Bound and Sweep is that it's only O(n) *after* the bounds have been sorted. Nearly all known sorting algorithms are O(nlogn), which quad trees are too, so while Bound and Sweep is a lot faster than a brute force approach (where you test every possible collision) would be, it's still slower than most spatial hashing algorithms, including the one featured in this video. I actually just spent some time implementing and testing in my collision test bench, and while it's competitive at <100 points, it falls off rapidly at 1000+.
@@ClokworkGremlin use O(n) sorting algorithm, like radix binary tree sort, you can add and remove items from the tree super fast without a new sort also, I just also tested that sorting algorithm in java against Arrays.sort, holds up until like millions of elements, because of system sort native optimizations.
@@ClokworkGremlin yes you can modify the axis sort tree just like with 2d quad tree and 3d octree.
@@ClokworkGremlin in other words, you can separate the axes for the limit values completely, ie separately check x, y and z axes limit intersections. and use linear time sort. ironically radix binary tree sort is 1D binary tree.
Those last 10 seconds was something I never quite got with quad trees, until I saw this video. So like… because cells overlap, an object can be in multiple cells? That’s subtle but genius!
Yes, if the cells overlap by 2 object radiuses, then collisions can be easily handled between several cells.
@@rustwithoutrust 🌌🧠
When I did my test implementation, I made it so that cells aren't split in half, they're split based on the bounds of the objects within them, so almost all cells overlap, but if two objects might be colliding then they're guaranteed to both be in at least one cell.
it's like that with a lot of data structures, like spatial hash maps too.
Pronunciation feedback, if you're interested: the "i" in linear is pronounced the same as in "pin"
you're right
That's some weird looking Rust code.
that's C
@@rustwithoutrust Indeed. C wasn't what I had in mind from Rust Without Rust!
same, lmao
kekw
@@DanDeebster Why not? It's right in the name: *without* Rust!
Hm dynamic area codes. Is this optimal for uniformly sized objects like you have here? Since they are all the same size you could scale the area the objects are located such that the radius of the objects you are testing is so small it might as well just be a location in space. Then you don't have to worry if any object is overlapping more than one area code and you can simplify the collision to two coordinate equality tests.
I created map applications in my previous job. Having kilometres/miles of road polygons, buildings, forests, rivers, lakes, cables, lamp posts, side walks etc. a large region could consist of 5 gigabytes of vector data and having the quad trees in files with indexes to the vectors we could zoom anywhere on the map and draw the area in just 20ms. Large vectors would be clipped before drawing to optimise drawing speed. Also large polygons or lines would be stored on upper levels and these span multiple quads.
Even for uniformly distributed objects, splitting the test area reduces the total number of collision checks which need to be made, so it does help a lot. Where quad trees should be most helpful is when you have irregularly distributed objects, which allows some of the branches to just be ignored entirely.
Very nice! I want to use something similar but on GPUs, basically render all these points interacting with each other through gravity (or charge repulsion), I was wondering how fast a Rust implementation would be to render them in real time. How many points did you have in this video and how fast was the simulation? I was wondering what would it be like for ~10k points, and also whether you multithreaded this, I think quadtrees might be a bit hard to parallelize but the spatial partitioning idea seems simpler.
kul-sudo/quadtrees on GitHub. Have it done with gravity.
Thats craaazy
real
BLAZINGLY FAST 🔥🔥🔥
it's actually all a scam
I dunno if the effort pays out; but if the overhead from converting to and from hexagonal coordinates doesn't cancel out the benefits; you would have just run the check one time on 12 cells, instead doing one check on 8 and then a second check on up to almost all the additional surrounding 16 cells around that; or if the second check is not that costly, then you would be checking 6 cells, and then up to just another 6 in the worse case scenario as opposed to up to almost 16 with the square grid. The data would still be stored in a square-based grid, but the coordinates would be offset horizontally every other layer and the vertical distances squished accordingly. RedBlobGames got a great article written about various techniques on hexagonal grids, might be worth a read; I was trying to find out if there was specific technical name for this and seems there's a lot of variations on how to handle things; Wikipedia mentioned HECS might be more efficient method for hexagonal coords; I haven't read about this area in while, so I dunno what else is out there and what are the pros and cons of the various alternatives
I am writing a custom replication driver for the Unreal engine, and this might be a useful way to cull the list of actors which need to be replicated to a player. Look up "Replication Graph" if you are interested in how Epic did it. They use the same grid system to create the set of actors which are in visual range of the player, but then they pretty much brute force the selection process. For my game, I need the minions to be able to find a target quickly since there will be hundreds of minions per player near the end of the game and the search has to happen on every frame. Minions which are attacking the player need to be prioritized over everything else so the player can respond. I am writing a custom replication driver because the current implementations don't combine targeting and proximity. Thanks for giving me something to think about.
I'm trying to somewhat do this in pygame, but... I want it to create smooth shapes of the matching colors... even shapes like spirals. Technically... every matching color within a pixel distance of 10 must gravitate into each other until they create a smooth edge. if too small of a number of the same color... then make that small cluster move to the next nearest of the same color.
please make a new version of this video where you go slower and more in depth and from first principles or something like that. thanks
Very cool
real
What's spatial hashing though?
pos.x / cell width, pos.y / cell height is the hash function here for getting the cell by the position. But many seem to criticize me for this terminology.
@@rustwithoutrust You're only listing inputs without explaining the concept you titled this video.