I am working on fixing my problem when I have more then one object, but to be honest I am kind of lost.
From what the output is, it looks the ray hits the wrong sphere and for some reasons place it at a random location.
Here is my sceene:
void Scene::createScene()
{
//Create a container for all the spheres
sphereList = new Sphere*[100];
// Create the scene
// ------------------------------------------
// Sphere1 - a blue one
// A few variables for the first sphere
Vector3D pos1(50,0,0);
Material blue(0,0,200);
// Create the first sphere
sphereList[0] = new Sphere;
sphereList[0]->setPosition(pos1);
sphereList[0]->setRadius(50);
sphereList[0]->setMaterial(blue);
// Sphere2 - a red one
// A few variables for the second sphere
Vector3D pos2(-50,0,0);
Material red(200,0,0);
// Create the second sphere
sphereList[1] = new Sphere;
sphereList[1]->setPosition(pos2);
sphereList[1]->setRadius(50);
sphereList[1]->setMaterial(red);
// Sphere3 - a green one
// A few variables for the second sphere
Vector3D pos3(0,-50,0);
Material green(200,0,0);
// Create the second sphere
sphereList[2] = new Sphere;
sphereList[2]->setPosition(pos2);
sphereList[2]->setRadius(50);
sphereList[2]->setMaterial(green);
/*
// Sphere3 - a light source
sphereList[2] = new Sphere;
sphereList[2]->setLight(1);
*/
// ------------------------------------------
// Done with the scene
// Set how many spheres there are, to make stuff
// easier
noOfObjects = 2;
// Print some info
std::cout << "Scene sucsesfully created" << std::endl;
std::cout << "Two spheres created! " << std::endl;
}
One thing I find weird is that if I change noOfObjects, the blue sphere moves(the blue is the only one that is draw to the picture for some reason)
If noOfObjects = 0 (its is used to acces members in an array) I get this:

If noOfObjects = 1 I get this:

And if noOfObjects = 2 I get the first picture again.
Maybe I have some pointers that point to the wrong thing? Can that be the case?
EDIT:
I found out that closes sphere allways equals the last sphere in my array
// Find closest sphere
if (traceResult.distance < closesSphereDistance )
{
closesSphereDistance = traceResult.distance;
closestSphere = currentSphere;
}
So I guess I am getting closer to finding my problem. I can see how this causes the object to have the same color no matter where it is placed (see above picture) but not why I only get one sphere.




