Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 12, 2009, 4:12:04 PM (15 years ago)
Author:
rgrieder
Message:

Added a few more generic parts to the input library:

  • Created Mouse and Keyboard to join JoyStick and provided them with a templated base class (InputDeviceTemplated) that does most of the work (reduces quite some redundancy)
  • Created InputPrereqs.h from InputInterfaces.h and destroyed the latter
  • Exported InputHandler to its own file and replaced KeyHandler, MouseHandler and JoyStickHandler with the single InputHandler.
  • Deleted the SimpleInputState: There is only one class now which fulfills all our needs.

In general there is now less code and the code itself has more 'pluses'. However I haven't really thrown away any feature at all.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/input/JoyStick.h

    r3270 r3274  
    2727 */
    2828
    29 /**
    30 @file
    31 @brief
    32 */
     29#ifndef _Core_JoyStick_H__
     30#define _Core_JoyStick_H__
    3331
    34 #ifndef _JoyStick_H__
    35 #define _JoyStick_H__
    36 
    37 #include "core/CorePrereqs.h"
     32#include "InputPrereqs.h"
    3833
    3934#include <string>
    4035#include <vector>
    41 #include "InputInterfaces.h"
     36#include "InputDevice.h"
    4237
    4338namespace orxonox
    4439{
    45     class _CoreExport JoyStick : public OrxonoxClass, public OIS::JoyStickListener
     40    /**
     41    @brief
     42        Wraps around an OIS::JoyStick and forwards the input events to
     43        a list of input states.
     44
     45        The class also supports joy stick calibration and stores the values
     46        in an ini-file.
     47    */
     48    class _CoreExport JoyStick
     49        : public OrxonoxClass
     50        , public InputDeviceTemplated<JoyStickTraits>
     51        , public OIS::JoyStickListener
    4652    {
    47     private:
    48         struct JoyStickCalibration
    49         {
    50         };
     53        friend class InputDeviceTemplated<JoyStickTraits>;
     54        //! Super class alias
     55        typedef InputDeviceTemplated<JoyStickTraits> super;
    5156
    5257    public:
    53         JoyStick(const std::vector<InputState*>& states, unsigned int id);
    54         ~JoyStick();
    55 
     58        //! Assigns a generated ID string and loads the calibration (if present)
     59        JoyStick(unsigned int id);
     60        ~JoyStick() { }
    5661        void setConfigValues();
    5762
    58         OIS::JoyStick* getOISJoyStick() { return this->oisJoyStick_; }
     63        //! Returns the generated (from the number of knobs and the device name) ID string
    5964        const std::string& getIDString() const { return this->idString_; }
    6065
    61         void startCalibration();
    62         void stopCalibration();
     66    private:
     67        void calibrationStarted();
     68        void calibrationStopped();
     69        void evaluateCalibration();
    6370
    64         void capture();
    65         void clearBuffer();
    66 
    67     private:
     71        void clearBuffersImpl();
    6872        void calibrationFileCallback();
    69         void evaluateCalibration();
    7073        void fireAxis(int axis, int value);
    7174
    72         bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
    73         bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     75        //! OIS event handler
     76        bool buttonPressed (const OIS::JoyStickEvent &arg, int button)
     77        {
     78            super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button));
     79            return true;
     80        }
     81
     82        //! OIS event handler
     83        bool buttonReleased(const OIS::JoyStickEvent &arg, int button)
     84        {
     85            super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button));
     86            return true;
     87        }
     88
    7489        bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
    7590        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    7691        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    77         // don't remove that! Or else add OIS as dependency library to orxonox (it actually is..)
     92        //!< OIS event handler (don't remove that because of OIS version issues!)
    7893        bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
    7994
    80         static const unsigned int sliderAxes_s = 8;
    81 
    82         OIS::JoyStick* oisJoyStick_;
    83         const unsigned int id_;
    84         std::string idString_;
     95        std::string idString_;                //!< ID string generated by the number of knobs and the device name
     96        int povStates_[4];                    //!< Internal states for the POVs
     97        int sliderStates_[4][2];              //!< Internal states for the Sliders (each slider has X and Y!)
    8598
    8699        // calibration
    87         bool bCalibrating_;
    88         int zeroValues_[24];
    89         float positiveCoeffs_[24];
    90         float negativeCoeffs_[24];
     100        int zeroValues_[24];                  //!< Axes values when the knob is in the middle
     101        float positiveCoeffs_[24];            //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range
     102        float negativeCoeffs_[24];            //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range
    91103
    92         std::vector<int> configMinValues_;
    93         std::vector<int> configMaxValues_;
    94         std::vector<int> configZeroValues_;
    95 
    96         int povStates_[4];
    97         int sliderStates_[4][2];
    98         std::vector<JoyStickButtonCode::ByEnum> pressedButtons_;
    99 
    100         // InputState handling
    101         const std::vector<InputState*>& inputStates_;
     104        std::vector<int> configZeroValues_;   //!< Config file stored axis values when the knob is in the middle
     105        std::vector<int> configMinValues_;    //!< Config file stored minimum axis values
     106        std::vector<int> configMaxValues_;    //!< Config file stored maximum axis values
    102107
    103108        // ConfigValues
    104         std::string calibrationFilename_;  //!< Joy stick calibration ini filename
     109        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
     110
     111        //!< Maximum number of slider axes
     112        static const unsigned int sliderAxes_s = 8;
    105113    };
    106114}
    107115
    108 #endif /* _JoyStick_H__ */
     116#endif /* _Core_JoyStick_H__ */
Note: See TracChangeset for help on using the changeset viewer.