def handleMovement(self, dx, dy): self.__idealYaw, self.__idealPitch = self.__worldYawPitchToTurret(self.__g_curYaw, self.__pitchfilter.value()) newPitch = self.__idealPitch + dy newYaw = self.__idealYaw + dx self.__idealYaw, idealPitch, inLimit, pitchMin, dp = self.__inLimit(self.__idealYaw, newYaw, newPitch) newPitch += dp if not inLimit: d1 = pitchMin - self.__idealPitch d2 = pitchMin - newPitch if math.fabs(d1) >= math.fabs(d2): self.__idealPitch = idealPitch currentGunMat = AimingSystems.getPlayerGunMat(self.__idealYaw, self.__idealPitch) self.__pitchfilter.adjust(currentGunMat.pitch - self.__pitchfilter.value()) else: currentGunMat = AimingSystems.getPlayerGunMat(self.__idealYaw, idealPitch) self.__pitchfilter.reset(currentGunMat.pitch) self.__g_curYaw = currentGunMat.yaw self.__g_curPitch = currentGunMat.pitch self._matrix.set(currentGunMat) self.__oscillator.velocity = Vector3(0.0, 0.0, 0.0) _, uncompensatedPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleTypeDescriptor, BigWorld.player().getOwnVehicleStabilisedMatrix(), self.getDesiredShotPoint()) if inLimit: self.__pitchCompensating = mathUtils.clamp(math.radians(-2.0), math.radians(2.0), idealPitch - uncompensatedPitch) else: self.__pitchCompensating = 0.0
def enable(self, targetPos): player = BigWorld.player() self.__vehicleTypeDescriptor = player.vehicleTypeDescriptor self.__vehicleMProv = player.getOwnVehicleStabilisedMatrix() self.__vehiclePrevMat = Matrix(self.__vehicleMProv) IAimingSystem.enable(self, targetPos) self.__yawLimits = self.__vehicleTypeDescriptor.gun['turretYawLimits'] self.__pitchLimits = self.__vehicleTypeDescriptor.gun['pitchLimits'] self.__idealYaw, self.__idealPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleTypeDescriptor, self.__vehicleMProv, targetPos, True) self.__idealYaw, self.__idealPitch = self.__clampToLimits(self.__idealYaw, self.__idealPitch) currentGunMat = AimingSystems.getPlayerGunMat(self.__idealYaw, self.__idealPitch) self.__g_curYaw = currentGunMat.yaw self.__g_curPitch = (targetPos - currentGunMat.translation).pitch self._matrix.set(currentGunMat) self.__idealYaw, self.__idealPitch = self.__worldYawPitchToTurret(self.__g_curYaw, self.__g_curPitch) self.__idealYaw, self.__idealPitch = self.__clampToLimits(self.__idealYaw, self.__idealPitch) self.__oscillator.reset() self.__pitchfilter.reset(currentGunMat.pitch) SniperAimingSystem.__activeSystem = self vehicle = player.getVehicleAttached() if vehicle is not None: if not vehicle.filter.placingOnGround: vehicle.filter.calcPlacedMatrix(True) self.__baseMatrix = vehicle.filter.placingMatrix else: self.__baseMatrix = vehicle.matrix return
def __update(self): if self.__manualSound is None: return elif not hasattr(BigWorld.player(), 'gunRotator'): return else: p = BigWorld.player().gunRotator if p.maxturretRotationSpeed is not None and p.maxturretRotationSpeed > 0: self.__manualSound.setRTPC('RTPC_ext_turret_speed', p.turretRotationSpeed / p.maxturretRotationSpeed) else: self.__manualSound.setRTPC('RTPC_ext_turret_speed', 0) player = BigWorld.player() vehicleTypeDescriptor = player.vehicleTypeDescriptor gunRotator = player.gunRotator turretYaw = gunRotator.turretYaw desiredShotPoint = gunRotator.predictLockedTargetShotPoint() if desiredShotPoint is None: desiredShotPoint = player.inputHandler.getDesiredShotPoint() if desiredShotPoint is None: desiredShotPoint = gunRotator.markerInfo[0] cameraTurretYaw, _ = AimingSystems.getTurretYawGunPitch(vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), desiredShotPoint, True) angleDiff = abs(turretYaw - cameraTurretYaw) if angleDiff > math.pi: angleDiff = 2 * math.pi - angleDiff self.__manualSound.setRTPC('RTPC_ext_turret_angle', angleDiff) turretPitch = BigWorld.player().gunRotator.gunPitch self.__manualSound.setRTPC('RTPC_ext_turret_pitch', turretPitch) self.__manualSound.setRTPC('RTPC_ext_turret_pitch_speed', abs(self.__oldPitch - turretPitch) / (BigWorld.time() - self.__oldTime)) self.__oldPitch = turretPitch self.__oldTime = BigWorld.time() self.__manualSound.setRTPC('RTPC_ext_turret_damaged', 0 if BigWorld.player().deviceStates.get('turretRotator', None) is None else 1) return self.__updatePeriod
def enable(self, targetPos): player = BigWorld.player() self.__vehicleTypeDescriptor = player.vehicleTypeDescriptor self.__vehicleMProv = player.getOwnVehicleStabilisedMatrix() self.__vehiclePrevMat = Matrix(self.__vehicleMProv) IAimingSystem.enable(self, targetPos) self.__yawLimits = self.__vehicleTypeDescriptor.gun['turretYawLimits'] self.__pitchLimits = self.__vehicleTypeDescriptor.gun['pitchLimits'] self.__idealYaw, self.__idealPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleTypeDescriptor, self.__vehicleMProv, targetPos, True) self.__idealYaw, self.__idealPitch = self.__clampToLimits(self.__idealYaw, self.__idealPitch) currentGunMat = AimingSystems.getPlayerGunMat(self.__idealYaw, self.__idealPitch) self.__g_curYaw = currentGunMat.yaw self.__g_curPitch = (targetPos - currentGunMat.translation).pitch self._matrix.set(currentGunMat) self.__idealYaw, self.__idealPitch = self.__worldYawPitchToTurret(self.__g_curYaw, self.__g_curPitch) self.__idealYaw, self.__idealPitch = self.__clampToLimits(self.__idealYaw, self.__idealPitch) self.__oscillator.reset() self.__pitchfilter.reset(currentGunMat.pitch) SniperAimingSystem.__activeSystem = self vehicle = player.getVehicleAttached() if vehicle is not None: if hasattr(vehicle.filter, 'placingOnGround') and not vehicle.filter.placingOnGround: vehicle.filter.calcPlacedMatrix(True) self.__baseMatrix = vehicle.filter.placingMatrix else: self.__baseMatrix = vehicle.matrix return
def handleMovement(self, dx, dy): self.__idealTurretYaw, self.__idealGunPitch = self.__worldYawPitchToTurret(self.__worldYaw, self.__worldPitch) self.__idealTurretYaw, self.__idealGunPitch = self.__clampToLimits(self.__idealTurretYaw + dx, self.__idealGunPitch + dy) currentGunMat = AimingSystems.getPlayerGunMat(self.__idealTurretYaw, self.__idealGunPitch) self.__worldYaw = currentGunMat.yaw self.__worldPitch = currentGunMat.pitch self._matrix.set(currentGunMat) self.__oscillator.velocity = Vector3(0.0, 0.0, 0.0) _, uncompensatedPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleTypeDescriptor, BigWorld.player().getOwnVehicleMatrix(), self.getDesiredShotPoint()) self.__pitchCompensating = mathUtils.clamp(math.radians(-2.0), math.radians(2.0), self.__idealGunPitch - uncompensatedPitch)
def _getTurretYawGunPitch(self, targetPos, compensateGravity=False): player = BigWorld.player() stabilisedMatrix = Math.Matrix(player.inputHandler.steadyVehicleMatrixCalculator.stabilisedMProv) turretYaw, gunPitch = AimingSystems.getTurretYawGunPitch(self._vehicleTypeDescriptor, stabilisedMatrix, targetPos, compensateGravity) rotation = math_utils.createRotationMatrix((turretYaw, gunPitch, 0.0)) rotation.postMultiply(stabilisedMatrix) invertSteady = Math.Matrix(self._vehicleMProv) invertSteady.invert() rotation.postMultiply(invertSteady) return (rotation.yaw, rotation.pitch)
def __testMouseTargetPoint(self, start, dir): closestPoint, isPointConvenient = self.__calculateClosestPoint(start, dir) turretYaw, gunPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleDesc, self.__vehicleMat, closestPoint, True) if not isPointConvenient: minPitch, maxPitch = gun_rotation_shared.calcPitchLimitsFromDesc(turretYaw, self.__vehicleDesc.gun['pitchLimits']) pitchInBorders = gunPitch <= maxPitch + 0.001 isPointConvenient = not pitchInBorders if isPointConvenient: isPointConvenient = not self.__isTurretTurnRequired(dir, turretYaw, closestPoint) return (closestPoint, isPointConvenient)
def getDesiredShotPoint(self, scanStart, scanDir): scanPos, isPointConvenient = self.__testMouseTargetPoint(scanStart, scanDir) if isPointConvenient: return scanPos planePos = self.__aimPlane.intersectRay(scanStart, scanDir) if scanStart.distSqrTo(planePos) < scanStart.distSqrTo(scanPos): return scanPos turretYaw, gunPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleDesc, self.__vehicleMat, planePos, True) gunMat = AimingSystems.getGunJointMat(self.__vehicleDesc, self.__getTurretMat(turretYaw), gunPitch) aimDir = gunMat.applyVector(Vector3(0.0, 0.0, 1.0)) return AimingSystems.getDesiredShotPoint(gunMat.translation, aimDir)
def __testMouseTargetPoint(self, start, direction): currentFrameStamp = BigWorld.wg_getFrameTimestamp() if self.__cachedResult.frameStamp == currentFrameStamp and self.__cachedResult.scanStart == start and self.__cachedResult.scanDir == direction: return (self.__cachedResult.result, self.__cachedResult.isConvenient) closestPoint, isPointConvenient = self.__calculateClosestPoint(start, direction) turretYaw, gunPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleDesc, self.__vehicleMat, closestPoint, True) if not isPointConvenient: _, maxPitch = gun_rotation_shared.calcPitchLimitsFromDesc(turretYaw, self.__vehicleDesc.gun.pitchLimits) pitchInBorders = gunPitch <= maxPitch + 0.001 isPointConvenient = not pitchInBorders if isPointConvenient: isPointConvenient = not self.__isTurretTurnRequired(direction, turretYaw, closestPoint) self.__cachedResult.update(currentFrameStamp, start, direction, closestPoint, isPointConvenient) return (closestPoint, isPointConvenient)
def enable(self, targetPos): player = BigWorld.player() self.__vehicleTypeDescriptor = player.vehicleTypeDescriptor self.__vehicleMProv = player.getOwnVehicleMatrix() self.__vehiclePrevMat = Matrix(self.__vehicleMProv) IAimingSystem.enable(self, targetPos) self.__yawLimits = self.__vehicleTypeDescriptor.gun['turretYawLimits'] self.__pitchLimits = self.__vehicleTypeDescriptor.gun['pitchLimits'] self.__idealTurretYaw, self.__idealGunPitch = AimingSystems.getTurretYawGunPitch(self.__vehicleTypeDescriptor, player.getOwnVehicleMatrix(), targetPos, True) self.__idealTurretYaw, self.__idealGunPitch = self.__clampToLimits(self.__idealTurretYaw, self.__idealGunPitch) currentGunMat = AimingSystems.getPlayerGunMat(self.__idealTurretYaw, self.__idealGunPitch) self.__worldYaw = currentGunMat.yaw self.__worldPitch = (targetPos - currentGunMat.translation).pitch self._matrix.set(currentGunMat) self.__idealTurretYaw, self.__idealGunPitch = self.__worldYawPitchToTurret(self.__worldYaw, self.__worldPitch) self.__idealTurretYaw, self.__idealGunPitch = self.__clampToLimits(self.__idealTurretYaw, self.__idealGunPitch) self.__oscillator.reset() SniperAimingSystem.__activeSystem = self
def __update(self): player = BigWorld.player() vehicleTypeDescriptor = player.vehicleTypeDescriptor gunRotator = player.gunRotator turretYaw = gunRotator.turretYaw desiredShotPoint = gunRotator.predictLockedTargetShotPoint() if desiredShotPoint is None: desiredShotPoint = player.inputHandler.getDesiredShotPoint() if desiredShotPoint is None: desiredShotPoint = gunRotator.markerInfo[0] cameraTurretYaw, _ = AimingSystems.getTurretYawGunPitch(vehicleTypeDescriptor, player.getOwnVehicleMatrix(), desiredShotPoint, True) angleDiff = abs(turretYaw - cameraTurretYaw) if angleDiff > math.pi: angleDiff = 2 * math.pi - angleDiff rotationSpeed = gunRotator.turretRotationSpeed if rotationSpeed < 0.0001: angleDiff = 0.0 self.__updateSound(angleDiff) return self.__updatePeriod
def __update(self): player = BigWorld.player() vehicleTypeDescriptor = player.vehicleTypeDescriptor gunRotator = player.gunRotator turretYaw = gunRotator.turretYaw desiredShotPoint = gunRotator.predictLockedTargetShotPoint() if desiredShotPoint is None: desiredShotPoint = player.inputHandler.getDesiredShotPoint() if desiredShotPoint is None: desiredShotPoint = gunRotator.markerInfo[0] cameraTurretYaw, _ = AimingSystems.getTurretYawGunPitch(vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), desiredShotPoint, True) angleDiff = abs(turretYaw - cameraTurretYaw) if angleDiff > math.pi: angleDiff = 2 * math.pi - angleDiff rotationSpeed = gunRotator.turretRotationSpeed if rotationSpeed < 0.0001: angleDiff = 0.0 self.__updateSound(angleDiff) return self.__updatePeriod
def __update(self): if self.__soundObject is None: return elif not hasattr(BigWorld.player(), 'gunRotator'): return else: player = BigWorld.player() gunRotator = player.gunRotator speedValue = 0.0 if gunRotator.maxturretRotationSpeed is not None and gunRotator.maxturretRotationSpeed > 0: speedValue = gunRotator.turretRotationSpeed / gunRotator.maxturretRotationSpeed self.__rtpcTurretSpeed.set(self.__soundObject, speedValue) vehicleTypeDescriptor = player.vehicleTypeDescriptor turretYaw = gunRotator.turretYaw desiredShotPoint = gunRotator.predictLockedTargetShotPoint() if desiredShotPoint is None: desiredShotPoint = player.inputHandler.getDesiredShotPoint() if desiredShotPoint is None: desiredShotPoint = gunRotator.markerInfo[0] cameraTurretYaw, _ = AimingSystems.getTurretYawGunPitch( vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), desiredShotPoint, True) turretPitch = player.gunRotator.gunPitch angleDiff = abs(turretYaw - cameraTurretYaw) if angleDiff > math.pi: angleDiff = 2 * math.pi - angleDiff self.__rtpcTurretAngle.set(self.__soundObject, angleDiff) self.__rtpcTurretPitch.set(self.__soundObject, turretPitch) self.__rtpcTurretPitchSpeed.set( self.__soundObject, abs(self.__oldPitch - turretPitch) / (BigWorld.time() - self.__oldTime)) self.__rtpcTurretDamaged.set( self.__soundObject, 0 if player.deviceStates.get('turretRotator', None) is None else 1) self.__oldPitch = turretPitch self.__oldTime = BigWorld.time() return self.__updatePeriod
def Main_update(): if ME_Tank.player is not None and ME_Tank.alive: if config.get('armorPanel/enable', True): try: if eAP.armorCallBack is not None: BigWorld.cancelCallback(eAP.armorCallBack) except Exception: pass player = BigWorld.player() playerVehicle = BigWorld.player().getVehicleAttached() gunRotator = player.gunRotator vehicleTypeDescriptor = player.vehicleTypeDescriptor turretYawRad = gunRotator.turretYaw turretYawDeg = math.degrees(turretYawRad) ME_Tank.turretYawDeg = turretYawDeg # don't need just for debug out ME_Tank.aimMode = player.inputHandler.ctrlModeName if ME_Tank.aimMode == CTRL_MODE_NAME.SNIPER: cameraTurretYawRad = player.inputHandler.ctrl.camera.aimingSystem.turretYaw cameraTurretYawDeg = math.degrees(cameraTurretYawRad) turretPitch = player.gunRotator.gunPitch ME_Tank.cameraTurretYaw = cameraTurretYawDeg # don't need just for debug out elif BigWorld.player().inputHandler.ctrlModeName == CTRL_MODE_NAME.ARCADE: # noinspection PyProtectedMember scanDir, scanStart = AvatarInputHandler.cameras.getWorldRayAndPoint(*BigWorld.player().inputHandler.ctrl._aimOffset) scanStop = scanStart + utills.getNormalisedVector(scanDir).scale(720) cameraTurretYawRad, _ = AimingSystems.getTurretYawGunPitch(vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), scanStop, True) cameraTurretYawDeg = math.degrees(cameraTurretYawRad) turretPitch = Math.Matrix(gunRotator.gunMatrix).pitch ME_Tank.cameraTurretYaw = cameraTurretYawDeg # don't need just for debug out else: desiredShotPoint = gunRotator.predictLockedTargetShotPoint() if desiredShotPoint is None: desiredShotPoint = player.inputHandler.getDesiredShotPoint() if desiredShotPoint is None: desiredShotPoint = gunRotator.markerInfo[0] cameraTurretYawRad, _ = AimingSystems.getTurretYawGunPitch(vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), desiredShotPoint, True) cameraTurretYawDeg = math.degrees(cameraTurretYawRad) turretPitch = Math.Matrix(gunRotator.gunMatrix).pitch vehicleMP = Math.Matrix(player.getOwnVehicleMatrix()) tankYawDeg = math.degrees(Math.Matrix(vehicleMP).yaw) arc = eAP.getDynamicArc(playerVehicle, vehicleTypeDescriptor, vehicleMP, turretYawRad, cameraTurretYawRad, turretPitch) ME_Tank.effFrontArmor = eAP.getEquArmor(ME_Tank.front, turretYawDeg, cameraTurretYawDeg, arc) ME_Tank.effSideArmor = eAP.getEquArmor(ME_Tank.side, (90 - math.fabs(turretYawDeg)), (90 - math.fabs(cameraTurretYawDeg)), 0) if ME_Tank.tankType != "SPG": eAP.updateEffArmor(ME_Tank.effFrontArmor, turretYawDeg, cameraTurretYawDeg) AnglePanel.updateProtractor(turretYawDeg, cameraTurretYawDeg, int(ME_Tank.leftArc), int(ME_Tank.rightArc)) else: AnglePanel.setArtyProtractor(turretYawDeg, int(ME_Tank.leftArc), int(ME_Tank.rightArc), tankYawDeg, ME_Tank.aimMode) as_event('ON_ARMOR') eAP.armorCallBack = BigWorld.callback(eAP.tickRate, Main_update) # 0.033 = 30hz 0.01667 = 60hz else: try: if eAP.armorCallBack is not None: BigWorld.cancelCallback(eAP.armorCallBack) except Exception: pass
def Main_update(): if ME_Tank.player is not None and ME_Tank.alive: if config.get('armorPanel/enable', True): try: if eAP.armorCallBack is not None: BigWorld.cancelCallback(eAP.armorCallBack) except Exception: pass player = BigWorld.player() playerVehicle = BigWorld.player().getVehicleAttached() gunRotator = player.gunRotator vehicleTypeDescriptor = player.vehicleTypeDescriptor turretYawRad = gunRotator.turretYaw turretYawDeg = math.degrees(turretYawRad) ME_Tank.turretYawDeg = turretYawDeg # don't need just for debug out ME_Tank.aimMode = player.inputHandler.ctrlModeName if ME_Tank.aimMode == CTRL_MODE_NAME.SNIPER: cameraTurretYawRad = player.inputHandler.ctrl.camera.aimingSystem.turretYaw cameraTurretYawDeg = math.degrees(cameraTurretYawRad) turretPitch = player.gunRotator.gunPitch ME_Tank.cameraTurretYaw = cameraTurretYawDeg # don't need just for debug out elif BigWorld.player( ).inputHandler.ctrlModeName == CTRL_MODE_NAME.ARCADE: # noinspection PyProtectedMember scanDir, scanStart = AvatarInputHandler.cameras.getWorldRayAndPoint( *BigWorld.player().inputHandler.ctrl._aimOffset) scanStop = scanStart + utills.getNormalisedVector( scanDir).scale(720) cameraTurretYawRad, _ = AimingSystems.getTurretYawGunPitch( vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), scanStop, True) cameraTurretYawDeg = math.degrees(cameraTurretYawRad) turretPitch = Math.Matrix(gunRotator.gunMatrix).pitch ME_Tank.cameraTurretYaw = cameraTurretYawDeg # don't need just for debug out else: desiredShotPoint = gunRotator.predictLockedTargetShotPoint() if desiredShotPoint is None: desiredShotPoint = player.inputHandler.getDesiredShotPoint( ) if desiredShotPoint is None: desiredShotPoint = gunRotator.markerInfo[0] cameraTurretYawRad, _ = AimingSystems.getTurretYawGunPitch( vehicleTypeDescriptor, player.getOwnVehicleStabilisedMatrix(), desiredShotPoint, True) cameraTurretYawDeg = math.degrees(cameraTurretYawRad) turretPitch = Math.Matrix(gunRotator.gunMatrix).pitch vehicleMP = Math.Matrix(player.getOwnVehicleMatrix()) tankYawDeg = math.degrees(Math.Matrix(vehicleMP).yaw) arc = eAP.getDynamicArc(playerVehicle, vehicleTypeDescriptor, vehicleMP, turretYawRad, cameraTurretYawRad, turretPitch) ME_Tank.effFrontArmor = eAP.getEquArmor(ME_Tank.front, turretYawDeg, cameraTurretYawDeg, arc) ME_Tank.effSideArmor = eAP.getEquArmor( ME_Tank.side, (90 - math.fabs(turretYawDeg)), (90 - math.fabs(cameraTurretYawDeg)), 0) if ME_Tank.tankType != "SPG": eAP.updateEffArmor(ME_Tank.effFrontArmor, turretYawDeg, cameraTurretYawDeg) AnglePanel.updateProtractor(turretYawDeg, cameraTurretYawDeg, int(ME_Tank.leftArc), int(ME_Tank.rightArc)) else: AnglePanel.setArtyProtractor(turretYawDeg, int(ME_Tank.leftArc), int(ME_Tank.rightArc), tankYawDeg, ME_Tank.aimMode) as_event('ON_ARMOR') eAP.armorCallBack = BigWorld.callback( eAP.tickRate, Main_update) # 0.033 = 30hz 0.01667 = 60hz else: try: if eAP.armorCallBack is not None: BigWorld.cancelCallback(eAP.armorCallBack) except Exception: pass