73a06f38cc6520c33e96d781fa4890f79ebe1d1a
[universe.git] / dummy.cc
1
2 ////////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or              //
4 // modify it under the terms of the GNU General Public License                //
5 // version 2 as published by the Free Software Foundation.                    //
6 //                                                                            //
7 // This program is distributed in the hope that it will be useful, but        //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                 //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          //
10 // General Public License for more details.                                   //
11 //                                                                            //
12 // Written and (C) by François Fleuret                                        //
13 // Contact <francois.fleuret@epfl.ch> for comments & bug reports              //
14 ////////////////////////////////////////////////////////////////////////////////
15
16 #include "task.h"
17 #include "universe.h"
18 #include "manipulator.h"
19
20 class Dummy : public Task {
21 public:
22
23   virtual char *name() { return "DUMMY"; }
24
25   virtual int nb_degrees() { return 1; }
26
27   virtual int width() { return 600; }
28
29   virtual int height() { return 700; }
30
31   virtual void init(Universe *universe, int degree) {
32     Polygon *p;
33     scalar_t width = 80, height = 80;
34     scalar_t deltax = 100, deltay = 100;
35
36     for(int k = 0; k < 4; k++) {
37       scalar_t x0 = k * deltax;
38       scalar_t y0 = 0;
39       p = new Polygon(1.0, 1.0, scalar_t(k)/scalar_t(4), 0.0, 0, 0, 4);
40       p->set_vertex(0, 0, 0);
41       p->set_vertex(1, width, 0);;
42       p->set_vertex(2, width, height);
43       p->set_vertex(3, 0, height);
44       p->set_position(x0 + deltax/2, y0 + deltay/2, 0);
45       p->set_speed(0, 0, 0);
46       universe->initialize(p);
47       universe->add_polygon(p);
48     }
49
50     for(int k = 0; k < 2; k++) {
51       scalar_t x0 = deltax + k * deltax * 2;
52       scalar_t y0 = deltay;
53       p = new Polygon(1.0, scalar_t(k)/scalar_t(2), 1.0, 0.0, 0, 0, 4);
54       p->set_vertex(0, 0, 0);
55       p->set_vertex(1, width + deltax, 0);;
56       p->set_vertex(2, width + deltax, height);
57       p->set_vertex(3, 0, height);
58       p->set_position(x0, y0 + deltay/2, 0);
59       p->set_speed(0, 0, 0);
60       universe->initialize(p);
61       universe->add_polygon(p);
62     }
63
64     scalar_t x0 = deltax;
65     scalar_t y0 = 2 * deltay;
66     p = new Polygon(1.0, 1.0, 1.0, 0.0, 0, 0, 4);
67     p->set_vertex(0, 0, 0);
68     p->set_vertex(1, width + 3 * deltax, 0);;
69     p->set_vertex(2, width + 3 * deltax, height);
70     p->set_vertex(3, 0, height);
71     p->set_position(x0 + deltax, y0 + deltay/2, 0);
72     p->set_speed(0, 0, 0);
73     universe->initialize(p);
74     universe->add_polygon(p);
75
76     p = new Polygon(1.0, 0.8, 0.2, 0.8, 0, 0, 8);
77     p->set_vertex(0,   0.0,   0.0);
78     p->set_vertex(1, 180.0,   0.0);
79     p->set_vertex(2, 180.0, 220.0);
80     p->set_vertex(3,   0.0, 220.0);
81     p->set_vertex(4,   0.0, 180.0);
82     p->set_vertex(5, 140.0, 180.0);
83     p->set_vertex(6, 140.0,  40.0);
84     p->set_vertex(7,   0.0,  40.0);
85     p->set_position(120, 420, 0);
86     p->set_speed(0, 0, 0);
87     universe->initialize(p);
88     universe->add_polygon(p);
89
90     int ne = 25;
91     p = new Polygon(1.0, 0.0, 0.25, 1.0, 0, 0, ne);
92     for(int e = 0; e < ne; e++) {
93       scalar_t alpha = 2 * M_PI * scalar_t(e) / scalar_t(ne);
94       p->set_vertex(e,  200 + 50 * cos(alpha), 200 + 70 * sin(alpha));
95     }
96     p->set_position(400, 400, 0);
97     p->set_speed(0, 0, 0);
98     universe->initialize(p);
99     universe->add_polygon(p);
100   }
101
102   virtual void update(scalar_t dt, Universe *universe, Manipulator *manipulator) { }
103
104   virtual scalar_t reward(Universe *universe, Manipulator *manipulator) { return 0.0; }
105
106   virtual void draw(SimpleWindow *window) { }
107
108 };
109
110 extern "C" Task *new_task() {
111   return new Dummy();
112 }