forked from jvan/vroom-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrag.vroom
executable file
·52 lines (38 loc) · 957 Bytes
/
drag.vroom
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
#!/usr/bin/env vroom-wrapper
from vroom import *
import math
# Functions
def hit(cursor):
dist = sum([(a-b)*(a-b) for a,b in zip(Global.position, cursor)])
return math.sqrt(dist) < Global.size
# vroom callbacks
def init():
Global.position = [0.0, 0.0, 0.0]
Global.size = 1.5
Global.dragging = False
Global.hover = False
def display():
lighting(False)
if Global.dragging:
color(red)
elif Global.hover:
color(green)
else:
color(blue)
pushMatrix()
translate(Global.position)
sphere(Global.size)
popMatrix()
def button_press(pos, button):
print 'button_press: pos={}'.format(pos)
if hit(pos):
print '!!!!! HIT !!!!!'
Global.dragging = True
def button_release(pos, button):
print 'button_release: pos={}'.format(pos)
Global.dragging = False
def motion(pos, button):
if Global.dragging:
Global.position = pos
else:
Global.hover = hit(pos)