Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem2/src/core/input/InputCommands.cc @ 2284

Last change on this file since 2284 was 2087, checked in by landauf, 16 years ago

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 2.7 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#include "core/CommandExecutor.h"
38
39namespace orxonox
40{
41    // ###############################
42    // ###  BufferedParamCommand   ###
43    // ###############################
44
45    /**
46    @brief
47        Executes a buffered command. This is used for commands with additional
48        parameters.
49    @return
50        True if command execution was successful or value was zero.
51    */
52    bool BufferedParamCommand::execute()
53    {
54        if (this->abs_ != 0.0f || this->rel_ != 0.0f)
55        {
56            evaluation_.setEvaluatedParameter(paramIndex_, Vector2(abs_, rel_));
57            // reset
58            rel_ = 0.0;
59            abs_ = 0.0;
60            return evaluation_.execute();
61        }
62        else
63            return true;
64    }
65
66    // ###############################
67    // #####    ParamCommand     #####
68    // ###############################
69
70    /**
71    @brief
72        Executes a parameter command. The commmand string is not directly executed,
73        but instead stored in a buffer list so that values can be combined.
74    @return
75        Always true.
76    */
77    bool ParamCommand::execute(float abs, float rel)
78    {
79        BufferedParamCommand& cmd = *paramCommand_;
80        // command has an additional parameter
81        if (rel != 0.0f)
82        {
83            // calculate relative movement.
84            // scale_ says how much one keystroke is
85            cmd.rel_ += scale_ * rel;
86        }
87
88        if (abs != 0.0f)
89        {
90            cmd.abs_ += scale_ * abs;
91            if (cmd.abs_ > 1.0)
92                cmd.abs_ = 1.0;
93            if (cmd.abs_ < -1.0)
94                cmd.abs_ = -1.0;
95        }
96        return true;
97    }
98}
Note: See TracBrowser for help on using the repository browser.