def loadTrainTrack(self, x1, y1, x2, y2, zAdj=0):
        turnTable = loader.loadModel(
            'phase_4/models/minigames/trolley_game_turntable')
        trainPart = turnTable.find('**/track_a2')
        trackHeight = 0.03
        trainTrack = render.attachNewNode('trainTrack%d%d%d%d' %
                                          (x1, y1, x2, y2))
        trainTrack.setPos(x1, y1, trackHeight)
        xDiff = abs(x2 - x1)
        yDiff = abs(y2 - y1)
        angleInRadians = math.atan((float(y2) - y1) / (x2 - x1))
        angle = rad2Deg(angleInRadians)
        desiredLength = math.sqrt(xDiff * xDiff + yDiff * yDiff)
        lengthToGo = desiredLength
        partIndex = 0
        lengthCovered = 0
        while lengthToGo > self.fullLength / 2.0:
            onePart = trainPart.copyTo(trainTrack)
            onePart.setX(lengthCovered)
            lengthToGo -= self.fullLength
            lengthCovered += self.fullLength

        trainTrack.setH(angle)
        newX = x1 + (x2 - x1) / 2.0
        newY = y1 + (y2 - y1) / 2.0
        trainTrack.setPos(x1, y1, trackHeight + zAdj)
        turnTable.removeNode()
        return trainTrack
Ejemplo n.º 2
0
    def commonMove(self):
        if not self.lastThinkTime:
            self.lastThinkTime = globalClock.getFrameTime()

        dt = globalClock.getFrameTime() - self.lastThinkTime
        self.oldpos = self.suit.getPos()
        pos = self.suit.getPos()
        pos += self.velocity * dt
        self.suit.setPos(pos)
        self.seeFriends()
        acc = Vec3(0, 0, 0)
        self.accumulate(acc, self.getTargetVector())
        if self.numFlockmatesSeen > 0:
            keepDistanceVector = self.keepDistance()
            oldAcc = Vec3(acc)
            self.accumulate(acc, keepDistanceVector)
            if self.cogIndex == 0:
                pass

        if acc.length() > self.maxAcceleration:
            acc.normalize()
            acc *= self.maxAcceleration

        self.oldVelocity = self.velocity
        self.velocity += acc
        if self.velocity.length() > self.maxVelocity:
            self.velocity.normalize()
            self.velocity *= self.maxVelocity

        forwardVec = Vec3(1, 0, 0)
        heading = rad2Deg(math.atan2(self.velocity[1], self.velocity[0]))
        heading -= 90
        self.suit.setH(heading)
Ejemplo n.º 3
0
 def commonMove(self):
     if not self.lastThinkTime:
         self.lastThinkTime = globalClock.getFrameTime()
     
     dt = globalClock.getFrameTime() - self.lastThinkTime
     self.oldpos = self.suit.getPos()
     pos = self.suit.getPos()
     pos += self.velocity * dt
     self.suit.setPos(pos)
     self.seeFriends()
     acc = Vec3(0, 0, 0)
     self.accumulate(acc, self.getTargetVector())
     if self.numFlockmatesSeen > 0:
         keepDistanceVector = self.keepDistance()
         oldAcc = Vec3(acc)
         self.accumulate(acc, keepDistanceVector)
         if self.cogIndex == 0:
             pass
         
     
     if acc.length() > self.maxAcceleration:
         acc.normalize()
         acc *= self.maxAcceleration
     
     self.oldVelocity = self.velocity
     self.velocity += acc
     if self.velocity.length() > self.maxVelocity:
         self.velocity.normalize()
         self.velocity *= self.maxVelocity
     
     forwardVec = Vec3(1, 0, 0)
     heading = rad2Deg(math.atan2(self.velocity[1], self.velocity[0]))
     heading -= 90
     self.suit.setH(heading)
 def loadTrainTrack(self, x1, y1, x2, y2, zAdj = 0):
     turnTable = loader.loadModel('phase_4/models/minigames/trolley_game_turntable')
     trainPart = turnTable.find('**/track_a2')
     trackHeight = 0.029999999999999999
     trainTrack = render.attachNewNode('trainTrack%d%d%d%d' % (x1, y1, x2, y2))
     trainTrack.setPos(x1, y1, trackHeight)
     xDiff = abs(x2 - x1)
     yDiff = abs(y2 - y1)
     angleInRadians = math.atan((float(y2) - y1) / (x2 - x1))
     angle = rad2Deg(angleInRadians)
     desiredLength = math.sqrt(xDiff * xDiff + yDiff * yDiff)
     lengthToGo = desiredLength
     partIndex = 0
     lengthCovered = 0
     while lengthToGo > self.fullLength / 2.0:
         onePart = trainPart.copyTo(trainTrack)
         onePart.setX(lengthCovered)
         lengthToGo -= self.fullLength
         lengthCovered += self.fullLength
     trainTrack.setH(angle)
     newX = x1 + (x2 - x1) / 2.0
     newY = y1 + (y2 - y1) / 2.0
     trainTrack.setPos(x1, y1, trackHeight + zAdj)
     turnTable.removeNode()
     return trainTrack
Ejemplo n.º 5
0
    def commonMove(self):
        """Move the cog thief. Common for all 3 behaviors """
        if not self.lastThinkTime:
            self.lastThinkTime = globalClock.getFrameTime()
        dt = globalClock.getFrameTime() - self.lastThinkTime

        # Step 1:  Update our position.
        # Update our position based on the velocity
        # vector we computed last time around.

        self.oldpos = self.suit.getPos()
        # save off our previous position

        pos = self.suit.getPos()
        pos += self.velocity * dt
        # apply velocities.
        self.suit.setPos(pos)

        # Step 2:  SeeFriends.
        # Determine if we can see any of our flockmates.

        self.seeFriends()

        acc = Vec3(0, 0, 0)

        # well first off we want to move to our target
        self.accumulate(acc, self.getTargetVector())

        # Step 3:  Flocking behavior.
        # Do we see any of our flockmates?  If yes, it's time to implement
        # the first Three Rules (they don't matter if we can't see anybody)

        if self.numFlockmatesSeen > 0:
            #if hasattr(base,'doDebug') and base.doDebug:
            #    import pdb; pdb.set_trace()
            keepDistanceVector = self.keepDistance()
            oldAcc = Vec3(acc)
            self.accumulate(acc, keepDistanceVector)
            if self.cogIndex == 0:
                #self.notify.debug('oldAcc=%s, keepDist=%s newAcc=%s' %
                #                  (oldAcc,keepDistanceVector, acc))
                pass

        # Step 8:  Constrain acceleration
        # If our acceleration change is more than we allow, constrain it

        if (acc.length() > self.maxAcceleration):
            # definitely too much...constrain to maximum change
            acc.normalize()
            acc *= self.maxAcceleration

        # Step 9:  Implementation.
        # Here's where we apply our newly computed acceleration vector
        # to create a new velocity vector to use next update cycle.

        self.oldVelocity = self.velocity
        # save off our previous velocity

        # now add in the acceleration

        self.velocity += acc

        # Step 10:  constraint Y velocity changes.
        # Attempt to restrict flight straight up/down by damping out Y axis velocity.
        # This isn't strictly necessary, but does lead to more realistic looking flight.

        # Step 11:  Constrain our speed.
        # If we're moving faster than we're allowed to move, constrain our velocity.
        if self.velocity.length() > self.maxVelocity:
            self.velocity.normalize()
            self.velocity *= self.maxVelocity

        # Step 12:  Compute roll/pitch/yaw.
        # Compute our orientation after all this speed adjustment nonsense.
        # bah no need, we turn on a dime towards our velocity
        forwardVec = Vec3(1, 0, 0)
        heading = rad2Deg(math.atan2(self.velocity[1], self.velocity[0]))
        heading -= 90
        self.suit.setH(heading)