I am completely new to ray tracing and am having a problem with displaying a cylinder. I have implemented the code to find a sphere and have been following the tutorial I found here: http://woo4.me/wootracer/cylinder-intersection/ to add a simple cylinder (infinite to start). I have the following code written but get a solid flat surface across the image no matter what coordinates I give the cylinder. Can anyone give me a hint as to where I'm going wrong? I've searched google for three days and searched through Stack Overflow and have tried multiple ways suggested in forums and tutorials to no avail so hopefully someone here can see where I'm going wrong?? Thanks in advance!!
virtual double findIntersection(Ray ray){
Vect rayOrigin = ray.getRayOrigin();
double rayOriginX = rayOrigin.getVectX();
double rayOriginY = rayOrigin.getVectY();
double rayOriginZ = rayOrigin.getVectZ();
Vect rayDirection = ray.getRayDirection();
double rayDirectionX = rayDirection.getVectX();
double rayDirectionY = rayDirection.getVectY();
double rayDirectionZ = rayDirection.getVectZ();
//a=d x2 + d y2 b = ex d x + e y d y c = ex2 + e y2−1
double a = rayDirectionX * rayDirectionX + rayDirectionY * rayDirectionY;
double b = 2* rayOriginX * rayDirectionX + 2* rayOriginY * rayDirectionY;
double c = rayOriginX * rayOriginX + rayOriginY * rayOriginY - 1;
double discriminant = b*b - 4 * a*c;
if (discriminant > 0){
//ray intersects
double root1 = ((-1 * b - sqrt(discriminant)) / 2*a - 0.0001);
if (root1 > 0){
return root1; //first root is the smallest positive value
}
else{
double root2 = ((sqrt(discriminant) - b) / 2*a - 0.0001);
return root2; //the second root is the smallest positive value
}
}
else{
//ray misses the Cylinder
return -1;
}
}
![enter image description here][1]};