mirror of
https://github.com/Floriansylvain/SFMLplayground.git
synced 2026-08-19 19:53:25 +02:00
feat: collision resolution & spatial grid for balls
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Ball.hpp"
|
||||
@@ -35,6 +36,18 @@ class Game {
|
||||
void update();
|
||||
void render();
|
||||
|
||||
struct CellHash {
|
||||
std::size_t operator()(const std::pair<int, int>& k) const {
|
||||
return static_cast<std::size_t>(k.first) * 73856093 ^
|
||||
static_cast<std::size_t>(k.second) * 19349663;
|
||||
}
|
||||
};
|
||||
|
||||
using Cell = std::pair<int, int>;
|
||||
using Grid = std::unordered_map<Cell, std::vector<Ball*>, CellHash>;
|
||||
Grid buildSpatialGrid();
|
||||
void resolveSpatialCollisions(const Grid& grid);
|
||||
|
||||
public:
|
||||
Game();
|
||||
void run();
|
||||
|
||||
Reference in New Issue
Block a user