title: Confusion about zFar and zNear plane offsets using glm::perspective
body: <p>I have been using glm to help build a software rasterizer for self education. In my camera class I am using glm::lookat() to create my view matrix and glm::perspective() to create my perspective matrix.</p>
  <p>I seem to be getting what I expect for my left, right top and bottom clipping planes. However, I seem to be either doing something wrong for my near/far planes of there is an error in my understanding. I have reached a point in which my <em>&quot;google-fu&quot;</em> has failed me.</p>
  <p>Operating under the assumption that I am correctly extracting clip planes from my glm::perspective matrix, and using the general plane equation:</p>
  <blockquote>
  <p>aX+bY+cZ+d = 0</p>
  </blockquote>
  <p>I am getting strange <strong>d</strong> or <em>&quot;offset&quot;</em> values for my zNear and zFar planes.
  It is my understanding that the <strong>d</strong> value is the value of which I would be shifting/translatin the point P0 of a plane along the normal vector.</p>
  <p>They are 0.200200200 and -0.200200200 respectively. However, my normals are correct orientated at +1.0f and -1.f along the z-axis as expected for a plane perpendicular to my z basis vector.</p>
  <p>So when testing a point such as the (0, 0, -5) world space against these planes, it is transformed by my view matrix to:</p>
  <p>(0, 0, 5.81181192)</p>
  <p>so testing it against these plane in a clip chain, said example vertex would be culled.</p>
  <p>Here is the start of a camera class establishing the relevant matrices:</p>
  <pre><code>static constexpr glm::vec3 UPvec(0.f, 1.f, 0.f);
  static constexpr auto zFar = 100.f;
  static constexpr auto zNear = 0.1f;
  
  
  Camera::Camera(glm::vec3 eye, glm::vec3 center, float fovY, float w, float h) :
  
  viewMatrix{ glm::lookAt(eye, center, UPvec) },
  perspectiveMatrix{ glm::perspective(glm::radians&lt;float&gt;(fovY), w/h, zNear, zFar) },
  
  frustumLeftPlane {setPlane(0, 1)},
  frustumRighPlane {setPlane(0, 0)},
  frustumBottomPlane {setPlane(1, 1)},
  frustumTopPlane {setPlane(1, 0)},
  frstumNearPlane  {setPlane(2, 0)},
  frustumFarPlane {setPlane(2, 1)},
  </code></pre>
  <p>The frustum objects are based off the following struct:</p>
  <pre><code>struct Plane
  {
      glm::vec4 normal;
      float offset;
  };
  </code></pre>
  <p>I have extracted the 6 clipping planes from the perspective matrix as below:</p>
  <pre><code>Plane Camera::setPlane(const int&amp; row, const bool&amp; sign)
  {
      float temp[4]{};
      Plane plane{};
      if (sign == 0)
      {
          for (int i = 0; i &lt; 4; ++i)
          {
              temp[i] = perspectiveMatrix[i][3] + perspectiveMatrix[i][row];
          }
      }
      else
      {
          for (int i = 0; i &lt; 4; ++i)
          {
              temp[i] = perspectiveMatrix[i][3] - perspectiveMatrix[i][row];
          }
      }
  
      plane.normal.x = temp[0];
      plane.normal.y = temp[1];
      plane.normal.z = temp[2];
      plane.normal.w = 0.f;
      plane.offset = temp[3];
      plane.normal = glm::normalize(plane.normal);
  
      return plane;
  }
  </code></pre>
  <p>Any help would be appreciated, as now I am at a loss.</p>
  <p>Many thanks.</p>