title: how to detect which side of 3d cube was clicked?
body: <p>I am writing a small 3d "engine" in canvas.. not really an engine, but more of an application based on code from <a href="http://www.pascarello.com/canvas/KeyBoard3DCube.html" rel="nofollow">Eric Pascarello's demo</a> (hit number "7" a few times to see it rotating)</p>
  
  <p>it's all going very nice, I even added sorting by average z-value for each plane ("side") - so that I can use a body made of several cubes so that close to camera shapes are drawn last.</p>
  
  <p>now, I want to detect which side was clicked, when a mouse clickes the canvas.
  something like <a href="http://www.fi.uu.nl/toepassingen/00208/toepassing_rekenweb.xml?style=rekenweb&amp;language=en&amp;use=game" rel="nofollow">this</a></p>
  
  <p>hints:</p>
  
  <ol>
  <li>each side is defined by 4 (x,y,z) corners</li>
  <li>each corner is drawn to canvas using what I believe is regular "perspective projection"</li>
  </ol>
  
  <p>here's my code - it's cool: use the mouse to rotate</p>
  
  <pre><code>//edit: see the code in my answer below
  </code></pre>