Revision: 7166
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 10, 2008 14:43 by ZeroByte
Initial Code
from MouseGest import Gesture import direct.directbase.DirectStart from BasePolling import interface test_gestures = {} test_gestures['right'] = Gesture() test_gestures['right'].add_stroke( [(0, 0), (1, 0)] ) test_gestures['left'] = Gesture() test_gestures['left'].add_stroke( [(0, 0), (-1, 0)] ) test_gestures['up'] = Gesture() test_gestures['up'].add_stroke( [(0, 0), (0, 1)] ) test_gestures['down'] = Gesture() test_gestures['down'].add_stroke( [(0, 0), (0, -1)] ) test_gestures['box'] = Gesture() test_gestures['box'].add_stroke([(0, 0), (0, 1)]) test_gestures['box'].add_stroke([(0, 1), (1, 1)]) test_gestures['box'].add_stroke([(1, 1), (1, 0)]) test_gestures['box'].add_stroke([(1, 0), (0, 0)]) for key in test_gestures: test_gestures[key].normalize() class MouseTest: def __init__(self): self.lastAct = 0 self.gestureDelay = 2 self.drawingFlag = False self.matchedFlag = True taskMgr.add(self.drawTask, "Drawing task") self.currGest = None self.currStroke = None def drawTask(self, task): if task.time - self.lastAct >= self.gestureDelay and not self.matchedFlag: self.currGest.normalize() print "--Evaluating gesture--" for gesture_name in test_gestures: if self.currGest == test_gestures[gesture_name]: print "Gesture:", gesture_name self.currGest = None self.matchedFlag = True if interface.getMouseHit('left'): if self.currGest is None: self.currGest = Gesture() self.currStroke = self.currGest.add_stroke() print "Starting new stroke" self.drawingFlag = True self.matchedFlag = False self.lastAct = task.time if self.drawingFlag: if not interface.getMouse('left'): self.drawingFlag = False return task.cont else: self.lastAct = task.time mousePos = interface.getMousePos() self.currStroke.points.append(Gesture.Point(mousePos[0], mousePos[1])) return task.cont mouse = MouseTest() run()
Initial URL
Initial Description
Usage example of my mouse gesture class (http://snipplr.com/view/7216/mouse-gestures/) in Panda3d
Initial Title
Mouse Gesture Integration With Panda3D
Initial Tags
Initial Language
Python