-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTouch.h
More file actions
164 lines (150 loc) · 4.85 KB
/
Touch.h
File metadata and controls
164 lines (150 loc) · 4.85 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (C) 2013 MoSync AB
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, version 2, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#ifndef TOUCH_H_
#define TOUCH_H_
#include <MAUtil/Environment.h>
#include <glm/glm.hpp>
#include <hash_map>
namespace MoGraph
{
/**
* \brief TouchState event
*/
enum TouchState{ Idle, Pressed, Moving, Released };
/**
* \brief Touch is a sturct that contains all info around a touch event.
*/
struct Touch
{
/**
* \brief Touch, Constructor
*/
Touch() : mPos(glm::vec2(0.0f,0.0f)),mOldPos(glm::vec2(0.0f,0.0f)), mId(0), mState(Idle) {}
/**
* \brief Touch, Constructor
* @param p, touch position in glm::vec2
* @param id, touch id
* @param state state see TouchState
*/
Touch(MAPoint2d &p, int id, TouchState state) : mPos(glm::vec2((float)p.x,(float)p.y)),mOldPos(glm::vec2((float)p.x,(float)p.y)), mId(id), mState(state) {}
glm::vec2 mPos; // Position of a touch
glm::vec2 mOldPos; // previous position of a touch
int mId; // touch index
TouchState mState; // state if event
};
typedef std::pair<int, Touch> TouchPair;
/**
* \brief TouchInput class used for handling the swipes for rotation and double swipe for scaling
*/
class TouchInput : public MAUtil::PointerListener
{
protected:
int mTouchActive;
std::hash_map<int, Touch> mTouch; // table of touch
glm::vec3 mRotSpeed; // calculated rotation speed
glm::vec3 mRotPos; // calculated rotation position
glm::vec2 mScalePosArr[2]; // Scale (reqd two touch position)
float mScalePos; // distance between 2 positions
float mScaleOldPos; // previous diance between 2 posions
float mDelta; // output scale speed
float mOldZ;
int mWidth;
int mHeight; // Screen resolution in ABS form e.g. 640,480
/**
* \brief getSpeed, gets the speed of touch from 2 different frames
* \note handles double touch speed=scale and single touch speed
* @param t, touch struct containing events and positions
* @param speed, input/output, speed.
* @return speed returns
*/
glm::vec3 getSpeed(Touch &t, glm::vec3 &speed);
public:
/**
* \brief TouchInput, Constructor
*/
TouchInput();
/**
* \brief ~TouchInput, Destructor
*/
virtual ~TouchInput(){}
/**
* \brief init, initiate the touch system by setting up screen limits.
* @param mWidth, screen width
* @param mHeight, screen height
*/
virtual void init(int mWidth, int mHeight);
/**
* \brief update, update swipe,scale to output rotation or scale
*/
virtual void update();
/**
* \brief getScale, scale for screen
* @return
*/
virtual float getScale() {return mDelta;}
/**
* \brief getAngularOrientation, in degrees
* @return yaw angle and pitch angle (y,x) in prio order
*/
virtual glm::vec3 getAngularOrientation() {return mRotPos;}
/**
* \brief getAngularSpeed, in degrees
* @return yaw speed angle and pitch speed angle (y,x) in prio order
*/
virtual glm::vec3 getAngularSpeed() {return mRotSpeed;}
// optional multi touch is in use here
/**
* \brief multitouchPressEvent, fwd events from the event handler to here
* \note optional, if user wants to use TouchInput class to handle this
* @param p, point in 2D
* @param touchId, touch index
*/
virtual void multitouchPressEvent(MAPoint2d p, int touchId);
/**
* \brief multitouchMoveEvent, fwd events from the event handler to here
* \note optional, if user wants to use TouchInput class to handle this
* @param p, point in 2D
* @param touchId, touch index
*/
virtual void multitouchMoveEvent(MAPoint2d p, int touchId);
/**
* \brief multitouchReleaseEvent, fwd events from the event handler to here
* \note optional, if user wants to use TouchInput class to handle this
* @param p, point in 2D
* @param touchId, touch index
*/
virtual void multitouchReleaseEvent(MAPoint2d p, int touchId);
// optional input handler pointers not in use
/**
* \brief pointerPressEvent
* \note not in use
* @param p
*/
virtual void pointerPressEvent(MAPoint2d p) {};
/**
* \brief pointerMoveEvent
* \note not in use
* @param p
*/
virtual void pointerMoveEvent(MAPoint2d p) {};
/**
* \brief pointerReleaseEvent
* \note not in use
* @param p
*/
virtual void pointerReleaseEvent(MAPoint2d p) {};
};
}
#endif /* TOUCH_H_ */