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))
Exemple #2
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
Exemple #3
0
 def process(self, dt):
     CImpulse.process(self, dt)
     me = self.nodePath
     target = self.target
     targetPos = target.getPos(me)
     x = targetPos[0]
     y = targetPos[1]
     distance = math.sqrt(x * x + y * y)
     self.lookAtNode.lookAt(target)
     relH = reduceAngle(self.lookAtNode.getH(me))
     epsilon = 0.005
     rotSpeed = self.mover.getRotSpeed()
     if relH < -epsilon:
         vH = -rotSpeed
     elif relH > epsilon:
         vH = rotSpeed
     else:
         vH = 0
     if abs(vH * dt) > abs(relH):
         vH = relH / dt
     if distance > self.minDist and abs(relH) < self.moveAngle:
         vForward = self.mover.getFwdSpeed()
     else:
         vForward = 0
     distanceLeft = distance - self.minDist
     if distance > self.minDist and vForward * dt > distanceLeft:
         vForward = distanceLeft / dt
     if vForward:
         self.vel.setY(vForward)
         self.mover.addShove(self.vel)
     if vH:
         self.rotVel.setX(vH)
         self.mover.addRotShove(self.rotVel)
 def _process(self, dt):
     Impulse.Impulse._process(self, dt)
     me = self.nodePath
     chaser = self.chaser
     chaserPos = chaser.getPos(me)
     chaserPos.setZ(0)
     distance = self.VecType(chaserPos).length()
     self.lookAtNode.lookAt(chaser)
     relH = reduceAngle(self.lookAtNode.getH(me) + 180.0)
     epsilon = 0.005
     rotSpeed = self.mover.getRotSpeed()
     if relH < -epsilon:
         vH = -rotSpeed
     elif relH > epsilon:
         vH = rotSpeed
     else:
         vH = 0
     if abs(vH * dt) > abs(relH):
         vH = relH / dt
     if distance < self.maxDist and abs(relH) < self.moveAngle:
         vForward = self.mover.getFwdSpeed()
     else:
         vForward = 0
     distanceLeft = self.maxDist - distance
     if 0.0 < distanceLeft < vForward * dt:
         vForward = distanceLeft / dt
     self.vel.setY(vForward)
     self.rotVel.setX(vH)
     self.mover.addShove(self.vel)
     self.mover.addRotShove(self.rotVel)
Exemple #5
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
Exemple #6
0
 def process(self, dt):
     CImpulse.CImpulse.process(self, dt)
     me = self.nodePath
     chaser = self.chaser
     chaserPos = chaser.getPos(me)
     chaserPos.setZ(0)
     distance = self.VecType(chaserPos).length()
     self.lookAtNode.lookAt(chaser)
     relH = reduceAngle(self.lookAtNode.getH(me) + 180.0)
     epsilon = 0.005
     rotSpeed = self.mover.getRotSpeed()
     if relH < -epsilon:
         vH = -rotSpeed
     elif relH > epsilon:
         vH = rotSpeed
     else:
         vH = 0
     if abs(vH * dt) > abs(relH):
         vH = relH / dt
     if distance < self.maxDist and abs(relH) < self.moveAngle:
         vForward = self.mover.getFwdSpeed()
     else:
         vForward = 0
     distanceLeft = self.maxDist - distance
     if distanceLeft > 0.0 and vForward * dt > distanceLeft:
         vForward = distanceLeft / dt
     self.vel.setY(vForward)
     self.rotVel.setX(vH)
     self.mover.addShove(self.vel)
     self.mover.addRotShove(self.rotVel)
 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
Exemple #8
0
 def _process(self, dt):
     Impulse.Impulse._process(self, dt)
     me = self.nodePath
     target = self.target
     targetPos = target.getPos(me)
     x = targetPos[0]
     y = targetPos[1]
     distance = math.sqrt(x * x + y * y)
     self.lookAtNode.lookAt(target)
     relH = reduceAngle(self.lookAtNode.getH(me))
     epsilon = 0.005
     rotSpeed = self.mover.getRotSpeed()
     if relH < -epsilon:
         vH = -rotSpeed
     elif relH > epsilon:
         vH = rotSpeed
     else:
         vH = 0
     if abs(vH * dt) > abs(relH):
         vH = relH / dt
     if distance > self.minDist and abs(relH) < self.moveAngle:
         vForward = self.mover.getFwdSpeed()
     else:
         vForward = 0
     distanceLeft = distance - self.minDist
     if distance > self.minDist and vForward * dt > distanceLeft:
         vForward = distanceLeft / dt
     if vForward:
         self.vel.setY(vForward)
         self.mover.addShove(self.vel)
     if vH:
         self.rotVel.setX(vH)
         self.mover.addRotShove(self.rotVel)
Exemple #9
0
    def _process(self, dt):
        Impulse.Impulse._process(self, dt)
        me = self.nodePath
        target = self.target

        targetPos = target.getPos(me)
        # work in 2d
        #targetPos.setZ(0)
        #distance = self.VecType(targetPos).length()
        x = targetPos[0]
        y = targetPos[1]
        distance = math.sqrt((x*x) + (y*y))
        self.lookAtNode.lookAt(target)
        relH = reduceAngle(self.lookAtNode.getH(me))

        # turn towards target
        epsilon = .005
        rotSpeed = self.mover.getRotSpeed()
        if relH < -epsilon:
            vH = -rotSpeed
        elif relH > epsilon:
            vH = rotSpeed
        else:
            vH = 0

        # don't oversteer
        if abs(vH*dt) > abs(relH):
            vH = relH / dt

        if (distance > self.minDist) and (abs(relH) < self.moveAngle):
            vForward = self.mover.getFwdSpeed()
        else:
            vForward = 0

        # don't get too close
        distanceLeft = distance - self.minDist
        if (distance > self.minDist) and ((vForward*dt) > distanceLeft):
            vForward = distanceLeft / dt

        if vForward:
            self.vel.setY(vForward)
            self.mover.addShove(self.vel)
        if vH:
            self.rotVel.setX(vH)
            self.mover.addRotShove(self.rotVel)
Exemple #10
0
    def _process(self, dt):
        Impulse.Impulse._process(self, dt)
        me = self.nodePath
        chaser = self.chaser

        chaserPos = chaser.getPos(me)
        # work in 2d
        chaserPos.setZ(0)
        distance = self.VecType(chaserPos).length()
        self.lookAtNode.lookAt(chaser)
        # run away from chaser
        relH = reduceAngle(self.lookAtNode.getH(me) + 180.)

        # turn away from chaser
        epsilon = .005
        rotSpeed = self.mover.getRotSpeed()
        if relH < -epsilon:
            vH = -rotSpeed
        elif relH > epsilon:
            vH = rotSpeed
        else:
            vH = 0

        # don't oversteer
        if abs(vH * dt) > abs(relH):
            vH = relH / dt

        if (distance < self.maxDist) and (abs(relH) < self.moveAngle):
            vForward = self.mover.getFwdSpeed()
        else:
            vForward = 0

        # don't get too far away
        distanceLeft = self.maxDist - distance
        if (distanceLeft > 0.) and ((vForward * dt) > distanceLeft):
            vForward = distanceLeft / dt

        self.vel.setY(vForward)
        self.rotVel.setX(vH)

        self.mover.addShove(self.vel)
        self.mover.addRotShove(self.rotVel)