Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
0fc618e5
Commit
0fc618e5
authored
May 18, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed rotation (finally).
parent
35a46583
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
42 deletions
+31
-42
src/touch.py
src/touch.py
+31
-42
No files found.
src/touch.py
View file @
0fc618e5
...
...
@@ -36,13 +36,19 @@ GESTURE_UPDATE_RATE = 60
DIST_THRESHOLD
=
1.
/
max
(
screen_size
)
def
angle_mod
(
angle
):
if
angle
>
pi
:
angle
-=
2
*
pi
elif
angle
<
-
pi
:
angle
+=
2
*
pi
def
rotation
(
p0
,
p1
):
"""
Calculate the relative rotation from p0 to p1 around (0, 0) in radians.
"""
rot
=
atan2
(
*
p1
)
-
atan2
(
*
p0
)
return
angle
# Assert that the smallest possible rotation value is returned
if
rot
>=
pi
:
rot
=
2
*
pi
-
rot
elif
rot
<=
-
pi
:
rot
=
-
2
*
pi
-
rot
return
rot
def
distance
(
a
,
b
):
...
...
@@ -114,21 +120,11 @@ class TouchPoint(object):
def
is_stationary
(
self
):
return
self
.
distance_to_prev
()
<
DIST_THRESHOLD
def
angle_diff
(
self
,
cx
,
cy
):
angle
=
atan2
(
cy
-
self
.
y
,
self
.
x
-
cx
)
if
self
.
prev_angle
==
None
:
delta
=
0
elif
self
.
prev_angle
>
0
and
angle
<
0
:
delta
=
-
2
*
pi
-
angle
+
self
.
prev_angle
elif
self
.
prev_angle
<
0
and
angle
>
0
:
delta
=
2
*
pi
-
angle
+
self
.
prev_angle
else
:
delta
=
angle
-
self
.
prev_angle
self
.
prev_angle
=
angle
def
rotation_around
(
self
,
cx
,
cy
):
prev
=
self
.
px
-
cx
,
self
.
py
-
cy
current
=
self
.
x
-
cx
,
self
.
y
-
cy
return
delta
return
rotation
(
prev
,
current
)
class
MultiTouchListener
(
Logger
):
...
...
@@ -146,11 +142,12 @@ class MultiTouchListener(Logger):
# Put centroid outside screen to prevent misinterpretation
self
.
centroid
=
-
1.
,
-
1.
self
.
rot_centroid
=
-
1.
,
-
1.
self
.
server
=
TuioServer2D
(
self
,
verbose
=
tuio_verbose
)
self
.
angle
=
self
.
pinch
=
None
self
.
prev_
pinch
=
None
self
.
prev_
dist
=
None
def
point_down
(
self
,
sid
,
x
,
y
):
"""
...
...
@@ -222,51 +219,43 @@ class MultiTouchListener(Logger):
def
detect_rotation_and_pinch
(
self
):
"""
Rotation is the average angle change between each point and the
centroid. Pinch is the
average distance change from the points to th
e
centroid.
centroid. Pinch is the
percentual change in average distance chang
e
from the points to the
centroid.
"""
l
=
len
(
self
.
points
)
if
l
<
2
or
(
'pinch'
not
in
self
.
handlers
\
and
'rotate'
not
in
self
.
handlers
):
self
.
prev_
pinch
=
None
self
.
prev_
dist
=
None
return
# Get the sum of all angle differences
l
=
len
(
self
.
points
)
cx
,
cy
=
self
.
centroid
#rcx, rcy = self.rot_centroid
rotation
=
sum
([
p
.
angle_diff
(
cx
,
cy
)
for
p
in
self
.
points
])
/
l
pinch
=
sum
([
p
.
distance
(
cx
,
cy
)
for
p
in
self
.
points
])
/
l
rotation
=
sum
([
p
.
rotation_around
(
cx
,
cy
)
for
p
in
self
.
points
])
/
l
dist
=
sum
([
p
.
distance
(
cx
,
cy
)
for
p
in
self
.
points
])
/
l
if
rotation
:
self
.
trigger
(
Rotate
(
cx
,
cy
,
rotation
,
l
))
if
self
.
prev_pinch
==
None
:
self
.
prev_pinch
=
pinch
else
:
pinch
-=
self
.
prev_pinch
if
self
.
prev_dist
!=
None
:
pinch
=
dist
/
self
.
prev_dist
if
pinch
:
self
.
trigger
(
Pinch
(
cx
,
cy
,
pinch
,
l
))
self
.
prev_dist
=
dist
def
update_centroid
(
self
):
"""
Calculate the centroid of all current touch points.
"""
self
.
old_centroid
=
self
.
centroid
l
=
len
(
self
.
points
)
# If there are no touch points, move the centroid to outside the screen
if
not
l
:
self
.
centroid
=
-
1.
,
-
1.
return
if
self
.
points
:
self
.
centroid
=
average
([
p
.
xy
for
p
in
self
.
points
])
# Only use stationary points for rotational centroid, if any
stat
=
[
p
.
xy
for
p
in
filter
(
TouchPoint
.
is_stationary
,
self
.
points
)]
self
.
rot_centroid
=
average
(
stat
)
if
stat
else
self
.
centroid
else
:
# There are no touch points, move the centroid out of the screen
self
.
centroid
=
-
1.
,
-
1.
def
centroid_movement
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment