Coordinate system confusion with apply_impulse()
Posted: Thu Mar 06, 2014 11:17 pm
I have searched throughout this forum for an answer to this, but am confused with the topics that address this. I'm using Pymunk and have a rectangular shape (with "nose cone") with these initial vertices:
where CX and CY are the center of my window.
I'd like to have an impulse act on the vertex at (CX, CY+50) or the "rear driver's side corner". So, I've setup an impulse:
I expect this impulse force to move the body down, but also rotate the body counter-clockwise as well.
I think this part is correct. The trouble comes with the offset position. I've tried every combination of things I can think of they all seem to not work as expected (shape is pushed in incorrect directions). Some of what I've tried:
From my understanding of viewtopic.php?f=1&t=59&hilit=coordinate+local+world, #4 seems like the correct way to go, but I get very strange results with it just like the others.
Thanks for the help!
Code: Select all
vertices = [(CX, CY), (CX, CY+50), (CX+100, CY+50), (CX+125, CY+25), (CX+100, CY)]
I'd like to have an impulse act on the vertex at (CX, CY+50) or the "rear driver's side corner". So, I've setup an impulse:
Code: Select all
| 500
|
\ /
+------------------------+
| \
| +
| /
+------------------------+
Code: Select all
angle = ship.body.angle
v = Vec2d(0, -500).rotated(angle)
Code: Select all
# (1)
p = Vec2d(-50, 25)
ship.body.apply_impulse(v, p)
Code: Select all
# (2)
p = Vec2d(-50, 25).rotated(angle)
ship.body.apply_impulse(v, p)
Code: Select all
# (3)
p = ship.body.local_to_world(Vec2d(-50, 25).rotated(angle))
ship.body.apply_impulse(v, p)
Code: Select all
# (4)
p = ship.body.local_to_world(Vec2d(-50, 25)).rotated(angle)
ship.body.apply_impulse(v, p)
Code: Select all
# (5)
px = shape.body.position.x
py = shape.body.position.y
p = ship.body.local_to_world(Vec2d(px-50, py+25)).rotated(angle)
ship.body.apply_impulse(v, p)
Thanks for the help!