Statistics
| Branch: | Tag: | Revision:

hlrc / server / include / Animation.h @ f150aab5

History | View | Annotate | Download (2.735 KB)

1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

    
29
#pragma once
30
#include <humotion/gaze_state.h>
31
#include "boost/date_time/posix_time/posix_time.hpp"
32
#include <boost/thread/thread_time.hpp>
33
#include <boost/thread/thread.hpp>
34

    
35
class Animation {
36
public:
37
        Animation();
38
        ~Animation();
39

    
40
        void apply_on_gazestate(humotion::GazeState* gaze);
41
        void start();
42
        bool is_active();
43
        bool collides_with(Animation* ani);
44

    
45
        typedef enum
46
        {
47
                IDLE = 0,
48
                HEAD_NOD,
49
                HEAD_SHAKE,
50
                EYEBLINK_L,
51
                EYEBLINK_R,
52
                EYEBLINK_BOTH,
53
                EYEBROWS_RAISE,
54
                EYEBROWS_LOWER,
55
                ENGAGEMENT_LEFT,
56
                ENGAGEMENT_RIGHT
57
        } AnimationType_t;
58

    
59
        AnimationType_t target;
60
        unsigned int repetitions;
61
        unsigned int duration_each; // in ms
62
        float scale;
63

    
64
        std::string type_as_string() {
65
                switch ((int)target) {
66
                        case (IDLE):
67
                                return "IDLE";
68
                        case (HEAD_NOD):
69
                                return "HEAD_NOD";
70
                        case (HEAD_SHAKE):
71
                                return "HEAD_SHAKE";
72
                        case (EYEBLINK_L):
73
                                return "EYEBLINK_L";
74
                        case (EYEBLINK_R):
75
                                return "EYEBLINK_R";
76
                        case (EYEBLINK_BOTH):
77
                                return "EYEBLINK_BOTH";
78
                        case (EYEBROWS_RAISE):
79
                                return "EYEBROWS_RAISE";
80
                        case (EYEBROWS_LOWER):
81
                                return "EYEBROWS_LOWER";
82
                        case (ENGAGEMENT_LEFT):
83
                                return "ENGAGEMENT_LEFT";
84
                        case (ENGAGEMENT_RIGHT):
85
                                return "ENGAGEMENT_RIGHT";
86
                        default:
87
                                return "INVALID ID!";
88
                }
89
        }
90

    
91
        std::string as_string() {
92
                char buf[256];
93
                snprintf(buf, 255, "Animation: %d times %s (duration each = %dms)", repetitions, type_as_string().c_str(),
94
                         duration_each);
95
                return buf;
96
        }
97

    
98
private:
99
        float apply_motion_profile_positive(float tn);
100
        float apply_motion_profile_symmetric(float tn, unsigned int rep);
101
        float apply_motion_profile_asymmetric(float tn, unsigned int rep);
102

    
103
        bool active;
104
        unsigned int repetition_now;
105
        boost::system_time end_time;
106
        boost::system_time start_time;
107
};