Example #1
0
void SceneManager::loadScenes(SceneList & toLoad)
{
	for(SceneList::iterator e = scenes.begin(); e != scenes.end(); ++e)
		delete *e;
		
	this->scenes.clear();		
		
	for(SceneList::iterator e = toLoad.begin(); e != toLoad.end(); ++e)
		this->scenes.push_back(*e);
		
	// Notify the listeners that a set of scenes has been loaded.
	for(SceneManagerListenerList::iterator e = listeners.begin(); e != listeners.end(); ++e)
		(*e)->sceneListLoaded(this->scenes);
}
Example #2
0
int main()
{
	// Build scene
	SceneList scene;
	
	scene.push_back(new Sphere(Point3(-320,0,50), 200.0f, ColorRGBA(255,0,0,255)));
	scene.push_back(new Sphere(Point3(320, 0, 50), 200.0f, ColorRGBA(0, 0, 255, 255)));
	scene.push_back(new Sphere(Point3(0, 0, -50), 200.0f, ColorRGBA(0, 255, 0, 255)));
	scene.push_back(new Plane(Vector3(0,1,0), Vector3(0, -150, 0), ColorRGBA(255,255,255,255)));
	
	// Render the scene
	RayTraceSettings settings;
	settings.resolutionWidth  = 600;
	settings.resolutionHeight = 480;
	settings.depth = 255;
	settings.clearColor = ColorRGB(50,50,50);
	settings.eyePosition = Point3(0, 0, 600);
	
	RayTracer rayTracer(settings);
	rayTracer.renderScene(scene);
	
	rayTracer.saveToFile("rayTracerTest.tga");

	// Clean up the scene
	std::for_each(scene.begin(), scene.end(), deleteDynamicObject());
	
	return 0;
}
Example #3
0
std::pair<Shape*, float> getClosestShape(const Ray& p_ray, const SceneList& p_scene)
{
	float closestDistance = std::numeric_limits<float>::max();
	Shape* closestShape(nullptr);
	
	for (auto it = p_scene.begin(); it != p_scene.end(); ++it)
	{
		if (*it == nullptr) continue;
		
		float intersectionDistance = (*it)->getFirstIntersection(p_ray);
		
		if (intersectionDistance > 0.0f && intersectionDistance < closestDistance)
		{
			closestDistance = intersectionDistance;
			closestShape = *it;
		}
	}
	return std::make_pair(closestShape, closestDistance);
}