Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple dispatch for collision detection in C++? [closed]

I have circles, boxes and lines. And now I want to implement collision detection between them. This means that I have to have a function for each combination of two kinds of shapes. Of course I can use the same for line vs circle and circle vs line, but I think my point still stands. What's the most elegant way to implement this in C++?

like image 560
user3174082 Avatar asked Dec 07 '25 05:12

user3174082


1 Answers

In the Modern C++ Design book, Multimethods chapter explains how to implement them and documents how to use [implementation provided by Loki library][2]. There is also Boost.Multimethod proposal, but it's not there yet. The book demonstrates the power of multimethods exactly on the topic of object collision.

like image 141
LavaScornedOven Avatar answered Dec 08 '25 19:12

LavaScornedOven