本文整理汇总了Python中pymunk.moment_for_box函数的典型用法代码示例。如果您正苦于以下问题:Python moment_for_box函数的具体用法?Python moment_for_box怎么用?Python moment_for_box使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了moment_for_box函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent, position, walking_task):
self.walking_task = walking_task
(w, l) = walking_task.leg_length / 5.0, walking_task.leg_length
mass = w * l * 0.2
# Upper leg
upperleg = pymunk.Body(mass, pymunk.moment_for_box(mass, w, l))
upperleg.position = pymunk.Vec2d(parent.position) + pymunk.Vec2d(position) + pymunk.Vec2d(0, l/2.0 - w/2.0)
shape = pymunk.Poly.create_box(upperleg, (w,l))
shape.group = 1
shape.friction = 2.0
# Joints
pos = pymunk.Vec2d(parent.position) + pymunk.Vec2d(position)
hip = Joint(parent, upperleg, pos, (-0.1*pi, 0.9*pi), self.walking_task.max_rate)
walking_task.space.add(hip.pivot, hip.motor, hip.limit, upperleg, shape)
# Lower leg
lowerleg = pymunk.Body(mass, pymunk.moment_for_box(mass, w, l * 1.2))
lowerleg.position = pymunk.Vec2d(upperleg.position) + pymunk.Vec2d(0, l - w/2.0)
shape = pymunk.Poly.create_box(lowerleg, (w, l * 1.2))
shape.group = 1
shape.friction = 2.0
# Joints
pos = pymunk.Vec2d(upperleg.position) + pymunk.Vec2d(0, l/2.0 - w/2.0)
knee = Joint(upperleg, lowerleg, pos, (-0.9*pi, 0.1*pi), self.walking_task.max_rate)
walking_task.space.add(knee.pivot, knee.motor, knee.limit, lowerleg, shape)
self.upperleg = upperleg
self.lowerleg = lowerleg
self.hip = hip
self.knee = knee
开发者ID:benzrf,项目名称:peas,代码行数:30,代码来源:walking.py
示例2: __init__
def __init__(self, space, field_friction, field_observation, initial_pos,
size=8,
motor_torque=6,
friction_scale=0.2,
angular_damping=0.9,
force_global=False):
self.field_friction = field_friction
self.field_observation = field_observation
self.size = size
self.friction_scale = friction_scale
self.motor_torque = motor_torque
self.angular_damping = angular_damping
self.force_global = force_global
mass = size ** 2 * 0.2
self.body = body = pymunk.Body(mass, pymunk.moment_for_box(mass, size, size))
body.position = pymunk.Vec2d(initial_pos[0], initial_pos[1])
body.angle = initial_pos[2]
self.shape = shape = pymunk.Poly.create_box(body, (size, size))
shape.group = 1
shape.collision_type = 1
space.add(body, shape)
self.sensors = [(r, theta) for r in np.linspace(1,4,3) * size * 0.75
for theta in np.linspace(-0.5 * np.pi, 0.5 * np.pi, 5)]
self.l = self.r = 0
开发者ID:benzrf,项目名称:peas,代码行数:27,代码来源:linefollowing.py
示例3: _createPhysicsObject
def _createPhysicsObject(self):
"""Return a new physics object"""
if self.geometry_type == 'circle':
inertia = pymunk.moment_for_circle(self.mass, 0, self.radius, (0,0))
else:
inertia = pymunk.moment_for_box(self.mass, self.width, self.height)
#
body = pymunk.Body(self.mass, inertia)
body.velocity = self.velocity
body.force = self.force
#
if self.geometry_type == 'circle':
shape = pymunk.Circle(body, self.radius, (0,0))
else:
#shape = pymunk.Poly(body, [(0, 0), (self.width, 0),
# (self.width, self.height), (0, self.height)])
w2, h2 = self.width/2, self.height/2
shape = pymunk.Poly(body, [(-w2,-h2), (+w2, -h2), (+w2, +h2), (-w2, +h2)])
#
shape.elasticity = self.elasticity
shape.collision_type = 2
shape.group = self.group
shape.layers = self.layers
shape.friction = self.friction
self.shape = shape
self.body = body
开发者ID:gregpuzzles1,项目名称:Sandbox,代码行数:26,代码来源:physical.py
示例4: __init__
def __init__(self, name, width = 0, height = 0, oType = 'loi'):
self.name = name
self.type = oType
if width == 0 or height == 0:
mass = 1
radius = 0.5
inertia = pymunk.moment_for_circle(mass, 0, radius)
self.body = pymunk.Body(mass, inertia)
self.shape = pymunk.Circle(self.body, radius)
self.dim = (1,1)
else:
mass = 1
radius = 0.5
inertia = pymunk.moment_for_box(mass, width, height)
self.body = pymunk.Body(mass, inertia)
verts = [(-width/2,-height/2), (width/2,-height/2),
(width/2, height/2), (-width/2,height/2)]
self.shape = pymunk.Poly(self.body,verts)
self.shape.friction = 0.01
self.shape.elasticity = 0.0
self.dim = (width,height)
开发者ID:elizabeth-matthews,项目名称:atlasChronicle,代码行数:25,代码来源:space.py
示例5: car
def car(self, space):
pos = Vec2d(100,100)
wheel_color = .2,.86,.47
shovel_color = .86,.47,.2
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel1_b = pymunk.Body(mass, moment)
wheel1_s = pymunk.Circle(wheel1_b, radius)
wheel1_s.friction = 1.5
wheel1_s.color = wheel_color
space.add(wheel1_b, wheel1_s)
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel2_b = pymunk.Body(mass, moment)
wheel2_s = pymunk.Circle(wheel2_b, radius)
wheel2_s.friction = 1.5
wheel2_s.color = wheel_color
space.add(wheel2_b, wheel2_s)
mass = 100
size = (50,30)
moment = pymunk.moment_for_box(mass, size)
chassi_b = pymunk.Body(mass, moment)
chassi_s = pymunk.Poly.create_box(chassi_b, size)
space.add(chassi_b, chassi_s)
vs = [(0,0),(0,-45),(25,-45)]
shovel_s = pymunk.Poly(chassi_b, vs, transform = pymunk.Transform(tx=85))
shovel_s.friction = 0.5
shovel_s.color = shovel_color
space.add(shovel_s)
wheel1_b.position = pos - (55,0)
wheel2_b.position = pos + (55,0)
chassi_b.position = pos + (0,25)
space.add(
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25,-15)),
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25, 15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25,-15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25, 15))
)
speed = -4
space.add(
pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
pymunk.SimpleMotor(wheel2_b, chassi_b, speed)
)
with self.canvas:
Color(*wheel_color)
wheel1_s.ky = self.ellipse_from_circle(wheel1_s)
Color(*wheel_color)
wheel2_s.ky = self.ellipse_from_circle(wheel2_s)
Color(*shovel_color)
chassi_s.ky = Quad(points=self.points_from_poly(chassi_s))
shovel_s.ky = Triangle(points=self.points_from_poly(shovel_s))
开发者ID:viblo,项目名称:pymunk,代码行数:60,代码来源:main.py
示例6: __init__
def __init__(self, world, position, width=1.6, length=4.0, tire_width=.25, tire_length=.8, skidmarks=None, body_density=1.0):
mass = width * length * body_density
inertia = moment_for_box(mass, width, length)
self.world = world
body = Body(mass, inertia, )
body.position = position
shape = Poly.create_box(body, size=(width, length))
super(Car, self).__init__(world, body, shape)
slot_density = .01
slot_radius = .1
slot_mass = slot_density * (slot_radius ** 2) * pi
slot_inertia = moment_for_circle(slot_mass, 0.0, slot_radius)
#self.slot = Body(slot_mass, slot_inertia)
flpos = position[0] - width / 2.0 - tire_width * 2, position[1] + length / 2.0
self.front_left = Tire(self, flpos, tire_width, tire_length, skidmarks=skidmarks, powered=False, density=body_density)
frpos = position[0] + width / 2.0 + tire_width * 2, position[1] + length / 2.0
self.front_right = Tire(self, frpos, tire_width, tire_length, skidmarks=skidmarks, powered=False, density=body_density)
rlpos = position[0] - width / 2.0 - tire_width * 2, position[1] - length / 2.0
self.rear_left = Tire(self, rlpos, tire_width * 1.5, tire_length, steerable=False, skidmarks=skidmarks, density=body_density)
rrpos = position[0] + width / 2.0 + tire_width * 2, position[1] - length / 2.0
self.rear_right = Tire(self, rrpos, tire_width * 1.5, tire_length, steerable=False, skidmarks=skidmarks, density=body_density)
self.tires = [self.front_left, self.front_right, self.rear_left, self.rear_right]
开发者ID:deets,项目名称:raspberry-racer,代码行数:29,代码来源:car.py
示例7: handle_hanging
def handle_hanging(self, shape):
logger.info('loading hanging %s', shape)
# assert(not shape.body.is_static)
shape.cache_bb()
bb = shape.bb
rect = pygame.Rect((bb.left, bb.top,
bb.right - bb.left, bb.top - bb.bottom))
rect.normalize()
shape.layers = 3
shape.collision_type = 0
# shape.body.velocity_func = ignore_gravity
shape.body.mass = 1
shape.body.moment = pymunk.moment_for_box(1, rect.width, rect.height)
anchor1 = shape.body.position - (0, 0)
joint = pymunk.PivotJoint(self.space.static_body, shape.body, anchor1,
(0, 0))
self.space.add(joint)
s = pygame.Surface((rect.width, rect.height))
s.fill((255, 255, 255))
spr = sprite.BoxSprite(shape)
spr.original_surface = resources.images['hanging']
m = models.BasicModel()
m.sprite = spr
开发者ID:bitcraft,项目名称:pyweek18,代码行数:29,代码来源:level_state.py
示例8: __init__
def __init__(self, gun_type="pistol"):
from time import time
# set gun attributes
attrs = self._gun_types[gun_type]
l = self.length = attrs["length"]
t = self.thickness = attrs["thickness"]
m = self.mass = attrs["mass"]
mo = self.moment = pymunk.moment_for_box(m, l, t)
f = self.force = attrs["force"]
h = self.handle = attrs["handle"]
b = self.bullet = attrs["bullet"]
c = self.cooldown = attrs["cooldown"]
self.cooldown_timer = time() # timer between shots
self.cooldown_timer_end = self.cooldown_timer + self.cooldown
# pygame init
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([l, t])
self.rect = self.image.get_rect()
# pymunk init
self.body = pymunk.Body(m, mo)
self.body_shape = pymunk.Poly(self.body, [(0,0), (0,-t), (l,-t), (l,0)])
self.body_shape.color = pygame.color.THECOLORS["black"]
self.body_shape.group = COLLISION_GROUP["character"]
self.constraints = []
开发者ID:desophos,项目名称:ragdoll,代码行数:29,代码来源:Gun.py
示例9: addBox
def addBox(self, actorID, **kwargs):
'''Create a box shape and body'''
if kwargs['moment'] == -1:
kwargs['moment'] = pymunk.moment_for_box(kwargs['mass'], kwargs['size'][0], kwargs['size'][1])
body = self.createBody(kwargs['isStatic'], kwargs['mass'], kwargs['moment'], kwargs['pos'])
shape = pymunk.Poly.create_box(body, kwargs['size'])
self.addShape(actorID, body, shape, kwargs['elasticity'], kwargs['collisionType'])
开发者ID:Trinak,项目名称:PyHopeEngine,代码行数:8,代码来源:physics.py
示例10: __init__
def __init__(self, space, name, initpos):
self.name = name
self.space = space
self.body = munk.Body(Block.MASS, munk.moment_for_box(Block.MASS, Block.WIDTH, Block.WIDTH))
w2 = Block.WIDTH / 2
self.verts = [(-w2, -w2), (-w2, w2), (w2, w2), (w2, -w2)]
self.shape = munk.Poly(self.body, self.verts)
self.space.add(self.body, self.shape)
self.body.position = initpos
开发者ID:jzxu,项目名称:SVS,代码行数:9,代码来源:splintersim_standalone.py
示例11: __init__
def __init__(self, space, pos, size):
self.points = []
self.points.append(tuple(pos))
self.points.append((pos[0], pos[1] + size[1]))
self.points.append((pos[0]+ size[0], pos[1]+size[1]))
self.points.append((pos[0]+ size[0], pos[1]))
inertia = pymunk.moment_for_box(1, size[0], size[1])
pymunk.Body.__init__(self, 1, inertia)
self.shape = pymunk.Poly(self, self.points, util.vectorMult(size, -0.5))
space.add(self, self.shape)
开发者ID:MichaelMauderer,项目名称:GeneaCrystal,代码行数:10,代码来源:physic.py
示例12: add_box
def add_box(self, mass=1):
radius = 24
inertia = pymunk.moment_for_box(mass, 0, radius)
body = pymunk.Body(mass, inertia)
x = random.randint(20,600)
y = random.randint(20,400)
body.position = x, y
shape = PymunkShape.square(body, radius)
self.space.add(body, shape)
return shape
开发者ID:Darion,项目名称:pymunk-edu,代码行数:10,代码来源:asteroids.py
示例13: testGeneral
def testGeneral(self):
p.version
p.inf
p.chipmunk_version
m = p.moment_for_box(1, 2, 3)
self.assertAlmostEqual(m, 1.08333333333)
m = p.moment_for_segment(1, Vec2d(-1,0), Vec2d(1,0))
self.assertAlmostEqual(m, 0.33333333333)
开发者ID:cfobel,项目名称:python___pymunk,代码行数:10,代码来源:test_common.py
示例14: box
def box(space):
global box_y
mass = 10
moment = pymunk.moment_for_box(mass, (40,20))
b = pymunk.Body(mass, moment)
s = pymunk.Poly.create_box(b, (40,20))
s.friction = 1
b.position = 600,box_y
box_y -= 30
space.add(b,s)
开发者ID:viblo,项目名称:pymunk,代码行数:11,代码来源:index_video.py
示例15: testMomentHelpers
def testMomentHelpers(self):
m = p.moment_for_circle(1,2,3,(1,2))
self.assertAlmostEqual(m, 11.5)
m = p.moment_for_segment(1, (-10,0), (10,0), 1)
self.assertAlmostEqual(m, 40.6666666666)
m = p.moment_for_poly(1, [(0,0), (10,10), (10,0)], (1,2), 3)
self.assertAlmostEqual(m, 98.3333333333)
m = p.moment_for_box(1, (2, 3))
self.assertAlmostEqual(m, 1.08333333333)
开发者ID:happy-fish,项目名称:pymunk,代码行数:12,代码来源:test_common.py
示例16: __init__
def __init__(self, space, position, size, hinge_pos,
padding,
ang_vel, start, end,
image):
self.padding = padding
padding_left = self.padding[0]
padding_bottom = self.padding[1]
padding_right = self.padding[2]
padding_top = self.padding[3]
self.ang_vel = abs(ang_vel) # Refrain from using negative angular velocities, as it may give unexpected results.
self.start = start + 57
self.end = end + 57
self.size = size
#self.force = force
self.space = space
mass = 3
self.inertia = pymunk.moment_for_box(mass, size[0], size[1])
self.body = pymunk.Body(mass, self.inertia)
self.body.angle = math.radians(start)
self.body.position = (position[0]-hinge_pos[0], position[1]-hinge_pos[1])
self.shape = pymunk.Poly.create_box(self.body, size)
self.shape.friction = 1
self.shape.group = 2
self.space.add(self.body, self.shape)
self.hinge_body = pymunk.Body()
self.hinge_body.angle = math.radians(start) + math.radians(57)
self.hinge_body.position = self.body.position[0] + hinge_pos[0], self.body.position[1] + hinge_pos[1]
pivot = pymunk.constraint.PivotJoint(self.body, self.hinge_body, (hinge_pos), (0,0))
self.space.add(pivot)
gear = pymunk.constraint.GearJoint(self.body, self.hinge_body, 1.0, 1.0)
self.space.add(gear)
self.left = (position[0] - padding_left, position[1] + padding_top)
self.bottom = (position[0] - padding_left, position[1]- padding_bottom)
self.right = (position[0] + padding_right, position[1]- padding_bottom)
self.top = (position[0] + padding_right, position[1] + padding_top)
self.bb = pymunk.BB(position[0] - padding_left, #- hinge_pos[0], # left
position[1] - padding_bottom, # - hinge_pos[1], # bottom
position[0] + padding_right, # - hinge_pos[0], # right
position[1] + padding_top, ) # - hinge_pos[1]) # top
alpha = 100
self.color = (200,0,0,alpha)
self.color2 = (0,200,0,alpha)
self.color3 = (200,200,0,alpha)
self.sprite = loaders.spriteloader(image,
size = size,
anchor = ('center','center'),
linear_interpolation = True)
开发者ID:nuds7,项目名称:FragileTruck---pyglet,代码行数:53,代码来源:mobi.py
示例17: car
def car(space):
pos = Vec2d(100,200)
wheel_color = 52,219,119
shovel_color = 219,119,52
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel1_b = pymunk.Body(mass, moment)
wheel1_s = pymunk.Circle(wheel1_b, radius)
wheel1_s.friction = 1.5
wheel1_s.color = wheel_color
space.add(wheel1_b, wheel1_s)
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel2_b = pymunk.Body(mass, moment)
wheel2_s = pymunk.Circle(wheel2_b, radius)
wheel2_s.friction = 1.5
wheel2_s.color = wheel_color
space.add(wheel2_b, wheel2_s)
mass = 100
size = (50,30)
moment = pymunk.moment_for_box(mass, size)
chassi_b = pymunk.Body(mass, moment)
chassi_s = pymunk.Poly.create_box(chassi_b, size)
space.add(chassi_b, chassi_s)
vs = [(0,0),(25,45),(0,45)]
shovel_s = pymunk.Poly(chassi_b, vs, transform = pymunk.Transform(tx=85))
shovel_s.friction = 0.5
shovel_s.color = shovel_color
space.add(shovel_s)
wheel1_b.position = pos - (55,0)
wheel2_b.position = pos + (55,0)
chassi_b.position = pos + (0,-25)
space.add(
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25,-15)),
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25, 15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25,-15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25, 15))
)
speed = 4
space.add(
pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
pymunk.SimpleMotor(wheel2_b, chassi_b, speed)
)
开发者ID:viblo,项目名称:pymunk,代码行数:52,代码来源:index_video.py
示例18: __init__
def __init__(self, mass, size):
super(Box, self).__init__()
self.size = size
inertia = pymunk.moment_for_box(mass, (size, size))
self.body = pymunk.Body(mass, inertia)
shape = pymunk.Poly.create_box(self.body, (size,size))
shape.elasticity = 0.2
shape.friction = 0.7
space.add(self.body, shape)
p = self.size / 2
self.vertex_list = pyglet.graphics.vertex_list(4, ("v2f\static", (-p,p, p,p, p,-p, -p,-p)))
self.forces = []
开发者ID:ddunwoody,项目名称:adastra,代码行数:13,代码来源:physics.py
示例19: addPhysicsTo
def addPhysicsTo(self, actor):
"""Add physics of a polygon"""
w, h = actor.width, actor.height
#
# Scale the polygon points
actual_points = [(px * w - w / 2.0, py * h - h / 2.0) for px, py in self.points]
if self.mass:
self.body = pymunk.Body(self.mass, moment=pymunk.moment_for_box(self.mass, w, h))
else:
self.body = pymunk.Body()
self.shape = pymunk.Poly(self.body, actual_points)
#
super(PolygonSpritePhysics, self).addPhysicsTo(actor)
开发者ID:IndexErrorCoders,项目名称:PygamesCompilation,代码行数:13,代码来源:physics.py
示例20: box
def box(self, space):
mass = 10
moment = pymunk.moment_for_box(mass, (40,20))
b = pymunk.Body(mass, moment)
s = pymunk.Poly.create_box(b, (40,20))
s.friction = 1
b.position = 600, self.box_y
self.box_y += 30
space.add(b,s)
with self.canvas:
Color(0.2,0.2,0.2)
s.ky = Quad(points=self.points_from_poly(s))
开发者ID:viblo,项目名称:pymunk,代码行数:13,代码来源:main.py
注:本文中的pymunk.moment_for_box函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论