Esempio n. 1
0
def test_odejoint_attach_both(world):
    from panda3d import ode

    body1 = ode.OdeBody(world)
    body2 = ode.OdeBody(world)

    assert len(body1.joints) == 0
    assert len(body2.joints) == 0

    joint = ode.OdeBallJoint(world)
    joint.attach(body1, body2)

    assert tuple(body1.joints) == (joint, )
    assert tuple(body2.joints) == (joint, )
Esempio n. 2
0
 def createBox(self, world, space, density, lx, ly, lz, colOnlyBall = 0):
     body = ode.OdeBody(self.world)
     M = ode.OdeMass()
     M.setSphere(density, 0.3 * (lx + ly + lz))
     body.setMass(M)
     boxsize = Vec3(lx, ly, lz)
     geom = ode.OdeBoxGeom(space, boxsize)
     geom.setBody(body)
     self.space.setSurfaceType(geom, 0)
     self.space.setCollideId(geom, 7)
     self.massList.append(M)
     self.geomList.append(geom)
     if colOnlyBall:
         geom.setCollideBits(BitMask32(251658240))
         geom.setCategoryBits(BitMask32(0))
     elif colOnlyBall == 2:
         geom.setCollideBits(BitMask32(0))
         geom.setCategoryBits(BitMask32(0))
     if self.canRender:
         color = random.choice([Vec4(1.0, 0.0, 0.5, 1.0), Vec4(0.5, 0.5, 1.0, 1.0), Vec4(0.5, 1.0, 0.5, 1.0)])
         boxsize = Vec3(lx, ly, lz)
         boxNodePathGeom, t1, t2 = BuildGeometry.addBoxGeom(self.worldAttach, lx, ly, lz, color, 1)
         boxNodePathGeom.setPos(0, 0, -100)
         self.odePandaRelationList.append((boxNodePathGeom, body))
     else:
         boxNodePathGeom = None
         self.bodyList.append((None, body))
     return (boxNodePathGeom, body)
Esempio n. 3
0
def test_odejoint_attach_1(world):
    from panda3d import ode

    body = ode.OdeBody(world)

    assert len(body.joints) == 0

    joint = ode.OdeBallJoint(world)
    joint.attach(None, body)

    assert tuple(body.joints) == (joint, )
Esempio n. 4
0
    def createPinWheel(self, world, space, density, lx, ly, lz, numBoxes, disV, disH, colOnlyBall = 0, attachedGeo = None, aHPR = None, aPos = None, offRot = 0):
        body = ode.OdeBody(self.world)
        M = ode.OdeMass()
        M.setBox(density, lx, ly, lz)
        body.setMass(M)
        body.setFiniteRotationMode(1)
        boxsize = Vec3(lx, ly * 0.5, lz)
        boxsize2 = Vec3(ly * 0.5, lx, lz)
        self.massList.append(M)
        self.placerNode.setPos(0, 0, 0)
        self.placerNode.setHpr(0, 0, 0)
        self.subPlacerNode.setHpr(0, 0, 0)
        self.subPlacerNode.setPos(disH, disV, 0)
        if self.canRender:
            someNodePathGeom = render.attachNewNode('pinwheel')
        else:
            someNodePathGeom = self.root.attachNewNode('pinwheel')
        for num in xrange(numBoxes):
            spin = 360.0 * float(num) / float(numBoxes) + float(offRot)
            self.placerNode.setH(spin)
            geom = ode.OdeBoxGeom(space, boxsize)
            geom.setBody(body)
            geom.setOffsetPosition(self.subPlacerNode.getPos(self.root))
            geom.setOffsetQuaternion(self.subPlacerNode.getQuat(self.root))
            self.geomList.append(geom)
            self.space.setSurfaceType(geom, 0)
            self.space.setCollideId(geom, 13)
            if colOnlyBall == 1:
                geom.setCollideBits(BitMask32(251658240))
                geom.setCategoryBits(BitMask32(0))
            elif colOnlyBall == 2:
                geom.setCollideBits(BitMask32(0))
                geom.setCategoryBits(BitMask32(0))
            if not attachedGeo:
                boxNodePathGeom, t1, t2 = BuildGeometry.addBoxGeom(someNodePathGeom, lx, ly * 0.5, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
                boxNodePathGeom.setPos(self.subPlacerNode.getPos(self.root))
                boxNodePathGeom.setHpr(self.subPlacerNode.getHpr(self.root))

        if attachedGeo and self.canRender:
            attachedGeo.reparentTo(someNodePathGeom)
            attachedGeo.setHpr(aHPR[0], aHPR[1], aHPR[2])
            attachedGeo.setPos(aPos[0], aPos[1], aPos[2])
        if self.canRender:
            self.odePandaRelationList.append((someNodePathGeom, body))
        else:
            someNodePathGeom = None
            self.bodyList.append((None, body))
        return (someNodePathGeom, body)
Esempio n. 5
0
 def createSphere(self, world, space, density, radius, ballIndex = None):
     self.notify.debug('create sphere index %s' % ballIndex)
     body = ode.OdeBody(world)
     M = ode.OdeMass()
     M.setSphere(density, radius)
     body.setMass(M)
     body.setPosition(0, 0, -100)
     geom = ode.OdeSphereGeom(space, radius)
     self.space.setSurfaceType(geom, 1)
     self.notify.debug('collide ID is %s' % self.space.setCollideId(geom, 42))
     self.massList.append(M)
     self.geomList.append(geom)
     if ballIndex == 1:
         self.notify.debug('1')
         geom.setCollideBits(BitMask32(16777215))
         geom.setCategoryBits(BitMask32(4278190080L))
     elif ballIndex == 2:
         self.notify.debug('2')
         geom.setCollideBits(BitMask32(16777215))
         geom.setCategoryBits(BitMask32(4278190080L))
     elif ballIndex == 3:
         self.notify.debug('3')
         geom.setCollideBits(BitMask32(16777215))
         geom.setCategoryBits(BitMask32(4278190080L))
     elif ballIndex == 4:
         self.notify.debug('4')
         geom.setCollideBits(BitMask32(16777215))
         geom.setCategoryBits(BitMask32(4278190080L))
     else:
         geom.setCollideBits(BitMask32(4294967295L))
         geom.setCategoryBits(BitMask32(4294967295L))
     geom.setBody(body)
     if self.notify.getDebug():
         self.notify.debug('golf ball geom id')
         geom.write()
         self.notify.debug(' -')
     self.notify.debug('Collide Bits %s' % geom.getCollideBits())
     if self.canRender:
         testball = render.attachNewNode('Ball Holder')
         ballmodel = loader.loadModel('phase_6/models/golf/golf_ball')
         ballmodel.reparentTo(testball)
         ballmodel.setColor(*GolfGlobals.PlayerColors[ballIndex - 1])
         testball.setPos(0, 0, -100)
         self.odePandaRelationList.append((testball, body))
     else:
         testball = None
         self.bodyList.append((None, body))
     return (testball, body, geom)
Esempio n. 6
0
 def createCross(self, world, space, density, lx, ly, lz, colOnlyBall = 0, attachedGeo = None, aHPR = None, aPos = None):
     body = ode.OdeBody(self.world)
     M = ode.OdeMass()
     M.setBox(density, lx, ly, lz)
     body.setMass(M)
     body.setFiniteRotationMode(1)
     boxsize = Vec3(lx, ly, lz)
     boxsize2 = Vec3(ly, lx, lz)
     geom = ode.OdeBoxGeom(space, boxsize)
     geom.setBody(body)
     self.space.setSurfaceType(geom, 0)
     self.space.setCollideId(geom, 13)
     geom2 = ode.OdeBoxGeom(space, boxsize2)
     geom2.setBody(body)
     self.space.setSurfaceType(geom2, 0)
     self.space.setCollideId(geom2, 26)
     self.massList.append(M)
     self.geomList.append(geom)
     self.geomList.append(geom2)
     self.odePandaRelationList.append((boxNodePathGeom, body))
     if colOnlyBall == 1:
         geom.setCollideBits(BitMask32(251658240))
         geom.setCategoryBits(BitMask32(0))
         geom2.setCollideBits(BitMask32(251658240))
         geom2.setCategoryBits(BitMask32(0))
     elif colOnlyBall == 2:
         geom.setCollideBits(BitMask32(0))
         geom.setCategoryBits(BitMask32(0))
         geom2.setCollideBits(BitMask32(0))
         geom2.setCategoryBits(BitMask32(0))
     if self.canRender:
         boxNodePathGeom, t1, t2 = BuildGeometry.addBoxGeom(self.worldAttach, lx, ly, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
         boxNodePathGeom.setPos(0, 0, -100)
         boxNodePathGeom2, t1, t2 = BuildGeometry.addBoxGeom(boxNodePathGeom, ly, lx, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
         boxNodePathGeom2.setPos(0, 0, 0)
         if attachedGeo:
             attachedGeo.reparentTo(boxNodePathGeom)
             attachedGeo.setHpr(0, 0, 90)
             attachedGeo.setPos(-4.8, 0, -2.0)
         self.odePandaRelationList.append((boxNodePathGeom, body))
     else:
         boxNodePathGeom = None
         self.bodyList.append((None, body))
     return (boxNodePathGeom, body)
Esempio n. 7
0
 def createRays(self):
     self.notify.debug('createRays')
     body = ode.OdeBody(self.world)
     self.ballRay = ode.OdeRayGeom(self.space, 50.0)
     self.ballRay.setBody(body)
     self.ballRay.setOffsetRotation(Mat3(1, 0, 0, 0, -1, 0, 0, 0, -1))
     self.ballRay.setOffsetPosition(0, 0, 0.0)
     self.ballRay.setCollideBits(BitMask32(16773375))
     self.ballRay.setCategoryBits(BitMask32(4278190080L))
     self.ballRayBody = body
     self.space.setCollideId(self.ballRay, GolfGlobals.OOB_RAY_COLLIDE_ID)
     self.rayList.append(self.ballRay)
     self.rayList.append(self.ballRayBody)
     self.skyRay = ode.OdeRayGeom(self.space, 100.0)
     self.skyRay.setCollideBits(BitMask32(240))
     self.skyRay.setCategoryBits(BitMask32(0))
     self.skyRay.setRotation(Mat3(1, 0, 0, 0, -1, 0, 0, 0, -1))
     self.space.setCollideId(self.skyRay, GolfGlobals.SKY_RAY_COLLIDE_ID)
     self.rayList.append(self.skyRay)
Esempio n. 8
0
 def createCross2(self, world, space, density, lx, ly, lz, latSlide, colOnlyBall = 0, attachedGeo = None, aHPR = None, aPos = None):
     body = ode.OdeBody(self.world)
     M = ode.OdeMass()
     M.setBox(density, lx, ly, lz)
     body.setMass(M)
     body.setFiniteRotationMode(1)
     boxsize = Vec3(lx, ly * 0.5, lz)
     boxsize2 = Vec3(ly * 0.5, lx, lz)
     geom = ode.OdeBoxGeom(space, boxsize)
     geom.setBody(body)
     geom.setOffsetPosition(-latSlide, ly * 0.25, 0)
     self.space.setSurfaceType(geom, 0)
     self.space.setCollideId(geom, 13)
     geom2 = ode.OdeBoxGeom(space, boxsize2)
     geom2.setBody(body)
     geom2.setOffsetPosition(ly * 0.25, latSlide, 0)
     self.space.setSurfaceType(geom2, 0)
     self.space.setCollideId(geom2, 13)
     geom3 = ode.OdeBoxGeom(space, boxsize)
     geom3.setBody(body)
     geom3.setOffsetPosition(latSlide, -ly * 0.25, 0)
     self.space.setSurfaceType(geom3, 0)
     self.space.setCollideId(geom3, 13)
     geom4 = ode.OdeBoxGeom(space, boxsize2)
     geom4.setBody(body)
     geom4.setOffsetPosition(-ly * 0.25, -latSlide, 0)
     self.space.setSurfaceType(geom4, 0)
     self.space.setCollideId(geom4, 13)
     self.massList.append(M)
     self.geomList.append(geom)
     self.geomList.append(geom2)
     self.geomList.append(geom3)
     self.geomList.append(geom4)
     if colOnlyBall == 1:
         geom.setCollideBits(BitMask32(251658240))
         geom.setCategoryBits(BitMask32(0))
         geom2.setCollideBits(BitMask32(251658240))
         geom2.setCategoryBits(BitMask32(0))
         geom3.setCollideBits(BitMask32(251658240))
         geom3.setCategoryBits(BitMask32(0))
         geom4.setCollideBits(BitMask32(251658240))
         geom4.setCategoryBits(BitMask32(0))
     elif colOnlyBall == 2:
         geom.setCollideBits(BitMask32(0))
         geom.setCategoryBits(BitMask32(0))
         geom2.setCollideBits(BitMask32(0))
         geom2.setCategoryBits(BitMask32(0))
         geom3.setCollideBits(BitMask32(0))
         geom3.setCategoryBits(BitMask32(0))
         geom4.setCollideBits(BitMask32(0))
         geom4.setCategoryBits(BitMask32(0))
     if self.canRender:
         someNodePathGeom = render.attachNewNode('pinwheel')
         if attachedGeo:
             attachedGeo.reparentTo(someNodePathGeom)
             attachedGeo.setHpr(aHPR[0], aHPR[1], aHPR[2])
             attachedGeo.setPos(aPos[0], aPos[1], aPos[2])
         boxNodePathGeom, t1, t2 = BuildGeometry.addBoxGeom(someNodePathGeom, lx, ly * 0.5, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
         boxNodePathGeom.setPos(-latSlide, ly * 0.25, 0)
         boxNodePathGeom2, t1, t2 = BuildGeometry.addBoxGeom(someNodePathGeom, ly * 0.5, lx, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
         boxNodePathGeom2.setPos(ly * 0.25, latSlide, 0)
         boxNodePathGeom3, t1, t2 = BuildGeometry.addBoxGeom(someNodePathGeom, lx, ly * 0.5, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
         boxNodePathGeom3.setPos(latSlide, -ly * 0.25, 0)
         boxNodePathGeom4, t1, t2 = BuildGeometry.addBoxGeom(someNodePathGeom, ly * 0.5, lx, lz, Vec4(1.0, 1.0, 1.0, 1.0), 1)
         boxNodePathGeom4.setPos(-ly * 0.25, -latSlide, 0)
         self.odePandaRelationList.append((someNodePathGeom, body))
     else:
         someNodePathGeom = None
         self.bodyList.append((None, body))
     return (someNodePathGeom, body)