Esempio n. 1
0
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(13.0, 0.25)

        bd=box2d.b2BodyDef() 
        bd.position.Set(-4.0, 6.0)
        bd.angle = -0.25

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.5, 0.5)
        sd.density = 25.0

        friction = [0.75, 0.5, 0.35, 0.1, 0.0]

        for i in range(5):
            bd=box2d.b2BodyDef() 
            bd.position.Set(-15.0 + 4.0 * i, 28.0)
            body = self.world.CreateBody(bd) 

            sd.friction = friction[i]
            body.CreateShape(sd)
            body.SetMassFromShapes()
     
if __name__=="__main__":
     test_main.main(VaryingFriction)
Esempio n. 2
0
        jd.Initialize(prevBody, ground, anchor)
        self.world.CreateJoint(jd)

        for i in range(2):
            sd=box2d.b2PolygonDef()
            sd.vertexCount = 3
            sd.setVertex(0,-0.5, 0.0)
            sd.setVertex(1,0.5, 0.0)
            sd.setVertex(2,0.0, 1.5)
            sd.density = 1.0

            bd=box2d.b2BodyDef()
            bd.position.Set(-8.0 + 8.0 * i, 12.0)
            body = self.world.CreateBody(bd)
            body.CreateShape(sd)
            body.SetMassFromShapes()

        for i in range(3):
            sd=box2d.b2CircleDef()
            sd.radius = 0.5
            sd.density = 1.0

            bd=box2d.b2BodyDef()
            bd.position.Set(-6.0 + 6.0 * i, 10.0)
            body = self.world.CreateBody(bd)
            body.CreateShape(sd)
            body.SetMassFromShapes()
 
if __name__=="__main__":
    test_main.main(Bridge)
     
    def __init__(self):
        super(VaryingRestitution, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2CircleDef() 
        sd.radius = 1.0
        sd.density = 1.0

        restitution = [0.0, 0.1, 0.3, 0.5, 0.75, 0.9, 1.0]

        for i in range(7):
            bd=box2d.b2BodyDef() 
            bd.position.Set(-10.0 + 3.0 * i, 20.0)

            body = self.world.CreateBody(bd) 

            sd.restitution = restitution[i]
            body.CreateShape(sd)
            body.SetMassFromShapes()

if __name__=="__main__":
     test_main.main(VaryingRestitution)
Esempio n. 4
0
        
        self.m_wheel.SetXForm(self.m_wheel.GetPosition(), -120.0 * box2d.b2_pi / 180.0)
        self.CreateLeg(-1.0, wheelAnchor)
        self.CreateLeg(1.0, wheelAnchor)
    
    def Step(self, settings) :
        self.DrawString(5, self.textLine, "Keys: left = a, brake = s, right = d, toggle motor = m")
        self.textLine += 15
        
        super(TheoJansen, self).Step(settings)
    
    def Keyboard(self, key) :
        if key==K_a:
            self.m_chassis.WakeUp()
            self.m_motorJoint.SetMotorSpeed(-self.m_motorSpeed)
            
        elif key==K_s:
            self.m_chassis.WakeUp()
            self.m_motorJoint.SetMotorSpeed(0.0)
            
        elif key==K_d:
            self.m_chassis.WakeUp()
            self.m_motorJoint.SetMotorSpeed(self.m_motorSpeed)
            
        elif key==K_m:
            self.m_chassis.WakeUp()
            self.m_motorJoint.EnableMotor(not self.m_motorJoint.IsMotorEnabled())
    
if __name__=="__main__":
    test_main.main(TheoJansen)
Esempio n. 5
0
               bd.angularDamping = 0.02
          
          self.bodies.append(self.world.CreateBody(bd) )
          
          if (index < 4) :
               self.bodies[-1].CreateShape(self.sds[index])
          else :
               self.bodies[-1].CreateShape(self.circleDef)
          self.bodies[-1].SetMassFromShapes()
          
    def DestroyBody(self) :
         for body in self.bodies:
            self.bodies.remove(body)
            self.world.DestroyBody(body)
            return
     
    def Keyboard(self, key) :
        if key==K_1 or key==K_2 or key==K_3 or key==K_4 or key==K_5:
            self.Create(key - K_1)

        elif key==K_d:
            self.DestroyBody()
     
    def Step(self, settings) :
        super(PolyShapes, self).Step(settings)
        self.DrawString(5, self.textLine, "Press 1-5 to drop stuff")
        self.textLine += 15
     
if __name__=="__main__":
     test_main.main(PolyShapes)
Esempio n. 6
0
def main():
    test_main.main()
    run_tests(services)
        body4.CreateShape(boxShapeDef)
        body4.SetMassFromShapes()

        # Small circle
        circleShapeDef=box2d.b2CircleDef()
        circleShapeDef.radius = 1.0
        circleShapeDef.density = 1.0

        circleShapeDef.filter.groupIndex = self.k_smallGroup
        circleShapeDef.filter.categoryBits = self.k_circleCategory
        circleShapeDef.filter.maskBits = self.k_circleMask

        circleBodyDef=box2d.b2BodyDef()
        circleBodyDef.position.Set(5.0, 2.0)

        body5 = self.world.CreateBody(circleBodyDef)
        body5.CreateShape(circleShapeDef)
        body5.SetMassFromShapes()

        # Large circle
        circleShapeDef.radius *= 2.0
        circleShapeDef.filter.groupIndex = self.k_largeGroup
        circleBodyDef.position.Set(5.0, 6.0)

        body6 = self.world.CreateBody(circleBodyDef)
        body6.CreateShape(circleShapeDef)
        body6.SetMassFromShapes()

if __name__=="__main__":
     test_main.main(CollisionFiltering)
Esempio n. 8
0
    def Step(self, settings):
        """Called upon every step.
        You should always call
         -> super(Your_Test_Class, self).Step(settings)
        at the _end_ of your function.
        """

        # do stuff
        self.DrawString(0,self.textLine,"*** Base your own testbeds on me! ***")
        self.textLine+=15

        super(Empty, self).Step(settings)

    def JointDestroyed(self, joint):
        """
        The joint passed in was removed.
        """
        pass


    def BoundaryViolated(self, body):
        """
        The body went out of the world's extents.
        """
        pass

if __name__=="__main__":
    test_main.main(Empty)

Esempio n. 9
0
#          glColor3(1.0, 1.0, 0.0)
#          glBegin(GL_LINES)
#          glVertex2(x1.x, x1.y)
#          glVertex2(x2.x, x2.y)
#          glEnd()

        settings.pause = True
        super(DistanceTest, self).Step(settings)
        settings.pause = False
     
    def Keyboard(self, key) :
        p = self.m_body2.GetPosition=box2d.b2Vec2()
        a = self.m_body2.GetAngle()

        if key==K_a:
           p.x -= 0.1
        elif key==K_d:
           p.x += 0.1
        elif key==K_s:
           p.y -= 0.1
        elif key==K_w:
           p.y += 0.1
        elif key==K_q:
           a += 0.1 * box2d.b2_pi
        elif key==K_e:
           a -= 0.1 * box2d.b2_pi
        self.m_body2.SetXForm(p, a)
     
if __name__=="__main__":
     test_main.main(DistanceTest)
Esempio n. 10
0
            # draw velocity vector
            print v
            self.debugDraw.DrawSegment(center, center + v,
                                       box2d.b2Color(1.0, 1.0, 1.0))

            for force in self.craft.get_force_vectors():
                world_force, world_point, color = force
                self.debugDraw.DrawSegment(world_point,
                                           world_point + (world_force / 100.0),
                                           color)

        self.craft.clear_force_vectors()

    def JointDestroyed(self, joint):
        """
		The joint passed in was removed.
		"""
        print "BOOM!"
        pass

    def BoundaryViolated(self, body):
        """
		The body went out of the world's extents.
		"""
        pass


if __name__ == "__main__":
    test_main.main(Masheet)
Esempio n. 11
0
        bd=box2d.b2BodyDef() 
        bd.position.Set(7.4, 1.0)

        b7 = self.world.CreateBody(bd)
        b7.CreateShape(sd)
        b7.SetMassFromShapes()

        djd=box2d.b2DistanceJointDef() 
        djd.body1 = b3
        djd.body2 = b7
        djd.localAnchor1.Set(6.0, 0.0)
        djd.localAnchor2.Set(0.0, -1.0)
        d = djd.body2.GetWorldPoint(djd.localAnchor2) - djd.body1.GetWorldPoint(djd.localAnchor1)
        djd.length = d.Length()
        self.world.CreateJoint(djd).getAsType() 

        sd=box2d.b2CircleDef() 
        sd.radius = 0.2
        sd.density = 10.0

        
        for i in range(4):
            bd=box2d.b2BodyDef() 
            bd.position.Set(5.9 + 2.0 * sd.radius * i, 2.4)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd)
            body.SetMassFromShapes()

if __name__=="__main__":
     test_main.main(Dominos)
Esempio n. 12
0
        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        a = 0.5
        sd.SetAsBox(a, a)
        sd.density = 5.0

        x=box2d.b2Vec2(-10.0, 0.75)
        y=box2d.b2Vec2() 
        deltaX=box2d.b2Vec2(0.5625, 2.0)
        deltaY=box2d.b2Vec2(1.125, 0.0)

        for i in range(25):
            y = x.copy()

            for j in range(i, 25):
                bd=box2d.b2BodyDef() 
                bd.position = y
                body = self.world.CreateBody(bd) 
                body.CreateShape(sd)
                body.SetMassFromShapes()
                y += deltaY

            x += deltaX

if __name__=="__main__":
     test_main.main(Pyramid)
        nuke = []
        nukeCount = 0
        
        # Traverse the contact results. Destroy bodies that
        # are touching heavier bodies.
        body_pairs = [(p.shape1.GetBody(), p.shape2.GetBody()) for p in self.points]

        for body1, body2 in body_pairs:
            mass1, mass2 = body1.GetMass(), body2.GetMass()

            if mass1 > 0.0 and mass2 > 0.0:
                if mass2 > mass1:
                    nuke_body = body1
                else:
                    nuke_body = body2

                if nuke_body not in nuke:
                    nuke.append(nuke_body)
                    if len(nuke) == k_maxNuke:
                        break

        # Destroy the bodies, skipping duplicates.
        for b in nuke:
            print "Nuking:", b
            self.world.DestroyBody(b)
     
        super(CollisionProcessing, self).Step(settings)

if __name__=="__main__":
     test_main.main(CollisionProcessing)
Esempio n. 14
0
        self.m_shape1 = self.m_body.CreateShape(sd)
        self.m_body.SetMassFromShapes()

        self.m_shape2 = None
             
    def Keyboard(self, key) :
        if key==K_c:
            if not self.m_shape2:
                sd=box2d.b2CircleDef()
                sd.radius = 3.0
                sd.density = 10.0
                sd.localPosition.Set(0.5, -4.0)
                self.m_shape2 = self.m_body.CreateShape(sd)
                self.m_body.SetMassFromShapes()
                self.m_body.WakeUp()

        elif key==K_d:
            if self.m_shape2:
                self.m_body.DestroyShape(self.m_shape2)
                self.m_shape2 = None
                self.m_body.SetMassFromShapes()
                self.m_body.WakeUp()

    def Step(self, settings) :
        self.DrawString(5, self.textLine, "Press: (c) create a shape, (d) destroy a shape.")
        self.textLine += 15
        super(ShapeEditing, self).Step(settings)

if __name__=="__main__":
     test_main.main(ShapeEditing)
Esempio n. 15
0
    def Keyboard(self, key) :
        if key==K_l:
            self.m_joint2.EnableLimit(not self.m_joint2.IsLimitEnabled())
            self.m_joint3.EnableLimit(not self.m_joint3.IsLimitEnabled())
            self.m_joint2.GetBody1().WakeUp()
            self.m_joint3.GetBody2().WakeUp()

        elif key==K_m:
            self.m_joint1.EnableMotor(not self.m_joint1.IsMotorEnabled())
            self.m_joint2.EnableMotor(not self.m_joint2.IsMotorEnabled())
            self.m_joint3.EnableMotor(not self.m_joint3.IsMotorEnabled())
            self.m_joint2.GetBody1().WakeUp()
            self.m_joint3.GetBody2().WakeUp()

        elif key==K_p:
            self.m_joint3.GetBody2().WakeUp()
            self.m_joint3.SetMotorSpeed(-self.m_joint3.GetMotorSpeed())
     
    def Step(self, settings):
        self.DrawString(5, self.textLine, "Keys: (l) limits, (m) motors, (p) prismatic speed")
        self.textLine += 15
        torque1 = self.m_joint1.GetMotorTorque()
        torque2 = self.m_joint2.GetMotorTorque()
        force3 = self.m_joint3.GetMotorForce()
        self.DrawString(5, self.textLine, "Motor Torque = %.0f, %.0f : Motor Force = %.0f" % (torque1,torque2, force3))
        self.textLine += 15
        super(MotorsAndLimits, self).Step(settings)

if __name__=="__main__":
     test_main.main(MotorsAndLimits)
Esempio n. 16
0
    def Keyboard(self, key) :
        if key == K_COMMA:
            if self.m_bullet:
                self.world.DestroyBody(self.m_bullet)
                self.m_bullet = None

            sd=box2d.b2CircleDef()
            sd.density = 20.0
            sd.radius = 0.25
            sd.restitution = 0.05

            bd=box2d.b2BodyDef()
            bd.isBullet = True
            bd.allowSleep = False
            bd.position.Set(-31.0, 5.0)

            self.m_bullet = self.world.CreateBody(bd)
            self.m_bullet.CreateShape(sd)
            self.m_bullet.SetMassFromShapes()

            self.m_bullet.SetLinearVelocity(box2d.b2Vec2(400.0, 0.0))
     
    def Step(self, settings) :
          self.DrawString(5, self.textLine, "Press: (,) to launch a bullet.")
          self.textLine += 15

          super(VerticalStack, self).Step(settings)

if __name__=="__main__":
     test_main.main(VerticalStack)
Esempio n. 17
0
        sweep2.t0 = 0.0
        sweep2.localCenter = self.m_body2.GetLocalCenter()

        toi = box2d.b2TimeOfImpact(self.m_shape1, sweep1, self.m_shape2, sweep2)

        self.DrawString(5, self.textLine, "toi = %g" % (toi))
        self.textLine += 15

        xf2=box2d.b2XForm ()
        sweep2.GetXForm(xf2, toi)
        vertexCount = self.m_shape2.GetVertexCount()
        vertices = []

        localVertices = self.m_shape2.getVertices_b2Vec2()
        for vertex in localVertices:
            vertices.append( box2d.b2Mul(xf2, vertex).tuple() )

        self.debugDraw.DrawPolygon(vertices, vertexCount, box2d.b2Color(0.5, 0.7, 0.9))

        localVertices = self.m_shape2.getCoreVertices_b2Vec2()
        for vertex in localVertices:
            vertices.append( box2d.b2Mul(xf2, vertex).tuple() )
        self.debugDraw.DrawPolygon(vertices, vertexCount, box2d.b2Color(0.5, 0.7, 0.9))
     
        settings.pause = True
        super(TimeOfImpact, self).Step(settings)
        settings.pause = False

if __name__=="__main__":
     test_main.main(TimeOfImpact)
Esempio n. 18
0
        sd_right.SetAsBox(0.15, 2.7, box2d.b2Vec2(1.45, 2.35), -0.2)
        sd_right.density = 4.0

        bd=box2d.b2BodyDef() 
        bd.position.Set( 0.0, 15.0 )
        body = self.world.CreateBody(bd) 
        body.CreateShape(sd_bottom)
        body.CreateShape(sd_left)
        body.CreateShape(sd_right)
        body.SetMassFromShapes()
        
        return

        for i in range(0):
            bd=box2d.b2BodyDef() 
            bd.position.Set(0.0, 15.0 + i)
            bd.isBullet = True
            body = self.world.CreateBody(bd) 
            body.SetAngularVelocity(box2d.b2Random(-50.0, 50.0))

            sd=box2d.b2CircleDef() 
            sd.radius = 0.25
            sd.density = 1.0
            sd.restitution = 0.0
            body.CreateShape(sd)
            body.SetMassFromShapes()


if __name__=="__main__":
     test_main.main(CCDTest)
Esempio n. 19
0
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.6, 0.125)
        sd.density = 20.0
        sd.friction = 0.2

        jd=box2d.b2RevoluteJointDef() 
        jd.collideConnected = False

        y = 25.0
        prevBody=ground
        for i in range(30):
            bd=box2d.b2BodyDef() 
            bd.position.Set(0.5 + i, y)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd)
            body.SetMassFromShapes()
            
            anchor=box2d.b2Vec2(i, y)
            jd.Initialize(prevBody, body, anchor)
            self.world.CreateJoint(jd).getAsType()
            
            prevBody = body
     
if __name__=="__main__":
     test_main.main(Chain)
Esempio n. 20
0
        bd=box2d.b2BodyDef() 

        box.SetAsBox(20.0, 0.5)
        box.friction = 0.62
        bd.position.Set(85.0, 2.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)
     
    def Step(self, settings) :
        self.DrawString(5, self.textLine, "Keys: left = a, brake = s, right = d")
        self.textLine += 15

        super(Car, self).Step(settings)
     
    def Keyboard(self, key) :
        if key==K_a:
           self.m_leftJoint.SetMaxMotorTorque(800.0)
           self.m_leftJoint.SetMotorSpeed(12.0)
           
        elif key==K_s:
           self.m_leftJoint.SetMaxMotorTorque(100.0)
           self.m_leftJoint.SetMotorSpeed(0.0)
           
        elif key==K_d:
           self.m_leftJoint.SetMaxMotorTorque(1200.0)
           self.m_leftJoint.SetMotorSpeed(-36.0)
             
if __name__=="__main__":
     test_main.main(Car)
Esempio n. 21
0
            bd=box2d.b2BodyDef() 
            bd.position.Set(x, 2.05 + 2.5 * i)
            bd.angle = 0.0
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd1)
            body.CreateShape(sd2)
            body.SetMassFromShapes()

        sd_bottom=box2d.b2PolygonDef() 
        sd_bottom.SetAsBox( 1.5, 0.15 )
        sd_bottom.density = 4.0

        sd_left=box2d.b2PolygonDef() 
        sd_left.SetAsBox(0.15, 2.7, box2d.b2Vec2(-1.45, 2.35), 0.2)
        sd_left.density = 4.0

        sd_right=box2d.b2PolygonDef() 
        sd_right.SetAsBox(0.15, 2.7, box2d.b2Vec2(1.45, 2.35), -0.2)
        sd_right.density = 4.0

        bd=box2d.b2BodyDef() 
        bd.position.Set( 0.0, 2.0 )
        body = self.world.CreateBody(bd) 
        body.CreateShape(sd_bottom)
        body.CreateShape(sd_left)
        body.CreateShape(sd_right)
        body.SetMassFromShapes()

if __name__=="__main__":
     test_main.main(CompoundShapes)
Esempio n. 22
0
        self.LWristDef.localAnchor1		= self.RWristDef.localAnchor1	= anchor - self.LHandDef.position
        self.LWristDef.localAnchor2		= self.RWristDef.localAnchor2	= anchor - self.LForearmDef.position
        self.LWristDef.referenceAngle	= self.RWristDef.referenceAngle	= 0.0
        self.LWristDef.lowerAngle		= self.RWristDef.lowerAngle		= -0.174532925
        self.LWristDef.upperAngle		= self.RWristDef.upperAngle		= 0.174532925

    def DefaultPositions(self) :
        global k_scale
        for foot in (self.LFootDef, self.RFootDef):
            foot.position		= k_scale * box2d.b2Vec2(-.122,-.901)
        for calf in (self.LCalfDef, self.RCalfDef):
            calf.position		= k_scale * box2d.b2Vec2(-.177,-.771)
        for thigh in (self.LThighDef, self.RThighDef):
            thigh.position		= k_scale * box2d.b2Vec2(-.217,-.391)
        for upperarm in (self.LUpperArmDef, self.RUpperArmDef):
            upperarm.position	= k_scale * box2d.b2Vec2(-.127,.228)
        for forearm in (self.LForearmDef, self.RForearmDef):
            forearm.position    = k_scale * box2d.b2Vec2(-.117,-.011)
        for hand in (self.LHandDef, self.RHandDef):
            hand.position		= k_scale * box2d.b2Vec2(-.112,-.136)

        self.PelvisDef.position	= k_scale * box2d.b2Vec2(-.177,-.101)
        self.StomachDef.position= k_scale * box2d.b2Vec2(-.142,.088)
        self.ChestDef.position	= k_scale * box2d.b2Vec2(-.132,.282)
        self.NeckDef.position	= k_scale * box2d.b2Vec2(-.102,.518)
        self.HeadDef.position	= k_scale * box2d.b2Vec2(.022,.738)


if __name__=="__main__":
     test_main.main(Test_Biped)
Esempio n. 23
0
        self.m_joint2 = self.world.CreateJoint(pjd).getAsType()

        # Create a payload
        sd.density = 2.0
        bd.position.Set(0.0, 23.0)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()

    def Keyboard(self, key) :
          if key==K_f:
               self.m_joint2.m_enableMotor = not self.m_joint2.m_enableMotor
               self.m_joint2.GetBody2().WakeUp()
               
          elif key==K_m:
               self.m_joint1.m_enableMotor = not self.m_joint1.m_enableMotor
               self.m_joint1.GetBody2().WakeUp()
     
    def Step(self, settings) :
          self.DrawString(5, self.textLine, "Keys: (f) toggle friction, (m) toggle motor")
          self.textLine += 15

          torque = self.m_joint1.GetMotorTorque()
          self.DrawString(5, self.textLine, "Motor Torque = %.0f" % (torque))
          self.textLine += 15
          super(SliderCrank, self).Step(settings)
     
if __name__=="__main__":
     test_main.main(SliderCrank)
Esempio n. 24
0
                # print "lift goes up trans: %G" % self.m_joint_elev.GetJointTranslation()

        # go down
        if self.m_joint_elev.GetJointTranslation() >= self.m_joint_elev.GetUpperLimit() - 2:
            self.m_joint_elev.SetMotorSpeed(-15)
            # printf("lift goes down: %G\n",self.m_joint_elev.GetJointTranslation())

        super(ElasticBody, self).Step(settings)

    # Add a spring force
    def AddSpringForce(self, bA, localA, bB, localB, k, friction, desiredDist):
        pA = bA.GetWorldPoint(localA)
        pB = bB.GetWorldPoint(localB)
        diff = pB - pA
        # Find velocities of attach points
        vA = bA.GetLinearVelocity() - box2d.b2Cross(bA.GetWorldVector(localA), bA.GetAngularVelocity())
        vB = bB.GetLinearVelocity() - box2d.b2Cross(bB.GetWorldVector(localB), bB.GetAngularVelocity())

        vdiff = vB - vA
        dx = diff.Normalize()  # normalizes diff and puts length into dx
        vrel = vdiff.x * diff.x + vdiff.y * diff.y
        forceMag = -k * (dx - desiredDist) - friction * vrel
        diff *= forceMag
        bB.ApplyForce(diff, bA.GetWorldPoint(localA))
        diff *= -1.0
        bA.ApplyForce(diff, bB.GetWorldPoint(localB))


if __name__ == "__main__":
    test_main.main(ElasticBody)
Esempio n. 25
0
            shape1, shape2=point.shape1, point.shape2
            other=None
            
            if shape1 == self.m_sensor:
                other = shape2.GetBody()
            elif shape2 == self.m_sensor:
                other = shape1.GetBody()
            else:
                continue

            ground = self.m_sensor.GetBody()
            circle = self.m_sensor.getAsType()
            center = ground.GetWorldPoint(circle.GetLocalPosition())

            d = center - point.position

            # Not in the bindings yet
            FLT_EPSILON = 1.192092896e-07
            if (d.LengthSquared() < FLT_EPSILON * FLT_EPSILON) :
                continue

            d.Normalize()
            F = 100.0 * d
            other.ApplyForce(F, point.position)

        super(SensorTest, self).Step(settings)


if __name__=="__main__":
     test_main.main(SensorTest)
Esempio n. 26
0
        body1.CreateShape(sd)
        body1.SetMassFromShapes()

        bd.position.Set(10.0, y)
        body2 = self.world.CreateBody(bd) 
        body2.CreateShape(sd)
        body2.SetMassFromShapes()

        pulleyDef=box2d.b2PulleyJointDef() 

        anchor1=box2d.b2Vec2(-10.0, y + b)

        anchor2=box2d.b2Vec2(10.0, y + b)

        groundAnchor1=box2d.b2Vec2(-10.0, y + b + L)

        groundAnchor2=box2d.b2Vec2(10.0, y + b + L)
        pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0)

        self.m_joint1 = self.world.CreateJoint(pulleyDef).getAsType() 
     
    def Step(self, settings) :
        ratio = self.m_joint1.GetRatio()
        L = self.m_joint1.GetLength1() + ratio * self.m_joint1.GetLength2()
        self.DrawString(5, self.textLine, "L1 + %.2f * L2 = %.2f" % (ratio, L))
        self.textLine += 15
        super(Pulleys, self).Step(settings)

if __name__=="__main__":
    test_main.main(Pulleys)
        cd.setVertex(4,-0.5 * s, w)
        cd.setVertex(5,-0.5 * w, b + s)
        cd.setVertex(6,-0.5 * w, b)
        cd.setVertex(7,-0.5 * s, 0.0)
        cd.density = 1.0

        self.m_ball_shape = self.m_ball.CreateShape(cd)
        self.m_ball.SetMassFromShapes()

    def Step(self, settings):
        strings = []
        for point in self.points:
            if  point.state ==fwContactTypes.contactAdded:
                strings.append("added:   " + str(point.shape1) + " . " + str(point.shape2) + ":" + str(point.id.key))
            elif  point.state ==fwContactTypes.contactRemoved:
                strings.append("removed: " + str(point.shape1) + " . " + str(point.shape2) + ":" + str(point.id.key))
            elif  point.state ==fwContactTypes.contactPersisted:
                strings.append("persisted:" + str(point.shape1) + " . " + str(point.shape2) + ":" + str(point.id.key))

        if len(strings) > 15:
            strings = strings[:14]

        for string in strings:
           self.DrawString(5, self.textLine, string)
           self.textLine += 15

        super(ContactCallbackTest, self).Step(settings)

if __name__=="__main__":
     test_main.main(ContactCallbackTest)
Esempio n. 28
0
			center = self.craft.get_center()
			self.setCenter(center * self._viewZoom)

			# draw velocity vector
			print v
			self.debugDraw.DrawSegment(center, center + v, box2d.b2Color(1.0, 1.0, 1.0))

			for force in self.craft.get_force_vectors():
				world_force, world_point, color = force
				self.debugDraw.DrawSegment(world_point, world_point + (world_force / 100.0), color)

		self.craft.clear_force_vectors()

	def JointDestroyed(self, joint):
		"""
		The joint passed in was removed.
		"""
		print "BOOM!"
		pass


	def BoundaryViolated(self, body):
		"""
		The body went out of the world's extents.
		"""
		pass

if __name__=="__main__":
	test_main.main(Masheet)

Esempio n. 29
0
        self.world.SetGravity(box2d.b2Vec2_zero)
        self.world.SetPositionCorrection(False)
     
    def Step(self, settings) :
        settings.pause = True
        super(PolyCollision, self).Step(settings)
        settings.pause = False
     
    def Keyboard(self, key) :
          p = self.m_body2.GetPosition()
          a = self.m_body2.GetAngle()
          
          if key==K_a:
               p.x -= 0.1
          elif key==K_d:
               p.x += 0.1
          elif key==K_s:
               p.y -= 0.1
          elif key==K_w:
               p.y += 0.1
          elif key==K_q:
               a += 0.1 * box2d.b2_pi
          elif key==K_e:
               a -= 0.1 * box2d.b2_pi

          self.m_body2.SetXForm(p, a)
     
if __name__=="__main__":
     test_main.main(PolyCollision)
Esempio n. 30
0
        sd2=box2d.b2PolygonDef() 
        sd2.vertexCount = 3
        sd2.setVertex(0, box2d.b2Mul(xf2, box2d.b2Vec2(-1.0, 0.0)))
        sd2.setVertex(1, box2d.b2Mul(xf2, box2d.b2Vec2(1.0, 0.0)))
        sd2.setVertex(2, box2d.b2Mul(xf2, box2d.b2Vec2(0.0, 0.5)))
        sd2.density = 2.0

        bd=box2d.b2BodyDef() 
        bd.angularDamping = 2.0
        bd.linearDamping = 0.1

        bd.position.Set(0.0, 1.05)
        bd.angle = box2d.b2_pi
        self.m_body = self.world.CreateBody(bd)
        self.m_body.CreateShape(sd1)
        self.m_body.CreateShape(sd2)
        self.m_body.SetMassFromShapes()
     
    def Keyboard(self, key) :
        if key==K_w:
            f = self.m_body.GetWorldVector(box2d.b2Vec2(0.0, -200.0))
            p = self.m_body.GetWorldPoint(box2d.b2Vec2(0.0, 2.0))
            self.m_body.ApplyForce(f, p)
        elif key==K_a:
            self.m_body.ApplyTorque(20.0)
        elif key==K_d:
            self.m_body.ApplyTorque(-20.0)

if __name__=="__main__":
     test_main.main(ApplyForce)
Esempio n. 31
0
        jd4.body1 = body1
        jd4.body2 = body2
        jd4.joint1 = self.m_joint1
        jd4.joint2 = self.m_joint2
        jd4.ratio = circle2.radius / circle1.radius
        self.m_joint4 = self.world.CreateJoint(jd4).getAsType()

        jd5=box2d.b2GearJointDef() 
        jd5.body1 = body2
        jd5.body2 = body3
        jd5.joint1 = self.m_joint2
        jd5.joint2 = self.m_joint3
        jd5.ratio = -1.0 / circle2.radius
        self.m_joint5 = self.world.CreateJoint(jd5).getAsType()
             
    def Step(self, settings):
        ratio = self.m_joint4.GetRatio()
        value = self.m_joint1.GetJointAngle() + ratio * self.m_joint2.GetJointAngle()
        self.DrawString(5, self.textLine, "theta1 + %.2f * theta2 = %.2f" % (ratio, value))
        self.textLine += 15

        ratio = self.m_joint5.GetRatio()
        value = self.m_joint2.GetJointAngle() + ratio * self.m_joint3.GetJointTranslation()
        self.DrawString(5, self.textLine, "theta2 + %.2f * delta = %.2f" % (ratio, value))
        self.textLine += 15

        super(Gears, self).Step(settings)

if __name__=="__main__":
     test_main.main(Gears)