Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 19, 2009, 5:31:02 PM (15 years ago)
Author:
rgrieder
Message:

Merged all remaining revisions from core4 back to the trunk.

Location:
code/trunk
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/input/JoyStick.h

    r3270 r3327  
    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    //! Template parameter collection for the base class
     41    struct JoyStickTraits
    4642    {
    47     private:
    48         struct JoyStickCalibration
    49         {
    50         };
     43        typedef JoyStick DeviceClass;
     44        typedef OIS::JoyStick OISDeviceClass;
     45        typedef JoyStickButtonCode::ByEnum ButtonType;
     46        typedef JoyStickButtonCode::ByEnum ButtonTypeParam;
     47        static const OIS::Type OISDeviceValue = OIS::OISJoyStick;
     48    };
     49
     50    /**
     51    @brief
     52        Wraps around an OIS::JoyStick and forwards the input events to
     53        a list of input states.
     54
     55        The class also supports joy stick calibration and stores the values
     56        in an ini-file.
     57    */
     58    class _CoreExport JoyStick
     59        : public OrxonoxClass
     60        , public InputDeviceTemplated<JoyStickTraits>
     61        , public OIS::JoyStickListener
     62    {
     63        friend class InputDeviceTemplated<JoyStickTraits>;
     64        //! Super class alias
     65        typedef InputDeviceTemplated<JoyStickTraits> super;
    5166
    5267    public:
    53         JoyStick(const std::vector<InputState*>& states, unsigned int id);
    54         ~JoyStick();
    55 
     68        //! Assigns a generated ID string and loads the calibration (if present)
     69        JoyStick(unsigned int id, OIS::InputManager* oisInputManager);
     70        ~JoyStick() { }
    5671        void setConfigValues();
    5772
    58         OIS::JoyStick* getOISJoyStick() { return this->oisJoyStick_; }
    59         const std::string& getIDString() const { return this->idString_; }
    60 
    61         void startCalibration();
    62         void stopCalibration();
    63 
    64         void capture();
    65         void clearBuffer();
     73        //! Returns the name generated from the number of knobs and the device name
     74        const std::string& getDeviceName() const { return this->deviceName_; }
    6675
    6776    private:
     77        void calibrationStarted();
     78        void calibrationStopped();
     79        void evaluateCalibration();
     80
     81        void clearBuffersImpl();
    6882        void calibrationFileCallback();
    69         void evaluateCalibration();
    7083        void fireAxis(int axis, int value);
    7184
    72         bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
    73         bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     85        //! OIS event handler
     86        bool buttonPressed (const OIS::JoyStickEvent &arg, int button)
     87        {
     88            super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button));
     89            return true;
     90        }
     91
     92        //! OIS event handler
     93        bool buttonReleased(const OIS::JoyStickEvent &arg, int button)
     94        {
     95            super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button));
     96            return true;
     97        }
     98
    7499        bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
    75100        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    76101        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..)
     102        //! OIS event handler (don't remove that because of OIS version issues!)
    78103        bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
    79104
    80         static const unsigned int sliderAxes_s = 8;
     105        //! Returns the class name as string
     106        static std::string getClassNameImpl() { return "JoyStick"; }
    81107
    82         OIS::JoyStick* oisJoyStick_;
    83         const unsigned int id_;
    84         std::string idString_;
     108        std::string deviceName_;              //!< Name generated by the number of knobs and the device name
     109        int povStates_[4];                    //!< Internal states for the POVs
     110        int sliderStates_[4][2];              //!< Internal states for the Sliders (each slider has X and Y!)
    85111
    86112        // calibration
    87         bool bCalibrating_;
    88         int zeroValues_[24];
    89         float positiveCoeffs_[24];
    90         float negativeCoeffs_[24];
     113        int zeroValues_[24];                  //!< Axes values when the knob is in the middle
     114        float positiveCoeffs_[24];            //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range
     115        float negativeCoeffs_[24];            //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range
    91116
    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_;
     117        std::vector<int> configZeroValues_;   //!< Config file stored axis values when the knob is in the middle
     118        std::vector<int> configMinValues_;    //!< Config file stored minimum axis values
     119        std::vector<int> configMaxValues_;    //!< Config file stored maximum axis values
    102120
    103121        // ConfigValues
    104         std::string calibrationFilename_;  //!< Joy stick calibration ini filename
     122        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
     123
     124        //! Contains a list of all names to avoid duplicates
     125        static std::vector<std::string> deviceNames_s;
     126
     127        //!< Maximum number of slider axes
     128        static const unsigned int sliderAxes_s = 8;
    105129    };
    106130}
    107131
    108 #endif /* _JoyStick_H__ */
     132#endif /* _Core_JoyStick_H__ */
Note: See TracChangeset for help on using the changeset viewer.