automatic commit
[universe.git] / manipulator.h
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 #ifndef MANIPULATOR_CC
17 #define MANIPULATOR_CC
18
19 #include "misc.h"
20 #include "map.h"
21 #include "universe.h"
22 #include "task.h"
23
24 class Manipulator : public Map {
25   static const int sqsize = 16;
26   Polygon *_touching_polygon, *_current_polygon;
27   scalar_t _grab_relative_x, _grab_relative_y;
28   scalar_t _xmax, _ymax;
29   scalar_t _hand_x, _hand_y;
30   scalar_t _force_x, _force_y;
31   bool _grab, _release;
32   int _current_action;
33   enum { FEEL_TOUCHING_OBJECT, FEEL_GRABBING_OBJECT, NB_DISCRETE_PARAMETERS };
34   enum { MAP_LOCATION_X, MAP_LOCATION_Y, MAP_RESISTANCE_X, MAP_RESISTANCE_Y, NB_CONTINUOUS_MAPS };
35   static const int continuous_map_size = 25;
36   scalar_t _kernel_continuous_maps[continuous_map_size * 2 + 1];
37 public:
38   enum { ACTION_IDLE,
39          ACTION_MOVE_UP, ACTION_MOVE_RIGHT, ACTION_MOVE_DOWN, ACTION_MOVE_LEFT,
40          ACTION_GRAB, ACTION_RELEASE,
41          NB_ACTIONS };
42   Manipulator(Task *task);
43
44   inline scalar_t hand_x() { return _hand_x; }
45   inline scalar_t hand_y() { return _hand_y; }
46   inline Polygon *grabbing() { return _current_polygon; }
47
48   int nb_actions();
49   void do_action(int action);
50
51   void update_map();
52   void update(scalar_t dt, Universe *universe);
53
54   int parameter_width();
55   int parameter_height();
56   void draw_parameters(int x0, int y0, SimpleWindow *window);
57   void draw_on_universe(SimpleWindow *window);
58
59   int random_action();
60
61 //   void force_grab(Universe *universe, scalar_t x, scalar_t y);
62   void force_move(scalar_t x, scalar_t y);
63   void force_release();
64 };
65
66 #endif