I have a class that I have problems with accesing some of the information from
Code:
class Scene
{
public:
...
Sphere getSphere(int i)
private:
Sphere** sphereList;
}
Here is where I add info to the sphereList
Code:
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;
}
And this is how I acces the list later on:
Code:
Sphere Scene::getSphere(int i)
{
return *sphereList[i];
}
But for some reason I dont get the right sphere returned. I looks like getSphere(0) returns the first sphere, but all other values return the last spere.
Any ideas on what is wrong ?
Thanks