-
Notifications
You must be signed in to change notification settings - Fork 1
/
ofkMultiTouchEvent.h
executable file
·97 lines (67 loc) · 2.35 KB
/
ofkMultiTouchEvent.h
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
#ifndef _ofkMultiTouchEvent_
#define _ofkMultiTouchEvent_
#include "ofMain.h"
/*
PLEASE create this function in testApp class
testAPp.h ________________
void touchTwoFinger ( ofkMultiTouchEventArgs &touch );
ofkMultiTouchEvent multiTouchEvent;
testAPp.cpp ________________
INSIDE [ void testApp :: setup() ]
multiTouchEvent.enable();
ofAddListener(multiTouchEvent.touchTwoFingerEvent, this, &testApp::touchTwoFinger) ;
///
void testApp :: touchTwoFinger ( ofkMultiTouchEventArgs &multiTouch )
{
//multiTouch.pinchLengthDif
}
///
*/
class ofkMultiTouchEventArgs : public ofEventArgs
{
public:
int time;
float angle;
float angleDif;
float pinchLength;
float pinchLengthDif;
float pinchLengthFromStart;
ofPoint centroidPos;
ofPoint centroidPosDif;
};
class ofkMultiTouchEvent{
public:
ofkMultiTouchEvent();
//THIS FUNCTION can be override
virtual void setTouchPos(int index, float x, float y);
void enable(){
//send touchDownEvent into touchDownMulti to check multi touch Event
ofAddListener(ofEvents().touchDown, this, &ofkMultiTouchEvent::touchDownMulti);
ofAddListener(ofEvents().touchMoved, this, &ofkMultiTouchEvent::touchMoveMulti);
ofAddListener(ofEvents().touchUp, this, &ofkMultiTouchEvent::touchUpMulti);
}
void disable(){
//remove touchDownEvent
ofRemoveListener(ofEvents().touchDown, this, &ofkMultiTouchEvent::touchDownMulti);
ofRemoveListener(ofEvents().touchMoved, this, &ofkMultiTouchEvent::touchMoveMulti);
ofRemoveListener(ofEvents().touchUp, this, &ofkMultiTouchEvent::touchUpMulti);
}
virtual void touchDownMulti(ofTouchEventArgs &touch);
virtual void touchMoveMulti(ofTouchEventArgs &touch);
virtual void touchUpMulti(ofTouchEventArgs &touch);
ofEvent<ofkMultiTouchEventArgs> touchTwoFingerEvent;
void debugDraw();
protected:
//calclate touch event and nofify event
// this function is actually most important
void calcAndNotifyTouchEvent();
void changeFingerNumber();
const static int TOUCHNUMMAX = 5;
ofVec2f mTouchPos[TOUCHNUMMAX];
int mCurrentTouchPointNum;
ofVec2f mVecBetweenTwoFingerStart;
ofVec2f mVecBetweenTwoFinger;
ofVec2f mAvarageVector;
float mDegTwoFinger;
};
#endif /* OFXEVENTSADDON_H_ */