-
Notifications
You must be signed in to change notification settings - Fork 1
/
Square.py
98 lines (88 loc) · 3.56 KB
/
Square.py
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
from __future__ import division
from panda3d.core import Point3
from positions import Positions
from direct.showbase.MessengerGlobal import messenger
class Square(object):
def __init__(self, config, key_map, base):
self.key_map = key_map
self.base = base
# self.depth needs to be more than zero for stuff to show up,
# otherwise arbitrary. This is used for positioning squares (Z)
self.depth = 55
self.pos = None
self.manual = None
# scale 17 is one visual angle, linear so just multiply by 17
self.square = self.create_square(config['SQUARE_SCALE']*17)
# print 'scale', config['SQUARE_SCALE']*17
def create_square(self, scale):
# setting up square object
obj = self.base.loader.loadModel("models/plane")
# don't turn on yet
# make depth greater than eye positions so eye positions are on top of squares
# initial position of Square
obj.setPos(Point3(0, self.depth, 0)) # Set initial position
# need to scale to be correct visual angle
# obj.setScale(1)
obj.setScale(scale)
# obj.setTransparency(1)
square = self.base.loader.loadTexture("textures/calibration_square.png")
obj.setTexture(square, 1)
# starting color, should be set by model, but let's make sure
obj.setColor(150 / 255, 150 / 255, 150 / 255, 1.0)
return obj
def setup_positions(self, config, manual):
# If doing manual, need to initiate Positions differently than if random,
# so key presses work properly
self.manual = manual
if self.manual:
del self.pos
# print 'manual positions'
self.pos = Positions(config)
else:
del self.pos
# print 'auto positions'
self.pos = Positions(config).get_position(self.depth, True)
# Square methods
def turn_on(self):
# print 'square on'
# make sure in correct color
self.square.setColor(150 / 255, 150 / 255, 150 / 255, 1.0)
# and render
self.square.reparentTo(self.base.render)
def fade(self):
# print 'square fade'
self.square.setColor(0.9, 0.9, 0.6, 1.0)
def turn_off(self):
# print 'square off'
self.square.clearColor()
self.square.detachNode()
def move_for_manual_position(self):
# used for manual move, called from sequences
# if a key was pressed, use that for next position
if self.key_map["switch"]:
# print 'manual move'
# print('switch', self.key_map["switch"])
self.move(self.pos.get_key_position(self.depth, self.key_map["switch"]))
self.key_map["switch"] = 0 # remove the switch flag
else:
# default is the center, which is key 5
self.move(self.pos.get_key_position(self.depth, 5))
def move(self, position=None):
# print 'square move'
# print 'square position', position
if not position:
# print 'trying to get a auto position'
try:
position = self.pos.next()
# print position
except StopIteration:
# print('stop iterating!')
messenger.send("s")
# Switch to manual and wait
# need to set a position
position = (0, self.depth, 0)
# self.close()
# print position
self.square.setPos(Point3(position))
# print 'square', position[0], position[2]
# print 'actually moved square'