-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScene.hh
61 lines (52 loc) · 1.5 KB
/
Scene.hh
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
#ifndef SCENE_HH
#define SCENE_HH
#include "Object.hh"
#include "Renderable.hh"
#include <list>
template<class F> class Scene;
template<class F> std::ostream& operator<<(std::ostream& out, const Scene<F>& scene);
template<class F>
class Scene
{
public:
typedef std::list<Object<F>*> ObjectList;
void Step(F timeslice) {
for (typename ObjectList::iterator i = mObjects.begin(); i != mObjects.end(); i++) {
typename ObjectList::iterator j = i;
j++;
for (; j != mObjects.end(); j++) {
(*i)->Interact(*j, timeslice);
}
// (*i)->DampenAngularVelocity(timeslice);
// (*i)->RandomizeAngularVelocity(timeslice);
(*i)->ApplyAngularVelocity(timeslice);
(*i)->ApplyVelocity(timeslice);
}
}
void AddObject(Object<F>* object) {
mObjects.push_back(object);
}
void Render(std::ostream& out) {
for (typename ObjectList::const_iterator i = mObjects.begin(); i != mObjects.end(); i++) {
Object<F>* object = *i;
Renderable<F>* renderable = dynamic_cast<Renderable<F>*>(object);
if (renderable != NULL) {
renderable->Render(out);
}
}
}
private:
friend std::ostream& operator<< <>(std::ostream& out, const Scene<F>& scene);
ObjectList mObjects;
};
template<class F>
std::ostream& operator<<(std::ostream& out, const Scene<F>& scene)
{
out << "(";
for (typename Scene<F>::ObjectList::const_iterator i = scene.mObjects.begin(); i != scene.mObjects.end(); i++) {
out << **i;
}
out << ")";
return out;
}
#endif