1 | #include ".\scene.h"
|
---|
2 |
|
---|
3 | Scene::Scene(void)
|
---|
4 | {
|
---|
5 | }
|
---|
6 |
|
---|
7 | Scene::~Scene(void)
|
---|
8 | {
|
---|
9 | }
|
---|
10 |
|
---|
11 | void Scene::Load(char* filename)
|
---|
12 | {
|
---|
13 | fprintf(stderr, "Loading scene:");
|
---|
14 | fprintf(stderr, filename);
|
---|
15 |
|
---|
16 | ifstream file(filename);
|
---|
17 |
|
---|
18 | char* tempchar=new char[500];
|
---|
19 | file.getline(tempchar,500,'\n');
|
---|
20 | sscanf(tempchar,"Objectcount %ui",&m_ObjectCount);
|
---|
21 | file.getline(tempchar,500,'\n');
|
---|
22 | sscanf(tempchar,"Lightcount %ui",&m_LightCount);
|
---|
23 | file.getline(tempchar,500,'\n');
|
---|
24 | sscanf(tempchar,"Materialcount %ui",&m_MaterialCount);
|
---|
25 | file.getline(tempchar,500,'\n');
|
---|
26 |
|
---|
27 | m_Objects=new Object[m_ObjectCount];
|
---|
28 | m_Lights=new Light[m_LightCount];
|
---|
29 | m_Materials=new Material[m_MaterialCount];
|
---|
30 |
|
---|
31 | fprintf(stderr, " objectcount %i ",m_ObjectCount);
|
---|
32 | fprintf(stderr, "lightcount %i ",m_LightCount);
|
---|
33 | fprintf(stderr, "materialcount %i\n",m_MaterialCount);
|
---|
34 |
|
---|
35 | for(unsigned i=0;i<m_LightCount;i++)
|
---|
36 | {
|
---|
37 | file.getline(tempchar,500,'\n');
|
---|
38 | m_Lights[i].Load(&file);
|
---|
39 | }
|
---|
40 | unsigned int objcount=0;
|
---|
41 | for(int i=0;i<m_MaterialCount;i++)
|
---|
42 | {
|
---|
43 | file.getline(tempchar,500,'\n');
|
---|
44 | file.getline(tempchar,500,'\n');
|
---|
45 | sscanf(tempchar,"connectedObjectCount: %ui",&m_Materials[i].m_ConnectedobjectCount);
|
---|
46 | m_Materials[i].Load(&file);
|
---|
47 |
|
---|
48 | for(unsigned int j=0;j<m_Materials[i].m_ConnectedobjectCount;j++)
|
---|
49 | {
|
---|
50 | file.getline(tempchar,500,'\n');
|
---|
51 | m_Objects[objcount].Load(&file);
|
---|
52 | objcount++;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | }
|
---|
57 |
|
---|
58 | void Scene::Display(bool lighting)
|
---|
59 | {
|
---|
60 | unsigned int objcount=0;
|
---|
61 | //set Light
|
---|
62 | if(m_LightCount>0)
|
---|
63 | {
|
---|
64 | glEnable(GL_LIGHTING);
|
---|
65 | glEnable(GL_LIGHT0);
|
---|
66 | m_Lights[0].SetLight(GL_LIGHT0);
|
---|
67 | if(m_LightCount>1)
|
---|
68 | {
|
---|
69 | glEnable(GL_LIGHTING);
|
---|
70 | glEnable(GL_LIGHT1);
|
---|
71 | m_Lights[1].SetLight(GL_LIGHT1);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | for(unsigned int i=0;i<m_MaterialCount;i++)
|
---|
75 | {
|
---|
76 | m_Materials[i].setMaterial();
|
---|
77 | for(unsigned int j=0;j<m_Materials[i].m_ConnectedobjectCount;j++)
|
---|
78 | {
|
---|
79 | m_Objects[objcount].Rendermodel();
|
---|
80 | objcount++;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | } |
---|