Esempio n. 1
0
    def _update(self):
        dt=globalClock.getDt()
        move_speed=dt*self.move_speed
        origHpr = self.vis_node.get_hpr()
        newHpr=origHpr
        self.vis_node.look_at(self.node)
        targetHpr = self.vis_node.get_hpr()
        origHpr = Vec3(fitSrcAngle2Dest(origHpr[0], targetHpr[0]),
                         fitSrcAngle2Dest(origHpr[1], targetHpr[1]),
                         fitSrcAngle2Dest(origHpr[2], targetHpr[2]))
        delta = max(abs(targetHpr[0] - origHpr[0]),
                    abs(targetHpr[1] - origHpr[1]),
                    abs(targetHpr[2] - origHpr[2]))
        if delta != 0:
            t = min(dt * self.turn_speed/delta, 1.0)
            newHpr = origHpr + (targetHpr - origHpr) * t
        self.vis_node.set_hpr(newHpr)

        pad=0.0
        if self.seq.isPlaying():
            pad=self.min_distance
        dist=self.vis_node.get_distance(self.node)

        if dist > move_speed +pad:
            move_speed*= dist/2.0
            self.vis_node.set_y(self.vis_node,move_speed)
 def __stickTask(self, task):
     tElapsed = globalClock.getFrameTime() - self.tContact
     if tElapsed > self.tStick:
         lToon = base.localAvatar
         self.isLocalToon = 1
         crateNormal = task.crateNormal
         crateWidth = 2.75 * self.scale
         offset = crateWidth + 1.5 + TorsoToOffset[lToon.style.torso]
         newPos = crateNormal * offset
         if self.avPushTrack:
             self.avPushTrack.pause()
         place = base.cr.playGame.getPlace()
         newHpr = CrateHprs[self.crateSide]
         h = lToon.getH(self)
         h = fitSrcAngle2Dest(h, newHpr[0])
         startHpr = Vec3(h, 0, 0)
         self.avPushTrack = Sequence(
             LerpPosHprInterval(lToon, 0.25, newPos, newHpr, startHpr=startHpr, other=self, blendType="easeInOut"),
             Func(place.fsm.request, "push"),
             Func(self.__sendPushRequest, task.crateNormal),
             SoundInterval(self.creakSound, node=self),
         )
         self.avPushTrack.start()
         return Task.done
     else:
         pos = task.toonPos
         base.localAvatar.setPos(task.toonPos)
         return Task.cont
Esempio n. 3
0
    def _updateTask(self, task=None):
        self.setFluidPos(render, self.lookAtNode.getPos(render))
        curSubjectH = self.subject.getH(render)
        if self._lockAtRear:
            self.setRotation(0.0)
        elif self._rotateToRearEnabled and self.getAutoFaceForward():
            relH = reduceAngle(self.getH(self.subject))
            absRelH = abs(relH)
            if absRelH < 0.10000000000000001:
                self.setRotation(0.0)
                self._stopRotateToRearIval()
                self._lockAtRear = True
            else:
                ivalPlaying = self._rotateToRearIvalIsPlaying()
                if ivalPlaying and curSubjectH == self.lastSubjectH:
                    pass
                else:
                    self._stopRotateToRearIval()
                    duration = self._autoFaceForwardMaxDur * absRelH / 180.0
                    targetH = curSubjectH
                    startH = fitSrcAngle2Dest(self.getH(render), targetH)
                    self._rotateToRearIval = LerpHprInterval(
                        self,
                        duration,
                        Point3(targetH, 0, 0),
                        startHpr=Point3(startH, 0, 0),
                        other=render,
                        blendType='easeOut')
                    self._rotateToRearIval.start()

        self.lastSubjectH = curSubjectH
        self.setP(0)
        self.setR(0)
        camera.clearMat()
        return Task.cont
Esempio n. 4
0
 def __stickTask(self, task):
     tElapsed = globalClock.getFrameTime() - self.tContact
     if tElapsed > self.tStick:
         lToon = base.localAvatar
         self.isLocalToon = 1
         crateNormal = task.crateNormal
         crateWidth = 2.75 * self.scale
         offset = crateWidth + 1.5 + TorsoToOffset[lToon.style.torso]
         newPos = crateNormal * offset
         if self.avPushTrack:
             self.avPushTrack.pause()
         place = base.cr.playGame.getPlace()
         newHpr = CrateHprs[self.crateSide]
         h = lToon.getH(self)
         h = fitSrcAngle2Dest(h, newHpr[0])
         startHpr = Vec3(h, 0, 0)
         self.avPushTrack = Sequence(
             LerpPosHprInterval(lToon,
                                0.25,
                                newPos,
                                newHpr,
                                startHpr=startHpr,
                                other=self,
                                blendType='easeInOut'),
             Func(place.fsm.request, 'push'),
             Func(self.__sendPushRequest, task.crateNormal),
             SoundInterval(self.creakSound, node=self))
         self.avPushTrack.start()
         return Task.done
     else:
         pos = task.toonPos
         base.localAvatar.setPos(task.toonPos)
         return Task.cont
 def _updateTask(self, task = None):
     self.setFluidPos(render, self.lookAtNode.getPos(render))
     curSubjectH = self.subject.getH(render)
     if self._lockAtRear:
         self.setRotation(0.0)
     elif self._rotateToRearEnabled and self.getAutoFaceForward():
         relH = reduceAngle(self.getH(self.subject))
         absRelH = abs(relH)
         if absRelH < 0.10000000000000001:
             self.setRotation(0.0)
             self._stopRotateToRearIval()
             self._lockAtRear = True
         else:
             ivalPlaying = self._rotateToRearIvalIsPlaying()
             if ivalPlaying and curSubjectH == self.lastSubjectH:
                 pass
             else:
                 self._stopRotateToRearIval()
                 duration = self._autoFaceForwardMaxDur * absRelH / 180.0
                 targetH = curSubjectH
                 startH = fitSrcAngle2Dest(self.getH(render), targetH)
                 self._rotateToRearIval = LerpHprInterval(self, duration, Point3(targetH, 0, 0), startHpr = Point3(startH, 0, 0), other = render, blendType = 'easeOut')
                 self._rotateToRearIval.start()
     
     self.lastSubjectH = curSubjectH
     self.setP(0)
     self.setR(0)
     camera.clearMat()
     return Task.cont
Esempio n. 6
0
 def _checkHBounds(self, hNode):
     currH = fitSrcAngle2Dest(hNode.getH(), 180)
     if currH < self.minH:
         hNode.setH(reduceAngle(self.minH))
     else:
         if currH > self.maxH:
             hNode.setH(reduceAngle(self.maxH))
Esempio n. 7
0
 def orientToon(angle, self = self):
     startAngle = self.lt.getH()
     startAngle = fitSrcAngle2Dest(startAngle, angle)
     dur = 0.1 * abs(startAngle - angle) / 90
     self.turnLocalToonIval = LerpHprInterval(self.lt, dur, Point3(angle, 0, 0), startHpr=Point3(startAngle, 0, 0), name='TwoDDriveLerpHpr')
     self.turnLocalToonIval.start()
     if self.atRestHeading != self.oldAtRestHeading:
         self.oldAtRestHeading = self.atRestHeading
         messenger.send('avatarOrientationChanged', [self.atRestHeading])
 def orientToon(angle, self = self):
     startAngle = self.lt.getH()
     startAngle = fitSrcAngle2Dest(startAngle, angle)
     dur = 0.1 * abs(startAngle - angle) / 90
     self.turnLocalToonIval = LerpHprInterval(self.lt, dur, Point3(angle, 0, 0), startHpr=Point3(startAngle, 0, 0), name='OrthoDriveLerpHpr')
     if self.instantTurn:
         self.turnLocalToonIval.finish()
     else:
         self.turnLocalToonIval.start()
Esempio n. 9
0
 def _updateTask(self, task=None):
     if not base.shipLookAhead:
         return OrbitCamera._updateTask(self, task)
     self.setFluidPos(render, self.lookAtNode.getPos(render))
     if self.lastHeading == None:
         self.lastHeading = reduceAngle(self.subject.getH())
     fittedAngle = fitSrcAngle2Dest(self.subject.getH(), self.lastHeading)
     headingDif = fittedAngle - self.lastHeading
     self.lastHeading = self.subject.getH()
     if self.lastFrameTime != None:
         lastFrameTime = self.lastFrameTime
         newFrameTime = globalClock.getFrameTime()
         timeDelta = min(self.smoothSecs, newFrameTime - lastFrameTime)
         self.lastFrameTime = newFrameTime
     else:
         self.lastFrameTime = globalClock.getFrameTime()
         timeDelta = 0.0
     if self._rotateToRearEnabled:
         if self.getAutoFaceForward() and self.camTimer < 0.0:
             self.camTimer = 0.0
         if self.camTimer >= 0.0:
             self.camTimer = min(
                 timeDelta * self.recoverySpeed + self.camTimer, 1.0)
             camTimer = max(0, self.camTimer)
         self.smoothProjectedTarget = (self.mouseControl
                                       or self.camTimer < 0) and self.getH(
                                           self.subject)
     else:
         if timeDelta == 0.0:
             headingVelocity = 0.0
         else:
             headingVelocity = headingDif / timeDelta
         projectedTarget = headingVelocity
         if self.shipSpeed < 0.0:
             projectedTarget = -1.0 * projectedTarget
         if projectedTarget < 0:
             projectedTarget = -3.5 * math.pow(abs(projectedTarget), 0.6)
         else:
             projectedTarget = 3.5 * math.pow(abs(projectedTarget), 0.6)
         readjustSpeed = 1.0
         if abs(headingVelocity) < 1.0:
             readjustSpeed = 0.5
         readjustTime = self.smoothSecs * readjustSpeed
         self.smoothProjectedTarget = (
             self.smoothProjectedTarget *
             (readjustTime - timeDelta * self.camTimer) + projectedTarget *
             (timeDelta * self.camTimer)) / readjustTime
         curSubjectH = self.subject.getH(render)
         relH = reduceAngle(self.getH(self.subject))
         self.setRotation(self.smoothProjectedTarget)
         self.setP(0)
         self.setR(0)
         camera.clearMat()
     return Task.cont
 def orientToon(angle, self=self):
     startAngle = self.lt.getH()
     startAngle = fitSrcAngle2Dest(startAngle, angle)
     dur = 0.1 * abs(startAngle - angle) / 90
     self.turnLocalToonIval = LerpHprInterval(self.lt,
                                              dur,
                                              Point3(angle, 0, 0),
                                              startHpr=Point3(
                                                  startAngle, 0, 0),
                                              name='OrthoDriveLerpHpr')
     if self.instantTurn:
         self.turnLocalToonIval.finish()
     else:
         self.turnLocalToonIval.start()
Esempio n. 11
0
    def __stickTask(self, task):
        tElapsed = globalClock.getFrameTime() - self.tContact
        if tElapsed > self.tStick:
            # The toon is definitely trying to push this block.
            # Tell the AI.
            lToon = base.localAvatar
            self.isLocalToon = 1

            # Set toons pos/hpr relative to crate
            crateNormal = task.crateNormal
            crateWidth = 2.75 * self.scale
            offset = crateWidth + 1.5 + TorsoToOffset[lToon.style.torso]
            newPos = crateNormal * offset

            if self.avPushTrack:
                self.avPushTrack.pause()
            place = base.cr.playGame.getPlace()
            newHpr = CrateHprs[self.crateSide]

            # figure out what heading the toon should start from, to avoid
            # spinning
            h = lToon.getH(self)
            h = fitSrcAngle2Dest(h, newHpr[0])
            startHpr = Vec3(h, 0, 0)

            # put toon perpendicular to crate
            self.avPushTrack = Sequence(
                LerpPosHprInterval(lToon,
                                   .25,
                                   newPos,
                                   newHpr,
                                   startHpr=startHpr,
                                   other=self,
                                   blendType='easeInOut'),
                Func(place.fsm.request, 'push'),
                Func(self.__sendPushRequest, task.crateNormal),
                SoundInterval(self.creakSound, node=self))

            self.avPushTrack.start()
            return Task.done
        else:
            # zero out the tangential velocity so the toon
            # doesn't slide off the crate
            pos = task.toonPos
            base.localAvatar.setPos(task.toonPos)
            return Task.cont
Esempio n. 12
0
    def follow(self, target, dt, speed):
        self.cam_node.setPos(target.getPos(render))
        orig_H = self.cam_node.getH(render)
        target_H = target.getH(render)
        # Make the rotation go the shortest way around.
        orig_H = fitSrcAngle2Dest(orig_H, target_H)

        # How far do we have to go from here?
        delta = abs(target_H - orig_H)
        if delta == 0:
            # We're already looking at the target.
            return
        # Figure out how far we should rotate in this frame, based on the
        # distance to go, and the speed we should move each frame.
        t = dt * delta * speed
        # If we reach the target, stop there.
        t = min(t, 1.0)
        new_H = orig_H + (target_H - orig_H) * t
        self.cam_node.setH(new_H)
Esempio n. 13
0
    def follow(self, target, dt, speed):
        self.cam_node.setPos(target.getPos(render))        
        orig_H = self.cam_node.getH(render)
        target_H = target.getH(render)
        # Make the rotation go the shortest way around.
        orig_H = fitSrcAngle2Dest(orig_H, target_H)

        # How far do we have to go from here?
        delta = abs(target_H - orig_H)
        if delta == 0:
            # We're already looking at the target.
            return
        # Figure out how far we should rotate in this frame, based on the
        # distance to go, and the speed we should move each frame.
        t = dt * delta *speed
        # If we reach the target, stop there.
        t = min(t, 1.0)
        new_H = orig_H + (target_H - orig_H) * t
        self.cam_node.setH(new_H)