-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.h
More file actions
105 lines (95 loc) · 2.85 KB
/
scene.h
File metadata and controls
105 lines (95 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
// Needed on MsWindows
#include <windows.h>
#endif // Win32 platform
#include <GLUT/glut.h>
#include "float2.h"
#include "float3.h"
#include "Mesh.h"
#include <vector>
#include <map>
#include "camera.h"
#include "light.h"
#include "material.h"
#include "object.h"
class Scene
{
Camera camera;
std::vector<LightSource*> lightSources;
std::vector<Object*> objects; //instead of 'intersectables'
std::vector<Material*> materials;
std::vector<MeshInstance*> meshes;
public:
Scene() {}
void initialize() {
lightSources.push_back(
new DirectionalLight(
float3(-0.5, 0, -0.5),
float3(0.2, 0.2, 0.2)));
lightSources.push_back(
new DirectionalLight(
float3(0.5, 0, 0.5),
float3(0.1, 0.1, 0.1)));
lightSources.push_back(
new DirectionalLight(
float3(0, 1, 0),
float3(0.5, 0.5, 0.5)));
Material* greenDiffuseMaterial = new Material();
greenDiffuseMaterial->kd = float3(0, 1, 0);
materials.push_back(greenDiffuseMaterial);
TexturedMaterial * f = new TexturedMaterial("star.jpg", GL_LINEAR);
f->kd = float3(1,1,1);
materials.push_back(f);
Avatar * arm = new Avatar(greenDiffuseMaterial,new Mesh("androidarm2.obj"), true);
Ground* g = new Ground(f);
objects.push_back(g);
Avatar * m = new Avatar(greenDiffuseMaterial,new Mesh("androidbody.obj"), false);
objects.push_back(m);
objects.push_back(arm);
}
~Scene()
{
for (std::vector<LightSource*>::iterator iLightSource = lightSources.begin(); iLightSource != lightSources.end(); ++iLightSource)
delete *iLightSource;
for (std::vector<Material*>::iterator iMaterial = materials.begin(); iMaterial != materials.end(); ++iMaterial)
delete *iMaterial;
for (std::vector<Object*>::iterator iObject = objects.begin(); iObject != objects.end(); ++iObject)
delete *iObject;
}
void move(double t, double dt, bool HELICAM)
{
for (unsigned int iObject=0; iObject<objects.size(); iObject++)
objects.at(iObject)->move(t, dt, &camera, HELICAM);
}
Camera& getCamera()
{
return camera;
}
void control(std::vector<bool>& keysPressed)
{
std::vector<Object*> spawn;
for (unsigned int iObject=0;
iObject<objects.size(); iObject++)
objects.at(iObject)->control(
keysPressed, objects);
}
void draw()
{
camera.apply();
unsigned int iLightSource=0;
for (; iLightSource<lightSources.size(); iLightSource++)
{
glEnable(GL_LIGHT0 + iLightSource);
lightSources.at(iLightSource)->apply(GL_LIGHT0 + iLightSource);
}
for (; iLightSource<GL_MAX_LIGHTS; iLightSource++)
glDisable(GL_LIGHT0 + iLightSource);
for (unsigned int iObject=0; iObject<objects.size(); iObject++)
objects.at(iObject)->draw();
for (unsigned int iMesh=0; iMesh<meshes.size(); iMesh++)
meshes.at(iMesh)->draw();
}
};