def _getSafeStartPoint(cls, world, rock_tags, start, end): """Return the best end point to use for a rope with the given start point We avoid having the end point be inside another actor """ # # Find all likely looking bodies we might interact with actors = world.getActors().findActorsByTags(rock_tags) # # Look for hits hits = [] for actor in actors: query = actor.getPhysical().shape.segment_query(end, start) if query: hits.append((query.get_hit_distance(), query.get_hit_point())) # # Were there any? if not hits: # None - just use the specified one return start # # Find closest hits.sort() return hits[0][1]
def testCanSerializeAndDeserialize(self): """testCanSerializeAndDeserialize: should be able to store and restore a physics based object""" a = serge.actor.Actor('test', 'test') a.visual = serge.blocks.visualblocks.Circle(40, (0,0,0,0)) a.setPhysical(serge.physical.PhysicalConditions(mass=1.0, radius=1.0, velocity=(1.0, 0.0), update_angle=True, visual_size=serge.geometry.CIRCLE)) a.moveTo(0,0) self.w.addActor(a) self.w.updateWorld(1000.0) # # Serialize and deserialize world = serge.serialize.Serializable.fromString(self.w.asString()) world.updateWorld(1000.0) actor = world.findActorByName('test') self.assertAlmostEqual(2.0, actor.x) self.assertEqual(True, actor.getPhysical().update_angle) self.assertEqual(serge.geometry.CIRCLE, actor.getPhysical().visual_size) self.assertEqual(40, actor.getPhysical().radius)
def linkActorTo(self, actor, move=False, link_length=False): """Link an actor to ourself""" # # Move the other actor if needed if move: actor.moveTo(self.x, self.y) # # Don't link too close length = 0 if not link_length else self.getDistanceFrom(actor) j = pymunk.SlideJoint(self.getPhysical().body, actor.getPhysical().body, (0,0), (0,0), 0, max(length, link_length+self.width/2)) self.getPhysical().space.add(j) actor.point_link = j self.log.debug('Linked %s (%s) and %s (%s) with length %s (%s)' % ( self.getNiceName(), (self.x, self.y), actor, (actor.x, actor.y), link_length+self.width/2, self.getDistanceFrom(actor))) # # Wake up the rope if needed if self.parent is not None: self.parent.wakeUp()