I'm trying to move shapes with a mouse and use chipmunk to handle collisions like an air hockey game.
When I move a shape it jitters and jumps around.
I'm using cpBodySlew each 60th of a second for the movement.
I can't find away to detect collisions and have smooth control of the shape's position.
Anyone have suggestions as to how to handle this?
Moving shapes with a mouse.
-
- Posts: 1
- Joined: Wed Jun 24, 2009 10:39 am
- Contact:
-
- Posts: 2
- Joined: Wed Jun 24, 2009 4:36 pm
- Contact:
Re: Moving shapes with a mouse.
Code: Select all
class GodFinger(object):
def __init__(self):
self.body = pymunk.Body(pymunk.inf, pymunk.inf)
self.body.set_velocity_func(self.update_velocity)
self.joint = None
self.point = Vec2d(0.0, 0.0)
def update_velocity(self, body, gravity, damping, dt):
difference = self.point - body.position
old_velocity = body.velocity
new_velocity = difference * (1.0 / dt) * 0.3
body.velocity = old_velocity * 0.7 + new_velocity * 0.3
self.moved = Vec2d(0.0, 0.0)
def grab(self, shape, point):
if not self.joint:
self.joint = pymunk.PivotJoint(self.body, shape.body, point);
space.add(self.joint)
def on_mouse_release(self, x, y, button, modifiers):
if self.joint:
space.remove(self.joint)
self.joint = None
def on_mouse_motion(self, x, y, dx, dy, *_):
self.point = Vec2d(x, y)
def on_mouse_press(self, x, y, button, modifiers):
space.nonstatic_point_query((x,y), self.grab, Vec2d(x,y))
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
self.point = Vec2d(x, y)
In the svn repository there seem to be cool toys that are more advanced than the current things I have.
Who is online
Users browsing this forum: Bing [Bot] and 10 guests