Ejemplo n.º 1
0
    def tick(self, target, t):
        if target.vel.m > self.min_vel:
            drag = Vector(
                a=target.vel.a + math.pi,
                m = (0.5) * (target.vel.m ** 2) * self.cons)

            if drag.m > target.vel.m:
                drag.m = target.vel.m
            if drag.m < self.min_drag:
                drag.m = self.min_drag

            target.apply_force(drag)
        elif 0 < target.vel.m < self.min_vel:
            target.vel = Vector()

        self.orig_tick(t)
Ejemplo n.º 2
0
 def __init__(self):
     self.size = Vector(32, 32)
     self.outline = pyglet.graphics.vertex_list(4,
         ('v2f/static', self.size.to('r2f')))
     self.highlight = pyglet.graphics.vertex_list_indexed(4,
         [0, 1, 2, 0, 2, 3],
         ('v2f/static', self.size.to('r2f')),
         ('c3f/static', (0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
                         0.5, 0.5, 0.5, 0.5, 0.5, 0.5)))
     self.active = False
Ejemplo n.º 3
0
class Tool(object):
    """Base class for a tool in the toolbar."""

    def __init__(self):
        self.size = Vector(32, 32)
        self.outline = pyglet.graphics.vertex_list(4,
            ('v2f/static', self.size.to('r2f')))
        self.highlight = pyglet.graphics.vertex_list_indexed(4,
            [0, 1, 2, 0, 2, 3],
            ('v2f/static', self.size.to('r2f')),
            ('c3f/static', (0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
                            0.5, 0.5, 0.5, 0.5, 0.5, 0.5)))
        self.active = False

    def draw(self):
        if self.active:
            self.highlight.draw(GL_TRIANGLE_STRIP)
        self.outline.draw(GL_LINE_LOOP)

    def drawCursor(self):
        self
Ejemplo n.º 4
0
    def __init__(self, engine):
        self.engine = engine
        engine.addDrawer(self, 'hud')
        engine.subscribeMouse(self, ['release'])

        self.size = Vector(engine.window.width, 32)
        self.pos = Vector(0, 0)

        #self.tools = [ToolObjectCursor(engine), ToolHand(engine),
        #              ToolAddPoint(engine), ToolRemovePoint(engine)]
        self.tools = [ToolObjectCursor(), ToolVertexCursor()]

        self.outline = pyglet.graphics.vertex_list(4,
            ('v2f/static', self.size.to('r2f')))
Ejemplo n.º 5
0
class Toolbar(object):

    def __init__(self, engine):
        self.engine = engine
        engine.addDrawer(self, 'hud')
        engine.subscribeMouse(self, ['release'])

        self.size = Vector(engine.window.width, 32)
        self.pos = Vector(0, 0)

        #self.tools = [ToolObjectCursor(engine), ToolHand(engine),
        #              ToolAddPoint(engine), ToolRemovePoint(engine)]
        self.tools = [ToolObjectCursor(), ToolVertexCursor()]

        self.outline = pyglet.graphics.vertex_list(4,
            ('v2f/static', self.size.to('r2f')))

    def on_mouse_release(self, x, y, button, modifiers):
        if 0 <= y <= 32:
            idx = x // 32
            if 0 <= idx < len(self.tools):
                self.activate(idx)

    def draw(self):
        self.outline.draw(GL_LINE_LOOP)

        glPushMatrix()
        for tool in self.tools:
            tool.draw()
            glTranslatef(32, 0, 0)
        glPopMatrix()

    def activate(self, idx):
        """Activate the tool at `idx`, and deactivate others."""
        for i, tool in enumerate(self.tools):
            tool.active = (i == idx)
        self.active_tool = self.tools[idx]