title: Ray tracing vectors
body: <p>So I decided to write a ray tracer the other day, but I got stuck because I forgot all my vector math.
  I've got a point behind the screen (the eye/camera, 400,300,-1000) and then a point on the screen (a plane, from 0,0,0 to 800,600,0), which I'm getting just by using the x and y values of the current pixel I'm looking for (using SFML for rendering, so it's something like 267,409,0)</p>
  
  <p>Problem is, I have no idea how to cast the ray correctly. I'm using this for testing sphere intersection(C++):</p>
  
  <pre><code>bool SphereCheck(Ray&amp; ray, Sphere&amp; sphere, float&amp; t)
  { //operator * between 2 vec3s is a dot product
      Vec3 dist = ray.start - sphere.pos; //both vec3s
      float B =  -1 * (ray.dir * dist);
      float D = B*B - dist * dist + sphere.radius * sphere.radius; //radius is float
      if(D &lt; 0.0f)
          return false;
      float t0 = B - sqrtf(D);
      float t1 = B + sqrtf(D);
      bool ret = false;
      if((t0 &gt; 0.1f) &amp;&amp; (t0 &lt; t))
      {
          t = t0;
          ret = true;
      }
      if((t1 &gt; 0.1f) &amp;&amp; (t1 &lt; t))
      {
          t = t1;
          ret = true;
      }
      return ret;
  }
  </code></pre>
  
  <p>So I get that the start of the ray would be the eye position, but what is the direction?</p>
  
  <p>Or, failing that, is there a better way of doing this? I've heard of some people using the ray start as (x, y, -1000) and the direction as (0,0,1) but I don't know how that would work.</p>
  
  <p>On a side note, how would you do transformations? I'm assuming that to change the camera angle you just adjust the x and y of the camera (or the screen if you need a drastic change)</p>