Esempio n. 1
0
    def criaPopulacao(self):

        vPos = 0

        for n in range(0, self.POPULACAO_TREINAMENTO):
            indiv = Individuo()

            # TRONCO
            shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

            tronco = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
            tronco.node().setMass(1.0)
            tronco.node().addShape(shape)
            tronco.setPos(vPos + 2, 0.5, 3)
            tronco.setScale(2, 0.6, 4)
            tronco.setCollideMask(BitMask32.allOn())
            #self.boxNP.node().setDeactivationEnabled(False)
            indiv.tronco = tronco

            self.world.attachRigidBody(tronco.node())

            visualNP = loader.loadModel('models/box.egg')
            visualNP.clearModelNodes()
            visualNP.reparentTo(tronco)
            frameA = TransformState.makePosHpr(Point3(0, 0, -2),
                                               Vec3(0, 0, 90))

            # PÉS
            shape = BulletBoxShape(Vec3(0.5, 1, 0.2))
            posicaoPes = [1, 2]
            for i in range(2):
                for j in range(1):
                    x = i + posicaoPes[i] + vPos
                    y = 0.0
                    z = j
                    pe = self.criaPe(shape, x, y, z)

                    if i == 1:
                        indiv.pe1 = pe
                    else:
                        indiv.pe2 = pe

                    # Cone
                    # frameB = TransformState.makePosHpr(Point3(-5, 0, 0), Vec3(0, 0, 0))

                    # cone = BulletConeTwistConstraint(tronco, pe, frameA, frameB)
                    # cone.setDebugDrawSize(2.0)
                    # cone.setLimit(30, 45, 170, softness=1.0, bias=0.3, relaxation=8.0)
                    # self.world.attachConstraint(cone)

            self.individuos.append(indiv)

            vPos = vPos + 4