Note that there are some explanatory texts on larger screens.

plurals
  1. POvisitor-like pattern for template objects
    primarykey
    data
    text
    <p>I’m trying to make a custom collision engine for academic purposes and i'm stuck on a general c++ programming issue I already have all the geometries which work properly and for the scope of the question i have this function:</p> <pre><code>template&lt;typename lhs_geometry, typename rhs_geometry&gt; bool intersects( const lhs_geometry&amp; lhs, const rhs_geometry&amp; rhs ) { //returns true if does objects intersects //(assume this functions works perfectly with every geometry type) } </code></pre> <p>I also have the following class which I need to finish implementing</p> <pre><code>template&lt;typename geometry_type&gt; class collidable_object { public: explicit collidable_object( geometry_type&amp; geometry ) : m_geometry( geometry ) { } ~collidable_object() { } private: geometry_type&amp; m_geometry; }; </code></pre> <p>Where my issue rises is when I want to create a list of <code>collidable_object</code> and test them for intersection 2 by 2.</p> <p>I have made some research on Google and found having a base class for <code>collidable_object</code> will allow me to store objects into the list. But after that how do I test the object depending on their specific geometries?</p> <p>I have tried to implement the visitor pattern but I get stuck every time because i don't want to hardcode every possible geometry type since I will always just call <code>intersetcs()</code>.</p> <p>I also found an article on <a href="http://www.artima.com/cppsource/cooperative_visitor.html" rel="nofollow">cooperative visitor</a> but this seems way to complicated.</p> <p>Does anyone have a simple and efficient solution? </p> <p>EDIT: the reason I wanted to avoid having a list of geometries is because I want it to be relatively easy to add new geometries without having to find files in the arborescence.</p> <p>EDIT2: Here is more information on the <code>intersetcs</code> method : the intersects method is based on tag dispatching to find the right geometry but almost all convex shape use the GJK algorithm which only require that the object can return the point furthest in a given direction. For non-convex shapes, the shapes are fragmented into convex sub-shapes and the process restarts. </p> <p>there is no uniform criteria to see if <code>intersects</code> will be able to process a given shape most use <code>furthest_along</code> but sphere on sphere does not and sphere agragations would also not require the use of <code>furthest_along</code></p> <p>Additional information: I use VS2012 and C++11</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload