Exemplo n.º 1
0
    def setBall(self, ball, value):
        """Set a new value for a particular ball.

        This method sends a JOYSTICK_BALL event.

        \param ball (\c int) Ball index
        \param value (\c float) Ball value
        """
        self.ball[ball] = value
        e = JoystickBallEvent(self.id, ball, value)
        eventManager().event(JOYSTICK_BALL, e)
Exemplo n.º 2
0
    def setBall(self, ball, value):
        """Set a new value for a particular ball.

        This method sends a JOYSTICK_BALL event.

        \param ball (\c int) Ball index
        \param value (\c float) Ball value
        """
        self.ball[ball] = value
        e = JoystickBallEvent(self.id, ball, value)
        eventManager().event(JOYSTICK_BALL, e)
Exemplo n.º 3
0
    def setHat(self, hat, x, y):
        """Set a new value for a particular hat.

        This method sends a JOYSTICK_HAT event.

        \param hat (\c int) Hat index
        \param x (\c int) X value
        \param y (\c int) Y value        
        """
        self.hat[hat]=(x,y)
        e = JoystickHatEvent(self.id, hat, x, y)
        eventManager().event(JOYSTICK_HAT, e)
Exemplo n.º 4
0
    def setHat(self, hat, x, y):
        """Set a new value for a particular hat.

        This method sends a JOYSTICK_HAT event.

        \param hat (\c int) Hat index
        \param x (\c int) X value
        \param y (\c int) Y value        
        """
        self.hat[hat] = (x, y)
        e = JoystickHatEvent(self.id, hat, x, y)
        eventManager().event(JOYSTICK_HAT, e)
Exemplo n.º 5
0
    def setButton(self, button, value):
        """Set the state of a particular button.

        This method sends either a JOYSTICK_BUTTON_DOWN or
        JOYSTICK_BUTTON_UP event.

        \param button (\c int) Button index
        \param value (\c bool) State of the button (True = pressed)
        """
        self.button[button] = value
        e = JoystickButtonEvent(self.id, button)
        if value:
            eventManager().event(JOYSTICK_BUTTON_DOWN, e)                
        else:
            eventManager().event(JOYSTICK_BUTTON_UP, e)
Exemplo n.º 6
0
    def setButton(self, button, value):
        """Set the state of a particular button.

        This method sends either a JOYSTICK_BUTTON_DOWN or
        JOYSTICK_BUTTON_UP event.

        \param button (\c int) Button index
        \param value (\c bool) State of the button (True = pressed)
        """
        self.button[button] = value
        e = JoystickButtonEvent(self.id, button)
        if value:
            eventManager().event(JOYSTICK_BUTTON_DOWN, e)
        else:
            eventManager().event(JOYSTICK_BUTTON_UP, e)
Exemplo n.º 7
0
    def __init__(self, name="SlideShow", slides=[], auto_insert=True):
        
        component.Component.__init__(self, name, auto_insert)

        if isinstance(slides, types.StringTypes):
            slides = Slide(slides)

        try:
            len(slides)
        except:
            slides = [slides]

        self.images = []
        for s in slides:
            for f in s.files:
                self.images.append((f, s.transition))

        # Currently displayed image index
        self.imageidx = 0

        self.setup()

        em = eventManager()
        em.connect(STEP_FRAME, self)
        em.connect(LEFT_DOWN, self)
        em.connect(KEY_PRESS, self)

        self.transition = self.images[0][1]

        # Global time when the next transition starts
#        self.transition_start = 3.0
        self.transition_start = 999999.0
        # Slide show state
        self.state = 0
Exemplo n.º 8
0
    def importFile(self, filename):
        """Import a Python source file."""

        file_globals = {}
        # Use all globals from the cgkit package
        # Commented out the following line as is imported from cgkit.all now
        #        file_globals = copy.copy(cgkit.__dict__)
        # Add some modules...
        exec "from cgkit.all import *" in file_globals
        exec "from cgkit.sl import *" in file_globals
        exec "from math import *" in file_globals
        # ...and some special global names...
        scene = globalscene.getScene()
        file_globals["scene"] = scene
        file_globals["timer"] = scene.timer()
        file_globals["worldroot"] = scene.worldRoot()
        file_globals["eventmanager"] = eventmanager.eventManager()

        paths = sys.path
        # Add the directory of the input file to the module search paths
        # so that local imports do work
        sys.path = [os.path.abspath(os.path.dirname(filename))] + sys.path
        # Import the file
        execfile(filename, file_globals)
        # Restore the old search paths
        sys.path = paths
Exemplo n.º 9
0
    def __init__(self,
                 cam,
                 name = "CameraControl",
                 mode = 0,
                 auto_insert = True):
        """Constructor.

        \param cam (\c ...Cam?...) Camera to control
        \param name (\c str) Name of the component
        \param mode (\c int) 0=Emulate MAX behavior, 1=Emulate Maya behavior
        \param auto_insert (\c bool) Insert into scene or not
        """
        
        component.Component.__init__(self, name=name, auto_insert=auto_insert)
        
        # mode: 0=Emulate MAX / 1=Emulate Maya / 2=Emulate Softimage (Navigation tool)
        self.mode = mode  
        self.cam = cam
        self.left_down = False
        self.middle_down = False
        self.right_down = False
        self.alt_down = False
        self.ctrl_down = False
        em = eventmanager.eventManager()
        em.connect(KEY_PRESS, self)
        em.connect(KEY_RELEASE, self)
        em.connect(LEFT_DOWN, self)
        em.connect(LEFT_UP, self)
        em.connect(MIDDLE_DOWN, self)
        em.connect(MIDDLE_UP, self)
        em.connect(RIGHT_DOWN, self)
        em.connect(RIGHT_UP, self)
        em.connect(MOUSE_MOVE, self)
        em.connect(MOUSE_WHEEL, self)
        em.connect(SPACE_MOTION, self)
Exemplo n.º 10
0
    def importFile(self, filename):
        """Import a Python source file."""

        file_globals = {}
        # Use all globals from the cgkit package
        # Commented out the following line as is imported from cgkit.all now
#        file_globals = copy.copy(cgkit.__dict__)
        # Add some modules...
        exec "from cgkit.all import *" in file_globals
        exec "from cgkit.sl import *" in file_globals
        exec "from math import *" in file_globals
        # ...and some special global names...
        scene = globalscene.getScene()
        file_globals["scene"] = scene
        file_globals["timer"] = scene.timer()
        file_globals["worldroot"] = scene.worldRoot()
        file_globals["eventmanager"] = eventmanager.eventManager()
        
        paths = sys.path
        # Add the directory of the input file to the module search paths
        # so that local imports do work
        sys.path = [os.path.abspath(os.path.dirname(filename))] + sys.path
        # Import the file
        execfile(filename, file_globals)
        # Restore the old search paths
        sys.path = paths
Exemplo n.º 11
0
    def __init__(self,
                 name = "PIDController",
                 setpoint = 0.0,
                 Kp = 0.0,
                 Ki = 0.0,
                 Kd = 0.0,
                 maxout = 999999,
                 minout = -999999,
                 auto_insert = True):
        """Constructor.
        """
        
        component.Component.__init__(self, name, auto_insert)

        self.input_slot = DoubleSlot()
        self.setpoint_slot = DoubleSlot(setpoint)
        self.maxout_slot = DoubleSlot(maxout)
        self.minout_slot = DoubleSlot(minout)
        self.Kp_slot = DoubleSlot(Kp)
        self.Ki_slot = DoubleSlot(Ki)
        self.Kd_slot = DoubleSlot(Kd)

        self.output_slot = ProceduralDoubleSlot(self.computeOutput)

        self.addSlot("input", self.input_slot)
        self.addSlot("setpoint", self.setpoint_slot)
        self.addSlot("output", self.output_slot)
        self.addSlot("maxout", self.maxout_slot)
        self.addSlot("minout", self.minout_slot)
        self.addSlot("Kp", self.Kp_slot)
        self.addSlot("Ki", self.Ki_slot)
        self.addSlot("Kd", self.Kd_slot)

        self.input_slot.addDependent(self.output_slot)
        self.setpoint_slot.addDependent(self.output_slot)
        self.maxout_slot.addDependent(self.output_slot)
        self.minout_slot.addDependent(self.output_slot)
        self.Kp_slot.addDependent(self.output_slot)
        self.Ki_slot.addDependent(self.output_slot)
        self.Kd_slot.addDependent(self.output_slot)

        self._integral = 0.0
        self._prev_err = 0.0

        eventmanager.eventManager().connect(events.STEP_FRAME, self)
        eventmanager.eventManager().connect(events.RESET, self)
Exemplo n.º 12
0
    def __init__(self,
                 name="PIDController",
                 setpoint=0.0,
                 Kp=0.0,
                 Ki=0.0,
                 Kd=0.0,
                 maxout=999999,
                 minout=-999999,
                 auto_insert=True):
        """Constructor.
        """

        component.Component.__init__(self, name, auto_insert)

        self.input_slot = DoubleSlot()
        self.setpoint_slot = DoubleSlot(setpoint)
        self.maxout_slot = DoubleSlot(maxout)
        self.minout_slot = DoubleSlot(minout)
        self.Kp_slot = DoubleSlot(Kp)
        self.Ki_slot = DoubleSlot(Ki)
        self.Kd_slot = DoubleSlot(Kd)

        self.output_slot = ProceduralDoubleSlot(self.computeOutput)

        self.addSlot("input", self.input_slot)
        self.addSlot("setpoint", self.setpoint_slot)
        self.addSlot("output", self.output_slot)
        self.addSlot("maxout", self.maxout_slot)
        self.addSlot("minout", self.minout_slot)
        self.addSlot("Kp", self.Kp_slot)
        self.addSlot("Ki", self.Ki_slot)
        self.addSlot("Kd", self.Kd_slot)

        self.input_slot.addDependent(self.output_slot)
        self.setpoint_slot.addDependent(self.output_slot)
        self.maxout_slot.addDependent(self.output_slot)
        self.minout_slot.addDependent(self.output_slot)
        self.Kp_slot.addDependent(self.output_slot)
        self.Ki_slot.addDependent(self.output_slot)
        self.Kd_slot.addDependent(self.output_slot)

        self._integral = 0.0
        self._prev_err = 0.0

        eventmanager.eventManager().connect(events.STEP_FRAME, self)
        eventmanager.eventManager().connect(events.RESET, self)
Exemplo n.º 13
0
    def __init__(self, name="AutoCam"):
        Component.__init__(self, name=name)

        # Input
        self.input_slot = slots.Vec3Slot()
        self.addSlot("input", self.input_slot)

        # Output
        self.output_slot = slots.Vec3Slot()
        self.addSlot("output", self.output_slot)

        self.accel_factor = 0.5
        self.out_offset = vec3(0, 0, 0)

        self.out = vec3(0, 0, 0)
        self.out_velocity = vec3(0, 0, 0)

        eventManager().connect(events.STEP_FRAME, self)
Exemplo n.º 14
0
    def __init__(self, name="AutoCam"):
        Component.__init__(self, name=name)

        # Input
        self.input_slot = slots.Vec3Slot()
        self.addSlot("input", self.input_slot)

        # Output
        self.output_slot = slots.Vec3Slot()
        self.addSlot("output", self.output_slot)

        self.accel_factor = 0.5
        self.out_offset = vec3(0,0,0)

        self.out = vec3(0,0,0)
        self.out_velocity = vec3(0,0,0)

        eventManager().connect(events.STEP_FRAME, self)
Exemplo n.º 15
0
    def __init__(self, name="Timer", auto_insert=True):
        Component.__init__(self, name=name, auto_insert=auto_insert)

        # The time() value when the clock was started
        self._clock_start = 0.0
        # This offset is added to the returned clock value. It stores the
        # clock value at the time the clock was stopped
        self._clock_offset = 0.0
        # This flag indicates if the clock is running or not
        self._clock_running = False

        self._duration = 1.0
        self._framecount = 25
        self._fps = 25
        self._timestep = 0.04

        # Virtual time...
        self.time_slot = slots.DoubleSlot()
        self.addSlot("time", self.time_slot)

        eventManager().connect(events.RESET, self)
Exemplo n.º 16
0
    def __init__(self, name="Timer", auto_insert=True):
        Component.__init__(self, name=name, auto_insert=auto_insert)

        # The time() value when the clock was started
        self._clock_start  = 0.0
        # This offset is added to the returned clock value. It stores the
        # clock value at the time the clock was stopped
        self._clock_offset = 0.0
        # This flag indicates if the clock is running or not
        self._clock_running = False

        self._duration = 1.0
        self._framecount = 25
        self._fps = 25
        self._timestep = 0.04
        
        # Virtual time...
        self.time_slot = slots.DoubleSlot()
        self.addSlot("time", self.time_slot)

        eventManager().connect(events.RESET, self)
Exemplo n.º 17
0
    def setAxis(self, axis, value):
        """Set a new value for a particular axis.

        The value is the raw (uncalibrated) value from the joystick.

        This method sends a JOYSTICK_AXIS event which contains the
        \em calibrated axis value.

        \param axis (\c int) Axis index
        \param value (\c float) Uncalibrated axis value
        
        \todo Sollte diese Methode setRawAxis() heissen?
        """
        self.axis[axis] = value

        # Adjust min/max values
        if value < self.axis_min[axis]:
            self.axis_min[axis] = value
        if value > self.axis_max[axis]:
            self.axis_max[axis] = value

        e = JoystickAxisEvent(self.id, axis, self._calibratedAxis(axis, value))
        eventManager().event(JOYSTICK_AXIS, e)
Exemplo n.º 18
0
    def setAxis(self, axis, value):
        """Set a new value for a particular axis.

        The value is the raw (uncalibrated) value from the joystick.

        This method sends a JOYSTICK_AXIS event which contains the
        \em calibrated axis value.

        \param axis (\c int) Axis index
        \param value (\c float) Uncalibrated axis value
        
        \todo Sollte diese Methode setRawAxis() heissen?
        """
        self.axis[axis] = value

        # Adjust min/max values
        if value<self.axis_min[axis]:
            self.axis_min[axis] = value
        if value>self.axis_max[axis]:
            self.axis_max[axis] = value
        
        e = JoystickAxisEvent(self.id, axis, self._calibratedAxis(axis, value))
        eventManager().event(JOYSTICK_AXIS, e)
Exemplo n.º 19
0
    def onStepFrame(self):
        timer = getScene().timer()

        ### State 0: Waiting for the transition
        if self.state==0:
            if timer.time>=self.transition_start:
                self.state = 1

        ### State 1: Begin of transition
        if self.state==1:
            self.transition.preTransition(self)
            eventManager().event("SlidePreTransition", self.images[self.imageidx][0])
            self.state = 2
            
        ### State 2: Transition
        if self.state==2:
            if self.transition.duration>0:
                t = (timer.time-self.transition_start)/self.transition.duration
            else:
                t = 1.0
            if t>1.0:
                t = 1.0
            self.transition.doTransition(self, t)
            eventManager().event("SlideDoTransition", t)
            if t==1.0:
                self.state = 3
                
        ### State 3: Transition is over
        elif self.state==3:
            eventManager().event("SlidePostTransition")
            self.transition.postTransition(self)
            self.switchSlide()

            self.frontplate.transform = mat4(1)
            self.backplate.transform = mat4(1)
            self.backplate.pos = vec3(0,0,-1)
                       
#            self.transition_start += 5.0
            self.transition_start = 999999.0
            self.state = 0
Exemplo n.º 20
0
def reset():
    """Reset an animation/simulation.

    Reset effectively sets the time back to 0.
    """
    eventmanager.eventManager().event(events.RESET)
Exemplo n.º 21
0
    def __init__(self,
                 name = "GnuPlotter",
                 title = None,
                 xlabel = None,
                 ylabel = None,
                 xrange = None,
                 yrange = None,
                 inputs = 1,
                 plottitles = [],
                 starttime = 0.0,
                 endtime = 99999.0,
                 enabled = True,
                 auto_insert = True):
        """Constructor.
        """
        global gnuplot_installed
        
        component.Component.__init__(self, name, auto_insert)

        self.enabled = enabled
        self.inputs = inputs
        self.plot_data = []
        self.starttime = starttime
        self.endtime = endtime

        for i in range(inputs):
            s = DoubleSlot()
            exec "self.input%d_slot = s"%(i+1)
            if i<len(plottitles):
                t = plottitles[i]
            else:
                t = None
            pd = _PlotDesc(slot=s, title=t)
            self.plot_data.append(pd)

        if not enabled:
            return

        if not gnuplot_installed:
            print >>sys.stderr, "Warning: PyGnuplot is not installed"
            return

        self.gp = Gnuplot.Gnuplot()
        self.gp('set data style lines')
        self.gp("set grid")
        self.gp("set xzeroaxis")
        if title!=None:
            self.gp.title(title)
        if xlabel!=None:
            self.gp.xlabel(xlabel)
        if ylabel!=None:
            self.gp.ylabel(ylabel)
        if yrange!=None:
            self.gp.set_range("yrange",yrange)
#            self.gp("set yrange [%f:%f]"%tuple(yrange))
        if xrange!=None:
            self.gp.set_range("xrange",xrange)

        self._delay = 0

        eventmanager.eventManager().connect(events.STEP_FRAME, self)
Exemplo n.º 22
0
    def __init__(self,
                 name = "FlockOfBirds",
                 com_port = 0,
                 baud_rate = 115200,
                 timeout = 2.0,
                 num_birds = 1,
                 bird_mode = "p",
                 hemisphere = "forward",
                 auto_insert = True):
        """Constructor.

        The bird mode is one of "p" (position), "a" (angles), "m" (matrix),
        "q" (quaternion) or a combination like "pa", "pm" and "pq".
        The argument \a bird_mode can either be a mode string that will
        be used for all birds, or it can be a list of mode strings for
        every bird.

        \param name (\c str) Component name
        \param com_port (\c int) COM port to use for communicating with the flock (0,1,...)
        \param baud_rate (\c int) Baud rate
        \param timeout (\c float) Time out value in seconds for RS232 operations
        \param num_birds (\c int) Number of birds to use (including the ERC)
        \param bird_mode (\c str or \c list) Tracker mode (selects what kind of data the birds will send)
        \param hemisphere (\c str) Hemisphere setting for the transmitter ("forward", "aft", "upper", "lower", "left", "right")
        \param auto_insert (\c bool) True if the component should be inserted into the scene automatically
        """
        
        component.Component.__init__(self, name, auto_insert)

        self.com_port = com_port
        self.baud_rate = baud_rate
        self.timeout = timeout
        self.num_birds = num_birds
        self.hemisphere = hemisphere

        if isinstance(bird_mode, types.StringTypes):
            self.bird_mode = self.num_birds*[bird_mode]
        else:
            self.bird_mode = bird_mode

        self.bird_mode = map(lambda x: x.upper(), self.bird_mode)

        if len(self.bird_mode)!=self.num_birds:
            raise ValueError("%d bird modes expected (got %d)"%(self.num_birds, len(self.bird_mode)))

        # Create slots
        self._slots = []
        for i in range(self.num_birds):
            p = Vec3Slot()
            a = Vec3Slot()
            m = Mat3Slot(mat3(1))
            q = QuatSlot(quat(1))
            self._slots.append((p,a,m,q))
            setattr(self, "pos%d_slot"%(i+1), p)
            setattr(self, "angle%d_slot"%(i+1), a)
            setattr(self, "matrix%d_slot"%(i+1), m)
            setattr(self, "quat%d_slot"%(i+1), q)
            self.addSlot("pos%d"%(i+1), p)
            self.addSlot("angle%d"%(i+1), a)
            self.addSlot("matrix%d"%(i+1), m)
            self.addSlot("quat%d"%(i+1), q)

        # Initialize the FOB...
        
        self._fob = fob.FOB()
        self._fob.open(self.com_port, self.baud_rate, self.timeout)
        
        self._fob.fbbAutoConfig(numbirds=self.num_birds)
        self._fob.fbbReset()
        hs = { "forward":fob.FORWARD,
               "aft":fob.AFT,
               "upper":fob.UPPER,
               "lower":fob.LOWER,
               "left":fob.LEFT,
               "right":fob.RIGHT }
        for i in range(1, self.num_birds):
            self._fob.hemisphere(hs[self.hemisphere.lower()], addr=i+1)
            self.setTrackerMode(self.bird_mode[i], i+1)
        self._fob.run()
        
        eventmanager.eventManager().connect(events.STEP_FRAME, self)
Exemplo n.º 23
0
    def __init__(self,
                 name="FlockOfBirds",
                 com_port=0,
                 baud_rate=115200,
                 timeout=2.0,
                 num_birds=1,
                 bird_mode="p",
                 hemisphere="forward",
                 auto_insert=True):
        """Constructor.

        The bird mode is one of "p" (position), "a" (angles), "m" (matrix),
        "q" (quaternion) or a combination like "pa", "pm" and "pq".
        The argument \a bird_mode can either be a mode string that will
        be used for all birds, or it can be a list of mode strings for
        every bird.

        \param name (\c str) Component name
        \param com_port (\c int) COM port to use for communicating with the flock (0,1,...)
        \param baud_rate (\c int) Baud rate
        \param timeout (\c float) Time out value in seconds for RS232 operations
        \param num_birds (\c int) Number of birds to use (including the ERC)
        \param bird_mode (\c str or \c list) Tracker mode (selects what kind of data the birds will send)
        \param hemisphere (\c str) Hemisphere setting for the transmitter ("forward", "aft", "upper", "lower", "left", "right")
        \param auto_insert (\c bool) True if the component should be inserted into the scene automatically
        """

        component.Component.__init__(self, name, auto_insert)

        self.com_port = com_port
        self.baud_rate = baud_rate
        self.timeout = timeout
        self.num_birds = num_birds
        self.hemisphere = hemisphere

        if isinstance(bird_mode, types.StringTypes):
            self.bird_mode = self.num_birds * [bird_mode]
        else:
            self.bird_mode = bird_mode

        self.bird_mode = map(lambda x: x.upper(), self.bird_mode)

        if len(self.bird_mode) != self.num_birds:
            raise ValueError("%d bird modes expected (got %d)" %
                             (self.num_birds, len(self.bird_mode)))

        # Create slots
        self._slots = []
        for i in range(self.num_birds):
            p = Vec3Slot()
            a = Vec3Slot()
            m = Mat3Slot(mat3(1))
            q = QuatSlot(quat(1))
            self._slots.append((p, a, m, q))
            setattr(self, "pos%d_slot" % (i + 1), p)
            setattr(self, "angle%d_slot" % (i + 1), a)
            setattr(self, "matrix%d_slot" % (i + 1), m)
            setattr(self, "quat%d_slot" % (i + 1), q)
            self.addSlot("pos%d" % (i + 1), p)
            self.addSlot("angle%d" % (i + 1), a)
            self.addSlot("matrix%d" % (i + 1), m)
            self.addSlot("quat%d" % (i + 1), q)

        # Initialize the FOB...

        self._fob = fob.FOB()
        self._fob.open(self.com_port, self.baud_rate, self.timeout)

        self._fob.fbbAutoConfig(numbirds=self.num_birds)
        self._fob.fbbReset()
        hs = {
            "forward": fob.FORWARD,
            "aft": fob.AFT,
            "upper": fob.UPPER,
            "lower": fob.LOWER,
            "left": fob.LEFT,
            "right": fob.RIGHT
        }
        for i in range(1, self.num_birds):
            self._fob.hemisphere(hs[self.hemisphere.lower()], addr=i + 1)
            self.setTrackerMode(self.bird_mode[i], i + 1)
        self._fob.run()

        eventmanager.eventManager().connect(events.STEP_FRAME, self)
Exemplo n.º 24
0
 def step(self):
     t = self.time_slot.getValue() + self._timestep
     self.time_slot.setValue(t)
     eventManager().event(events.STEP_FRAME)
Exemplo n.º 25
0
    def __init__(
        self,
        name="GnuPlotter",
        title=None,
        xlabel=None,
        ylabel=None,
        xrange=None,
        yrange=None,
        inputs=1,
        plottitles=[],
        starttime=0.0,
        endtime=99999.0,
        enabled=True,
        auto_insert=True,
    ):
        """Constructor.
        """
        global gnuplot_installed

        component.Component.__init__(self, name, auto_insert)

        self.enabled = enabled
        self.inputs = inputs
        self.plot_data = []
        self.starttime = starttime
        self.endtime = endtime

        for i in range(inputs):
            s = DoubleSlot()
            exec "self.input%d_slot = s" % (i + 1)
            if i < len(plottitles):
                t = plottitles[i]
            else:
                t = None
            pd = _PlotDesc(slot=s, title=t)
            self.plot_data.append(pd)

        if not enabled:
            return

        if not gnuplot_installed:
            print >>sys.stderr, "Warning: PyGnuplot is not installed"
            return

        self.gp = Gnuplot.Gnuplot()
        self.gp("set data style lines")
        self.gp("set grid")
        self.gp("set xzeroaxis")
        if title != None:
            self.gp.title(title)
        if xlabel != None:
            self.gp.xlabel(xlabel)
        if ylabel != None:
            self.gp.ylabel(ylabel)
        if yrange != None:
            self.gp.set_range("yrange", yrange)
        #            self.gp("set yrange [%f:%f]"%tuple(yrange))
        if xrange != None:
            self.gp.set_range("xrange", xrange)

        self._delay = 0

        eventmanager.eventManager().connect(events.STEP_FRAME, self)
Exemplo n.º 26
0
    def __init__(self,
                 name="ODEDynamics",
                 gravity = 9.81,
                 substeps = 1,
                 cfm = None,
                 erp = None,
                 defaultcontactproperties = None,
                 enabled = True,
                 show_contacts = False,
                 contactmarkersize = 0.1,
                 contactnormalsize = 1.0,
                 collision_events = False,
                 auto_add = False,
                 auto_insert=True):
        """Constructor.

        \param name (\c str) Component name
        \param auto_add (\c bool) Automatically add the world objects to the simulation
        \param auto_insert (\c bool) Automatically add the component to the scene
        """
        Component.__init__(self, name=name, auto_insert=auto_insert)

        scene = getScene()

        self.substeps = substeps
        self.collision_events = collision_events

        self.world = ode.World()
        g = -gravity*scene.up
        self.world.setGravity(g)
        if cfm!=None:
            self.world.setCFM(cfm)
        if erp!=None:
            self.world.setERP(erp)
        
#        self.world.setAutoDisableFlag(True)

        self.enabled = enabled

        self.eventmanager = eventManager()
        self.eventmanager.connect(STEP_FRAME, self)
        self.eventmanager.connect(RESET, self.reset)

        # Space object
        self.space = ode.Space()

        # Joint group for the contact joints
        self.contactgroup = ode.JointGroup()

        # A dictionary with WorldObjects as keys and ODEBodies as values
        self.body_dict = {}
        # A list of all bodies
        self.bodies = []
        # A list of all joints
        self.joints = []

        # A dictionary with contact properties
        # Key is a 2-tuple (material1, material2). Value is a
        # ODEContactProperties object.
        # The value of (mat1, mat2) should always be the same than
        # the value of (mat2, mat1).
        self.contactprops = {}

        # Default contact properties
        if defaultcontactproperties==None:
            defaultcontactproperties = ODEContactProperties()
        self.defaultcontactprops = defaultcontactproperties

        self.show_contacts = show_contacts
        self.contactmarkersize = contactmarkersize
        self.contactnormalsize = contactnormalsize

        # A list of weakrefs to body manipulators
        self.body_manips = []

        # Debug statistics (the number of contacts per simulation step)
        self.numcontacts = 0

        # Automatically add world objects
        if auto_add:
            # Add all rigid bodies first...
            for obj in scene.worldRoot().iterChilds():
                try:
                    obj = protocols.adapt(obj, IRigidBody)
                    self.add(obj)
                except NotImplementedError:
                    pass

            # Then add all joints...
            for obj in scene.worldRoot().iterChilds():
                if isinstance(obj, ODEJointBase):
                    self.add(obj)
Exemplo n.º 27
0
    def __init__(self,
                 name="ODEDynamics",
                 gravity=9.81,
                 substeps=1,
                 cfm=None,
                 erp=None,
                 defaultcontactproperties=None,
                 enabled=True,
                 show_contacts=False,
                 contactmarkersize=0.1,
                 contactnormalsize=1.0,
                 collision_events=False,
                 auto_add=False,
                 auto_insert=True):
        """Constructor.

        \param name (\c str) Component name
        \param auto_add (\c bool) Automatically add the world objects to the simulation
        \param auto_insert (\c bool) Automatically add the component to the scene
        """
        Component.__init__(self, name=name, auto_insert=auto_insert)

        scene = getScene()

        self.substeps = substeps
        self.collision_events = collision_events

        self.world = ode.World()
        g = -gravity * scene.up
        self.world.setGravity(g)
        if cfm != None:
            self.world.setCFM(cfm)
        if erp != None:
            self.world.setERP(erp)

#        self.world.setAutoDisableFlag(True)

        self.enabled = enabled

        self.eventmanager = eventManager()
        self.eventmanager.connect(STEP_FRAME, self)
        self.eventmanager.connect(RESET, self.reset)

        # Space object
        self.space = ode.Space()

        # Joint group for the contact joints
        self.contactgroup = ode.JointGroup()

        # A dictionary with WorldObjects as keys and ODEBodies as values
        self.body_dict = {}
        # A list of all bodies
        self.bodies = []
        # A list of all joints
        self.joints = []

        # A dictionary with contact properties
        # Key is a 2-tuple (material1, material2). Value is a
        # ODEContactProperties object.
        # The value of (mat1, mat2) should always be the same than
        # the value of (mat2, mat1).
        self.contactprops = {}

        # Default contact properties
        if defaultcontactproperties == None:
            defaultcontactproperties = ODEContactProperties()
        self.defaultcontactprops = defaultcontactproperties

        self.show_contacts = show_contacts
        self.contactmarkersize = contactmarkersize
        self.contactnormalsize = contactnormalsize

        # A list of weakrefs to body manipulators
        self.body_manips = []

        # Debug statistics (the number of contacts per simulation step)
        self.numcontacts = 0

        # Automatically add world objects
        if auto_add:
            # Add all rigid bodies first...
            for obj in scene.worldRoot().iterChilds():
                try:
                    obj = protocols.adapt(obj, IRigidBody)
                    self.add(obj)
                except NotImplementedError:
                    pass

            # Then add all joints...
            for obj in scene.worldRoot().iterChilds():
                if isinstance(obj, ODEJointBase):
                    self.add(obj)
Exemplo n.º 28
0
Arquivo: cmds.py Projeto: behnam/cgkit
def reset():
    """Reset an animation/simulation.

    Reset effectively sets the time back to 0.
    """
    eventmanager.eventManager().event(events.RESET)
Exemplo n.º 29
0
 def step(self):
     t = self.time_slot.getValue() + self._timestep
     self.time_slot.setValue(t)
     eventManager().event(events.STEP_FRAME)