def __updateVisibleAxis(self): if not self._notControlledByUser and EntityStates.inState(BigWorld.player(), EntityStates.GAME): player = BigWorld.player() fmRotation = BigWorld.player().getRotation() norm = Math.Vector3(self.__camDirection) norm.normalise() yawAngle = 0.5 * math.pi - math.acos(clamp(-1.0, fmRotation.getAxisX().dot(norm), 1.0)) pitchAngle = 0.5 * math.pi - math.acos(clamp(-1.0, fmRotation.getAxisY().dot(norm), 1.0)) mouseRoll = -sign(yawAngle) * clamp(-1.0, max(0.0, abs(yawAngle) / math.radians(5.0) - 1.0), 1.0) hAxis = clamp(-1.0, yawAngle / math.radians(5.0) * 8.0, 1.0) * (1 - abs(self.__lastKeyBoardAxis[HORIZONTAL_AXIS])) + self.__lastKeyBoardAxis[HORIZONTAL_AXIS] vAxis = clamp(-1.0, pitchAngle / math.radians(10.0), 1.0) * (1 - abs(self.__lastKeyBoardAxis[VERTICAL_AXIS])) + self.__lastKeyBoardAxis[VERTICAL_AXIS] rAxis = bool(InputMapping.g_instance.mouseSettings.ROLL_SPEED_CFC) * mouseRoll * (1 - abs(self.__lastKeyBoardAxis[ROLL_AXIS])) + self.__lastKeyBoardAxis[ROLL_AXIS] speedDirection = player.getWorldVector() speedDirection.normalise() dotX = clamp(-1.0, fmRotation.getAxisX().dot(speedDirection), 1.0) dotY = clamp(-1.0, fmRotation.getAxisY().dot(speedDirection), 1.0) angleX = abs(0.5 * math.pi - math.acos(dotX)) / math.radians(10.0) angleY = abs(0.5 * math.pi - math.acos(dotY)) / math.radians(35.0 / 2.0) signX = sign(dotX) signY = sign(dotY) hAxis = clamp(-1.0, hAxis - (1.0 - abs(hAxis)) * clamp(-1.0, signX * angleX, 1.0), 1.0) vAxis = clamp(-1.0, vAxis - (1.0 - abs(vAxis)) * clamp(-1.0, signY * angleY, 1.0), 1.0) mouseAngle = math.acos(clamp(-1.0, fmRotation.getAxisZ().dot(norm), 1.0)) equalizerAngle = 0.5 * (0.3 + 0.7 * InputMapping.g_instance.mouseSettings.RADIUS_OF_CONDUCTING) * BigWorld.projection().fov * InputMapping.g_instance.mouseSettings.EQUALIZER_ZONE_SIZE equalizer = max(0.0, (equalizerAngle - mouseAngle) / equalizerAngle) * clamp(-1.0, 3.0 * bool(InputMapping.g_instance.mouseSettings.EQUALIZER_FORCE) * player.roll / math.pi, 1.0) if equalizerAngle else 0.0 rAxis = clamp(-1.0, rAxis - (1.0 - abs(rAxis)) * equalizer, 1.0) self.__applyInputAxis(HORIZONTAL_AXIS, clamp(-1.0, hAxis, 1.0)) self.__applyInputAxis(ROLL_AXIS, clamp(-1.0, rAxis, 1.0)) self.__applyInputAxis(VERTICAL_AXIS, clamp(-1.0, vAxis, 1.0)) self.__applyInputAxis(FORCE_AXIS, self.__lastKeyBoardAxis[FORCE_AXIS]) automaticFlaps = False if InputMapping.g_instance.mouseSettings.AUTOMATIC_FLAPS: automaticFlaps = int(max(0.0, player.asymptoteVMaxPitch - abs(player.getRotationSpeed().y)) < 0.25 * player.asymptoteVMaxPitch) self.__applyInputAxis(FLAPS_AXIS, self.__lastKeyBoardAxis[FLAPS_AXIS] or automaticFlaps)
def __updateCursorAxis(self): if BigWorld.player( ).planeType == PLANE_TYPE.BOMBER and self._isRunning: if self._profile.battleMode == BATTLE_MODE.ASSAULT_MODE: cursor = self._cameraStrategy.cursorDirection hCursor = Math.Vector3(cursor) hCursor.y = 0 pitch = cursor.angle(hCursor) if pitch > FORCE_RUDDER_BOMBER_SETTINGS.get( sign(cursor.y), 100000): self._profile.sendExtraAxis(FORCE_AXIS, sign(cursor.y)) else: self._profile.sendExtraAxis(FORCE_AXIS, 0) else: self._profile.sendExtraAxis(FORCE_AXIS, 0)
def onAxisEvent(self, event): """handle joystick event""" device = self.__storedAxisDevice.get(event.deviceId, dict()) lastAxisSign = device.get(event.axis, 0) if lastAxisSign == 0: if abs(event.value) > InputMapping.HI_AXIS_BOUND: newAxisSign = sign(event.value) else: newAxisSign = 0 elif abs(event.value) < InputMapping.LOW_AXIS_BOUND: newAxisSign = 0 else: newAxisSign = sign(event.value) device[event.axis] = newAxisSign self.__storedAxisDevice[event.deviceId] = device if lastAxisSign != newAxisSign: if lastAxisSign != 0: self.__processAxisChange(event.deviceId, event.axis, lastAxisSign, False) self.__processAxisChange(event.deviceId, event.axis, newAxisSign, True)
def slipCompensationVisualisation(self): if self._isSlipComp and not self._notControlledByUser: owner = BigWorld.player() fmRotation = owner.getRotation() speedDirection = owner.getWorldVector() speedDirection.normalise() dotX = clamp(-1.0, fmRotation.getAxisX().dot(speedDirection), 1.0) dotY = clamp(-1.0, fmRotation.getAxisY().dot(speedDirection), 1.0) angleX = abs(math.pi / 2.0 - math.acos(dotX)) / math.radians(10.0) angleY = abs(math.pi / 2.0 - math.acos(dotY)) / math.radians( 35.0 / 2.0) signX = sign(dotX) signY = sign(dotY) hAxis = clamp( -1.0, self.__lastAxis[HORIZONTAL_AXIS] - self._isSlipComp * (1.0 - abs(self.__lastAxis[HORIZONTAL_AXIS])) * clamp(-1.0, signX * angleX, 1.0), 1.0) owner.applyInputAxis(HORIZONTAL_AXIS, hAxis) vAxis = clamp( -1.0, self.__lastAxis[VERTICAL_AXIS] - self._isSlipComp * (1.0 - abs(self.__lastAxis[VERTICAL_AXIS])) * clamp(-1.0, signY * angleY, 1.0), 1.0) owner.applyInputAxis(VERTICAL_AXIS, vAxis)
def getOutNormZone(self, direction, normAngle): halfNorm = normAngle norm = 2 * normAngle ld = self._toSectorLocal(direction) pitchDir = self._getPitchAngle(ld) yawDir = self._getYawAngle(ld) res = Math.Vector2(0, 0) pB = pitchDir + halfNorm pD = pitchDir - halfNorm if pB > self._pitchUp: res.y = clamp(-1, (pB - self._pitchUp) / norm, 1) elif pD < self._pitchDown: res.y = clamp(-1, (pD - self._pitchDown) / norm, 1) ySign = sign(yawDir) y = yawDir + ySign * halfNorm if self._yawRight < y or y < self._yawLeft: edgeAngle = self._yawRight if ySign >= 0 else self._yawLeft res.x = -clamp(-1, (y - edgeAngle) / norm, 1) return res
def brusUillisInAction(self, curr_health, max_health): effects = { 'screen_damage_overlife_01', 'screen_damage_overlife_02', 'screen_damage_overlife_03', 'screen_damage_overlife_04', 'screen_damage_overlife_05', 'screen_damage_overlife_06', 'screen_damage_overlife_07', 'screen_damage_overlife_08' } pr_cfc = 0.1 * max_health if curr_health <= max_health * 0.01: return range_effects = int((max_health - curr_health) / pr_cfc) - len( self.__brusUillisEffects) progress = sign(range_effects) > 0 for _ in xrange(abs(range_effects)): can_be_use = list(effects - self.__brusUillisEffects) if progress else list( self.__brusUillisEffects) if len(can_be_use): curr_effect = choice(can_be_use) if progress: self.__brusUillisEffects.add(curr_effect) else: self.__brusUillisEffects.remove(curr_effect) self._emInst.setScreenParticle(curr_effect, active=progress)
def __launch(self, shellIndex): shellType = self.getShellType(shellIndex) shellSettings = self.__shellsCommonData[shellIndex] if shellType == UPDATABLE_TYPE.BOMB and not isCorrectBombingAngle( self._owner, self._owner.controllers['flightModel'].rotation): self._owner.shellsCount[shellIndex] = self._owner.shellsCount[ shellIndex] / shellSettings['portion'] * shellSettings[ 'portion'] self._owner.onLaunchShell(shellIndex, 0) self._launchSequence[shellIndex].clear() return sequence = self._launchSequence[shellIndex] now = BigWorld.time() shellInShoot = 0 while sequence and sequence[0] <= now: sequence.popleft() shellInShoot += 1 updatableManager = self._owner.controllers['updatableManager'] shellGroup = self.__shellGroups[shellIndex] shellStartIndex = shellSettings['maxCount'] - self.getShellCount( shellIndex) dispersionAngle = self._getDispersionAngle(shellIndex) resourceId = shellSettings['resourceId'] for i in range(shellStartIndex, shellStartIndex + shellInShoot): if i < 0 or i >= len(shellGroup): LOG_ERROR('shoot error for airplane ', self._owner.globalID, 'with shellIndex = ', shellIndex, 'currShellCount = ', self.getShellCount(shellIndex), 'i = ', i, 'shellStartIndex = ', shellStartIndex, 'shellInShoot = ', shellInShoot, 'maxCount = ', shellSettings['maxCount']) shell = shellGroup[i] ownerRotation = Math.Quaternion(self._owner.rotation) startPosition = self._owner.position + ownerRotation.rotateVec( shell.posDelta) startVector = self._owner.vector * WORLD_SCALING if shellType == UPDATABLE_TYPE.ROCKET: axisAngle = random() * math.pi * 2.0 dispersionAxis = Math.Vector3(sin(axisAngle), cos(axisAngle), 0) angle = math.pow(random(), 1.5) * dispersionAngle dispersionRotation = Math.Quaternion() dispersionRotation.fromAngleAxis(angle, dispersionAxis) ownerRotation = ownerRotation.mul(dispersionRotation) startVector = ownerRotation.rotateVec( self._owner.reductionPointVector) startVector.normalise() startVector *= self._owner.vector.length * WORLD_SCALING startRotation = quat2Euler(ownerRotation) updatableManager.createUpdatableLocal(shellType, resourceId, startPosition, startVector, startRotation) else: accelerationV = getBombGravityAcceleration( self._owner.settings.airplane.planeType) zScaling = 1.0 + BOMB_Z_SCATTER_SCALING * hypot( startVector.x, startVector.z) / ( WORLD_SCALING * movementAbsToSpeed(VELLOCITY_OF_SOUND)) delta = abs(accelerationV.y * math.tan(dispersionAngle / 2.0)) probability = lambda x: sign(2.0 * x - 1.0) * pow( abs(2.0 * x - 1.0), 1.3) dispersionZ = probability(random()) * delta * zScaling dispersionX = probability(random()) * delta startRotation = quat2Euler(ownerRotation) updatableManager.createUpdatableLocal(shellType, resourceId, startPosition, startVector, startRotation, dispersionX, dispersionZ) self._owner.shellsCount[shellIndex] -= shellInShoot if shellInShoot > 0: self._owner.onLaunchShell(shellIndex, shellInShoot) return shellInShoot
def _update(self): planeDir = Vector3(self._player.getRotation().getAxisZ()) planeDir.y = 0 self._model.sightAngle = -math.degrees(self._player.roll) self._model.compassAngle = -sign(planeDir.dot(Vector3( 1, 0, 0))) * math.degrees(planeDir.angle(Vector3(0, 0, 1)))
def _getYawAngle(direction): xzProjection = Math.Vector3(direction.x, 0, direction.z) return sign(-direction.x) * xzProjection.angle(Math.Vector3(0, 0, 1))
def _getPitchAngle(direction): yzProjection = Math.Vector3(direction.x, 0, direction.z) return sign(direction.y) * direction.angle(yzProjection)