1 #ifndef MATERIALFACTORY_HXX
 2 #define MATERIALFACTORY_HXX
 3 
 4 #include <istream>
 5 #include <vector>
 6 
 7 #include "Scene.hxx"
 8 #include "Material.hxx"
 9 #include "Shader.hxx"
10 #include "PhotonDistributor.hxx"
11 #include "SceneMaterialDescription.hxx"
12 
13 class MaterialFactory
14 {
15 	// We use vectors of shaders and according photon distributors. This function
16 	// returns in which vector elements the respective objects can be found,
17 	// according to the face number
18 	int GetVectorPosition(int face)
19 	{
20 		int position = 0;
21 
22 		for (unsigned int i = 0; i < lookupvector.size() && lookupvector.at(i) <= face; ++i)
23 			++position;
24 
25 		return position - 1;
26 	};
27 public:
28 	// The three mentioned vectors (lookup does the mapping)
29 	vector<Shader*>            shaders;
30 	vector<PhotonDistributor*> photondistris;
31 	vector<int>                lookupvector;
32 
33 	// Scene to operate in
34 	Scene *scene;
35 
36 	// Description of available Materials
37 	SceneMaterialDescription *sceneDescription;
38 
39 	// Use a standard white default material if nothing is specified
40 	MaterialFactory(Scene *scene)
41 		:scene(scene), sceneDescription(NULL)
42 	{};
43 
44 	virtual ~MaterialFactory(){};
45 
46 	// Returns the current shader
47 	virtual Shader *GetShader(int count)
48 	{
49 		return shaders.at(GetVectorPosition(count));
50 	};
51 
52 	// Returns the current photon distributor
53 	virtual PhotonDistributor *GetPhotonDistributor(int count)
54 	{
55 		return photondistris.at(GetVectorPosition(count));
56 	};
57 
58 	// Implement this method depending on your shaders
59 	virtual void SetMaterial(std::istream&, const int face) = 0;
60 };
61 
62 #endif


syntax highlighted by Code2HTML, v. 0.9.1