aboutsummaryrefslogtreecommitdiffstats
path: root/Samples/CommonSrc/Platform/Gamepad.h
blob: d078bdb360616e4c302ab10da55661505a675c77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/************************************************************************************

Filename    :   Gamepad.h
Content     :   Cross platform Gamepad interface.
Created     :   May 6, 2013
Authors     :   Lee Cooper

Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

************************************************************************************/

#ifndef OVR_Gamepad_h
#define OVR_Gamepad_h

#include <OVR_Kernel.h>

namespace OVR { namespace OvrPlatform {

// Buttons on a typical gamepad controller.
enum GamepadButtons
{
    Gamepad_A               = 0x1000,
    Gamepad_CROSS           = 0x1000,
    Gamepad_B               = 0x2000,
    Gamepad_CIRCLE          = 0x2000,
    Gamepad_X               = 0x4000,
    Gamepad_SQUARE          = 0x4000,
    Gamepad_Y               = 0x8000,
    Gamepad_TRIANGLE        = 0x8000,
    Gamepad_Up              = 0x0001,
    Gamepad_Down            = 0x0002,
    Gamepad_Left            = 0x0004,
    Gamepad_Right           = 0x0008,
    Gamepad_Start           = 0x0010,
    Gamepad_Back            = 0x0020,
    Gamepad_LStick          = 0x0040,
    Gamepad_RStick          = 0x0080,
    Gamepad_L1              = 0x0100,
    Gamepad_R1              = 0x0200,
};

//-------------------------------------------------------------------------------------
// ***** GamepadState

// Describes the state of the controller buttons and analog inputs.
struct GamepadState
{
    uint32_t  Buttons;            // Bitfield representing button state.
    float   LX;                 // Left stick X axis [-1,1]
    float   LY;                 // Left stick Y axis [-1,1]
    float   RX;                 // Right stick X axis [-1,1]
    float   RY;                 // Right stick Y axis [-1,1]
    float   LT;                 // Left trigger [0,1]
    float   RT;                 // Right trigger [0,1]

    GamepadState() : Buttons(0), LX(0), LY(0), RX(0), RY(0), LT(0), RT(0) {}

    bool operator==(const GamepadState& b) const
    {
        return Buttons == b.Buttons && LX == b.LX && LY == b.LY && RX == b.RX && RY == b.RY && LT == b.LT && RT == b.RT;
    }
    bool operator!=(const GamepadState& b) const
    {
        return !(*this == b);
    }
	void Debug() const
	{
		OVR_DEBUG_LOG(("Buttons:0x%4x LX:%.2f LY:%.2f RX:%.2f RY:%.2f LT:%.2f RT:%.2f", Buttons, LX, LY, RX, RY, LT, RT));
	}
};

//-------------------------------------------------------------------------------------
// ***** GamepadManager

// GamepadManager provides a cross platform interface for accessing gamepad controller
// state.
class GamepadManager : public RefCountBase<GamepadManager>
{
public:

    // Get the number of connected gamepads.
    virtual uint32_t GetGamepadCount() = 0;

    // Get the state of the gamepad with a given index.
    virtual bool    GetGamepadState(uint32_t index, GamepadState* pState) = 0;
};

}} // OVR::OvrPlatform

#endif // OVR_Gamepad_h