Esempio n. 1
0
 def __init__(self, a, b, *args):
     """a and b are the two bodies to connect, and pivot is the point in
     world coordinates of the pivot. Because the pivot location is given in
     world coordinates, you must have the bodies moved into the correct
     positions already. 
     Alternatively you can specify the joint based on a pair of anchor 
     points, but make sure you have the bodies in the right place as the 
     joint will fix itself as soon as you start simulating the space. 
     
     That is, either create the joint with PivotJoint(a, b, pivot) or 
     PivotJoint(a, b, anchr1, anchr2).
     
         a : `Body`
             The first of the two bodies
         b : `Body`
             The second of the two bodies
         args : [Vec2d] or [Vec2d,Vec2d]
             Either one pivot point, or two anchor points
     """
     
     if len(args) == 1:
         self._constraint = cp.cpPivotJointNew(a._body, b._body, args[0])
     elif len(args) == 2:
         self._constraint = cp.cpPivotJointNew2(a._body, b._body, args[0], args[1])
     else:
         raise Exception("You must specify either one pivot point or two anchor points")
         
     self._ccontents = self._constraint.contents
     self._pjc = cp.cast(self._constraint, ct.POINTER(cp.cpPivotJoint)).contents
     self._a = a
     self._b = b
Esempio n. 2
0
    def __init__(self, a, b, *args):
        """a and b are the two bodies to connect, and pivot is the point in
        world coordinates of the pivot. Because the pivot location is given in
        world coordinates, you must have the bodies moved into the correct
        positions already. 
        Alternatively you can specify the joint based on a pair of anchor 
        points, but make sure you have the bodies in the right place as the 
        joint will fix itself as soon as you start simulating the space. 
        
        That is, either create the joint with PivotJoint(a, b, pivot) or 
        PivotJoint(a, b, anchr1, anchr2).
        
            a : `Body`
                The first of the two bodies
            b : `Body`
                The second of the two bodies
            args : [Vec2d] or [Vec2d,Vec2d]
                Either one pivot point, or two anchor points
        """

        if len(args) == 1:
            self._constraint = cp.cpPivotJointNew(a._body, b._body, args[0])
        elif len(args) == 2:
            self._constraint = cp.cpPivotJointNew2(a._body, b._body, args[0],
                                                   args[1])
        else:
            raise Exception(
                "You must specify either one pivot point or two anchor points")

        self._ccontents = self._constraint.contents
        self._pjc = cp.cast(self._constraint,
                            ct.POINTER(cp.cpPivotJoint)).contents
        self._a = a
        self._b = b
Esempio n. 3
0
 def __init__(self, a, b, groove_a, groove_b, anchr2):
     """The groove goes from groove_a to groove_b on body a, and the pivot 
     is attached to anchr2 on body b. All coordinates are body local. 
     """
     self._constraint = cp.cpGrooveJointNew(a._body, b._body, groove_a, groove_b, anchr2)
     self._ccontents = self._constraint.contents
     self._pjc = cp.cast(self._constraint, ct.POINTER(cp.cpGrooveJoint)).contents
     self._a = a
     self._b = b
Esempio n. 4
0
 def __init__(self, a, b, anchr1, anchr2, min, max):
     """a and b are the two bodies to connect, anchr1 and anchr2 are the
     anchor points on those bodies, and min and max define the allowed
     distances of the anchor points.
     """
     self._constraint = cp.cpSlideJointNew(a._body, b._body, anchr1, anchr2, min, max)
     self._ccontents = self._constraint.contents
     self._sjc = cp.cast(self._constraint, ct.POINTER(cp.cpSlideJoint)).contents
     self._a = a
     self._b = b
Esempio n. 5
0
    def __init__(self, a, b, anchr1=(0,0), anchr2=(0,0)):
        """a and b are the two bodies to connect, and anchr1 and anchr2 are the
        anchor points on those bodies.
        """

        self._constraint = cp.cpPinJointNew(a._body, b._body, anchr1, anchr2)
        self._ccontents = self._constraint.contents
        self._pjc = cp.cast(self._constraint, ct.POINTER(cp.cpPinJoint)).contents
        self._a = a
        self._b = b
Esempio n. 6
0
 def __init__(self, a, b, phase, ratchet):
     """Works like a socket wrench. ratchet is the distance between 
     "clicks", phase is the initial offset to use when deciding where the 
     ratchet angles are.  
     """
     self._constraint = cp.cpRatchetJointNew(a._body, b._body, phase, ratchet)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint, ct.POINTER(cp.cpRatchetJoint)).contents
     self._a = a
     self._b = b
Esempio n. 7
0
 def __init__(self, a, b, min, max):
     """Constrains the relative rotations of two bodies. min and max are 
     the angular limits in radians. It is implemented so that it's possible 
     to for the range to be greater than a full revolution.
     """
     self._constraint = cp.cpRotaryLimitJointNew(a._body, b._body, min, max)
     self._ccontents = self._constraint.contents
     self._rlc = cp.cast(self._constraint, ct.POINTER(cp.cpRotaryLimitJoint)).contents
     self._a = a
     self._b = b
Esempio n. 8
0
 def __init__(self, a, b, rate):
     """Keeps the relative angular velocity of a pair of bodies constant. 
     rate is the desired relative angular velocity. You will usually want 
     to set an force (torque) maximum for motors as otherwise they will be 
     able to apply a nearly infinite torque to keep the bodies moving.  
     """
     self._constraint = cp.cpSimpleMotorNew(a._body, b._body, rate)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint, ct.POINTER(cp.cpSimpleMotor)).contents
     self._a = a
     self._b = b
Esempio n. 9
0
 def __init__(self, a, b, phase, ratio):
     """Keeps the angular velocity ratio of a pair of bodies constant. 
     ratio is always measured in absolute terms. It is currently not 
     possible to set the ratio in relation to a third body's angular 
     velocity. phase is the initial angular offset of the two bodies.  
     """
     self._constraint = cp.cpGearJointNew(a._body, b._body, phase, ratio)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint, ct.POINTER(cp.cpGearJoint)).contents
     self._a = a
     self._b = b
Esempio n. 10
0
 def __init__(self, a, b, groove_a, groove_b, anchr2):
     """The groove goes from groove_a to groove_b on body a, and the pivot 
     is attached to anchr2 on body b. All coordinates are body local. 
     """
     self._constraint = cp.cpGrooveJointNew(a._body, b._body, groove_a,
                                            groove_b, anchr2)
     self._ccontents = self._constraint.contents
     self._pjc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpGrooveJoint)).contents
     self._a = a
     self._b = b
Esempio n. 11
0
    def __init__(self, a, b, anchr1, anchr2):
        """a and b are the two bodies to connect, and anchr1 and anchr2 are the
        anchor points on those bodies.
        """

        self._constraint = cp.cpPinJointNew(a._body, b._body, anchr1, anchr2)
        self._ccontents = self._constraint.contents
        self._pjc = cp.cast(self._constraint,
                            ct.POINTER(cp.cpPinJoint)).contents
        self._a = a
        self._b = b
Esempio n. 12
0
 def __init__(self, a, b, min, max):
     """Constrains the relative rotations of two bodies. min and max are 
     the angular limits in radians. It is implemented so that it's possible 
     to for the range to be greater than a full revolution.
     """
     self._constraint = cp.cpRotaryLimitJointNew(a._body, b._body, min, max)
     self._ccontents = self._constraint.contents
     self._rlc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpRotaryLimitJoint)).contents
     self._a = a
     self._b = b
Esempio n. 13
0
 def __init__(self, a, b, anchr1, anchr2, min, max):
     """a and b are the two bodies to connect, anchr1 and anchr2 are the
     anchor points on those bodies, and min and max define the allowed
     distances of the anchor points.
     """
     self._constraint = cp.cpSlideJointNew(a._body, b._body, anchr1, anchr2,
                                           min, max)
     self._ccontents = self._constraint.contents
     self._sjc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpSlideJoint)).contents
     self._a = a
     self._b = b
Esempio n. 14
0
 def __init__(self, a, b, rate):
     """Keeps the relative angular velocity of a pair of bodies constant. 
     rate is the desired relative angular velocity. You will usually want 
     to set an force (torque) maximum for motors as otherwise they will be 
     able to apply a nearly infinite torque to keep the bodies moving.  
     """
     self._constraint = cp.cpSimpleMotorNew(a._body, b._body, rate)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpSimpleMotor)).contents
     self._a = a
     self._b = b
Esempio n. 15
0
 def __init__(self, a, b, phase, ratio):
     """Keeps the angular velocity ratio of a pair of bodies constant. 
     ratio is always measured in absolute terms. It is currently not 
     possible to set the ratio in relation to a third body's angular 
     velocity. phase is the initial angular offset of the two bodies.  
     """
     self._constraint = cp.cpGearJointNew(a._body, b._body, phase, ratio)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpGearJoint)).contents
     self._a = a
     self._b = b
Esempio n. 16
0
 def __init__(self, a, b, phase, ratchet):
     """Works like a socket wrench. ratchet is the distance between 
     "clicks", phase is the initial offset to use when deciding where the 
     ratchet angles are.  
     """
     self._constraint = cp.cpRatchetJointNew(a._body, b._body, phase,
                                             ratchet)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpRatchetJoint)).contents
     self._a = a
     self._b = b
Esempio n. 17
0
 def __init__(self, a, b, rest_angle, stiffness, damping):
     """Like a damped spring, but works in an angular fashion. 
     
     :Parameters:
         rest_angle
             The relative angle in radians that the bodies want to have
         stiffness
             The spring constant (Young's modulus). 
         damping
             How soft to make the damping of the spring. 
     """
     self._constraint = cp.cpDampedRotarySpringNew(a._body, b._body, rest_angle, stiffness, damping)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint, ct.POINTER(cp.cpDampedRotarySpring)).contents
     self._a = a
     self._b = b
Esempio n. 18
0
 def __init__(self, a, b, anchr1, anchr2, rest_length, stiffness, damping):
     """Defined much like a slide joint. 
     
     :Parameters:
         rest_length : float
             The distance the spring wants to be.
         stiffness : float
             The spring constant (Young's modulus). 
         damping : float
             How soft to make the damping of the spring. 
     """
     self._constraint = cp.cpDampedSpringNew(a._body, b._body, anchr1, anchr2, rest_length, stiffness, damping)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint, ct.POINTER(cp.cpDampedSpring)).contents
     self._a = a
     self._b = b
Esempio n. 19
0
 def __init__(self, a, b, anchr1, anchr2, rest_length, stiffness, damping):
     """Defined much like a slide joint. 
     
     :Parameters:
         rest_length : float
             The distance the spring wants to be.
         stiffness : float
             The spring constant (Young's modulus). 
         damping : float
             How soft to make the damping of the spring. 
     """
     self._constraint = cp.cpDampedSpringNew(a._body, b._body, anchr1,
                                             anchr2, rest_length, stiffness,
                                             damping)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpDampedSpring)).contents
     self._a = a
     self._b = b
Esempio n. 20
0
 def __init__(self, a, b, rest_angle, stiffness, damping):
     """Like a damped spring, but works in an angular fashion. 
     
     :Parameters:
         rest_angle
             The relative angle in radians that the bodies want to have
         stiffness
             The spring constant (Young's modulus). 
         damping
             How soft to make the damping of the spring. 
     """
     self._constraint = cp.cpDampedRotarySpringNew(a._body, b._body,
                                                   rest_angle, stiffness,
                                                   damping)
     self._ccontents = self._constraint.contents
     self._dsc = cp.cast(self._constraint,
                         ct.POINTER(cp.cpDampedRotarySpring)).contents
     self._a = a
     self._b = b