Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are making things more complicated than needed. You have a collection of objects (which you are calling <code>figures</code>) and a collection of actions (which you are calling <code>moves</code>). The obvious choice from an OOP perspective is to make the <code>moves</code> methods in your <code>figures</code> classes.</p> <p><b>Update</b></p> <p>Based on the comment below, you should be using a linear algebra library such as <a href="http://www.boost.org/doc/libs/1_47_0/libs/numeric/ublas/doc/index.htm" rel="nofollow"><code>boost::ublas</code></a>. There are others as well that you might want to look into such as <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page" rel="nofollow">Eigen</a> (more or less shown below).</p> <p>The basic idea is to abstract both the figures and the moves to generalize both so you don't have to rewrite the code for each possible combination. Thus, you would create a base class which looks something like:</p> <pre><code>template &lt;typename T> class figure { std::vector&lt;Eigen::Vector3d&lt;T> > point_list; ... void applyTransform(const Eigen::Affine3d&lt;T>& src) { for (auto pt=point_list.begin(); pt != point_list.end(); pt++) (*pt) = src * (*pt); } }</code></pre> <p>In this case, you define your point list based on the shape you are rendering. You can adjust meaning of the points in your derived classes to define specific geometric figures you're interested in. The <code>Eigen::Affine3D</code> class is used to define the transformations you want to apply. Eigen already has rotations and other affine transformations defined, so you should be able to reuse those.</p> <p>You can also look into some specialized OpenGL or DirectX geometry classes which does all of this for you.</p>
 

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