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)
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
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
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')))
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]