Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/libraries/core/input/InputCommands.cc @ 9853

Last change on this file since 9853 was 7401, checked in by landauf, 14 years ago

merged doc branch back to trunk

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30@file
31@brief
32    Implementation of the different input handlers.
33*/
34
35#include "InputCommands.h"
36#include "util/Math.h"
37
38namespace orxonox
39{
40    // ###############################
41    // ###  BufferedParamCommand   ###
42    // ###############################
43
44    /**
45    @brief
46        Executes a buffered command. This is used for commands with additional
47        parameters.
48    @return
49        True if command execution was successful or value was zero.
50    */
51    bool BufferedParamCommand::execute()
52    {
53        if (this->abs_ != 0.0f || this->rel_ != 0.0f)
54        {
55            evaluation_.setEvaluatedArgument(paramIndex_, Vector2(abs_, rel_));
56            // reset
57            rel_ = 0.0;
58            abs_ = 0.0;
59            return evaluation_.execute();
60        }
61        else
62            return true;
63    }
64
65    // ###############################
66    // #####    ParamCommand     #####
67    // ###############################
68
69    /**
70    @brief
71        Executes a parameter command. The commmand string is not directly executed,
72        but instead stored in a buffer list so that values can be combined.
73    @return
74        Always true.
75    */
76    bool ParamCommand::execute(float abs, float rel)
77    {
78        BufferedParamCommand& cmd = *paramCommand_;
79        // command has an additional parameter
80        if (rel != 0.0f)
81        {
82            // calculate relative movement.
83            // scale_ says how much one keystroke is
84            cmd.rel_ += scale_ * rel;
85        }
86
87        if (abs != 0.0f)
88        {
89            cmd.abs_ += scale_ * abs;
90            if (cmd.abs_ > 1.0)
91                cmd.abs_ = 1.0;
92            if (cmd.abs_ < -1.0)
93                cmd.abs_ = -1.0;
94        }
95        return true;
96    }
97}
Note: See TracBrowser for help on using the repository browser.