title: Simple Oriented Bounding Box OBB collision detection explaining
body: <p>I can implement the AABB method to detect collisions it is easy and cheap but I want to implement OBB for more accuracy so I create the bounding box with the model initialization it is consists of 8 bounding vertices and center, each frame I transform all the vertices with the transformation matrix to fit the Oriented Bounding Box but I can't understand the method for detecting the collision between two OBBs and I can't find a simplified and clear tutorial which explain the algorithm with the code view point not the math because I am not a mathematician.</p>
  
  <p>if I have </p>
  
  <pre><code>struct Box {
      glm::vec3 vertices[8];
      Box() {
          for (int i = 0; i &lt; 8; i++) {
              vertices[i] = glm::vec3(0);
          }
      }
      glm::vec3 max;
      glm::vec3 min;
      glm::vec3 origin;
  
      void reCompute() {
          max = vertices[0];
          min = vertices[0];
          for (int i = 1; i &lt; 8; i++) {
              max.x = max.x &gt; vertices[i].x ? max.x : vertices[i].x;
              max.y = max.y &gt; vertices[i].y ? max.y : vertices[i].y;
              max.z = max.z &gt; vertices[i].z ? max.z : vertices[i].z;
  
              min.x = min.x &lt; vertices[i].x ? min.x : vertices[i].x;
              min.y = min.y &lt; vertices[i].y ? min.y : vertices[i].y;
              min.z = min.z &lt; vertices[i].z ? min.z : vertices[i].z;
          }
          origin = glm::vec3((max.x + min.x) / 2.0f, (max.y + min.y) / 2.0f, (max.z + min.z) / 2.0f);
      }
  //AABB intersection
      bool intersects(const Box &amp;b) const {
          return (min.x &lt; b.max.x) &amp;&amp; (max.x &gt; b.min.x) &amp;&amp; (min.y &lt; b.max.y) &amp;&amp; (max.y &gt; b.min.y) &amp;&amp; (min.z &lt; b.max.z) &amp;&amp; (max.z &gt; b.min.z) &amp;&amp; *this != b;
      }
  
      bool operator==(const Box&amp; b) const {
          return (max.x == b.max.x &amp;&amp; max.y == b.max.y &amp;&amp; max.z == b.max.z &amp;&amp; min.x == b.min.x &amp;&amp; min.y == b.min.y &amp;&amp; min.z == b.min.z);
      }
      bool operator!=(const Box&amp; b) const {
          return (max.x != b.max.x) || (max.y != b.max.y) || (max.z != b.max.z) || (min.x != b.min.x) || (min.y != b.min.y) || (min.z != b.min.z);
      }
  };
  </code></pre>
  
  <p>on model initialization I create the box</p>
  
  <pre><code>    box.vertices[0] = glm::vec3(meshMinX, meshMinY, meshMinZ);
      box.vertices[1] = glm::vec3(meshMaxX, meshMinY, meshMinZ);
      box.vertices[2] = glm::vec3(meshMinX, meshMaxY, meshMinZ);
      box.vertices[3] = glm::vec3(meshMaxX, meshMaxY, meshMinZ);
      box.vertices[4] = glm::vec3(meshMinX, meshMinY, meshMaxZ);
      box.vertices[5] = glm::vec3(meshMaxX, meshMinY, meshMaxZ);
      box.vertices[6] = glm::vec3(meshMinX, meshMaxY, meshMaxZ);
      box.vertices[7] = glm::vec3(meshMaxX, meshMaxY, meshMaxZ);
  </code></pre>
  
  <p>and each frame I recompute the box with the transformation matrix of the model</p>
  
  <pre><code>for (int n = 0; n &lt; 8; n++) {
          boxs[j].vertices[n] = glm::vec3(matrix * glm::vec4(box.vertices[n], 1));
      }
  boxs[j].reCompute();
  </code></pre>