title: For mouse click ray casting a line, why aren't my starting rays updating to my camera position after I move my camera?
body: <p>When camera is moved around, why are my starting rays are still stuck at origin 0, 0, 0 even though the camera position has been updated?</p>
  <p>It works fine if I start the program and my camera position is at default 0, 0, 0. But once I move my camera for instance pan to the right and click some more, the lines are still coming from 0 0 0 when it should be starting from wherever the camera is. Am I doing something terribly wrong? I've checked to make sure they're being updated in the main loop. I've used this code snippit below referenced from:<br>
  <a href="https://stackoverflow.com/questions/20140711/picking-in-3d-with-ray-tracing-using-ninevehgl-or-opengl-i-phone">picking in 3D with ray-tracing using NinevehGL or OpenGL i-phone</a></p>
  <pre><code>// 1. Get mouse coordinates then normalize
  float x = (2.0f * lastX) / width - 1.0f;
  float y = 1.0f - (2.0f * lastY) / height;
  
  // 2. Move from clip space to world space
  glm::mat4 inverseWorldMatrix = glm::inverse(proj * view);
  glm::vec4 near_vec = glm::vec4(x, y, -1.0f, 1.0f);
  glm::vec4 far_vec = glm::vec4(x, y, 1.0f, 1.0f);
  glm::vec4 startRay = inverseWorldMatrix * near_vec;
  glm::vec4 endRay = inverseWorldMatrix * far_vec;
  
  // perspective divide
  startR /= startR.w;
  endR /= endR.w;
  
  glm::vec3 direction = glm::vec3(endR - startR);
  
  // start the ray points from the camera position
  glm::vec3 startPos = glm::vec3(camera.GetPosition());
  glm::vec3 endPos = glm::vec3(startPos + direction * someLength);
  </code></pre>
  <p>The first screenshot I click some rays, the 2nd I move my camera to the right and click some more but the initial starting rays are still at 0, 0, 0. What I'm looking for is for the rays to come out wherever the camera position is in the 3rd image, ie the red rays sorry for the confusion, the red lines are supposed to shoot out and into the distance not up.</p>
  <p><a href="https://i.stack.imgur.com/PxP3u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PxP3u.png" alt="3d ray casting mouse clicks" /></a></p>
  <pre><code>// and these are my matrices
  // projection
  glm::mat4 proj = glm::perspective(glm::radians(camera.GetFov()), (float)width / height, 0.1f, 100.0f);
  // view
  glm::mat4 view = camera.GetViewMatrix(); // This returns glm::lookAt(this-&gt;Position, this-&gt;Position + this-&gt;Front, this-&gt;Up);
  // model
  glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f));
  </code></pre>