def coneMayHitVolume(boundingRadius, center, segmentStart, segmentEnd, startDeviation, endDeviation, do2DTest=True): segmentStart = segmentStart - center segmentEnd = segmentEnd - center if do2DTest: ao = Vector2(-segmentStart.x, -segmentStart.z) bo = Vector2(-segmentEnd.x, -segmentEnd.z) else: ao = segmentStart.scale(-1.0) bo = segmentEnd.scale(-1.0) ab = ao - bo e = ao.dot(ab) if e <= 0.0: return ao.lengthSquared <= (boundingRadius + startDeviation)**2 if e >= ab.lengthSquared: return bo.lengthSquared <= (boundingRadius + endDeviation)**2 d = math.sqrt(e / ab.lengthSquared) radiusSquared = (boundingRadius + (1.0 - d) * startDeviation + d * endDeviation)**2 return ao.lengthSquared - e * e / ab.lengthSquared <= radiusSquared
def getSectorIdByPosition(self, position, radius=None): pos2D = Vector2(position.x, position.z) sectors = sorted( self._sectors.values(), key=lambda s: (float('+inf') if s.isFreeZone else (Vector2(s.positionPoint.x, s.positionPoint.z) - pos2D).length)) for sector in sectors: if sector.geometry.isInside(position, radius): return sector.ident
def __init__(self, data=None): self.__camPresetInfo = {} self.__camPresetAmpFactorMin = 1.0 self.__normSpeedAddRelNeigbourZone = 0.0 self.__wakeParams = WakeEffectParams() self.__airwaveDistance = 0.0 self.blurSpeedCurve = Curve([Vector2(0.0, 0.0)]) self.blurHeightCurve = Curve([Vector2(0.0, 0.0)]) self.readData(data) self.__rammingEffectSplitter = 0.0
def getZoneBoundsFromId(arenaTypeID, zoneId): lowerLeft, upperRight = ArenaType.g_cache[arenaTypeID].boundingBox lowerLeft = Vector2(*lowerLeft) upperRight = Vector2(*upperRight) x = zoneId % ZONES_X y = zoneId / ZONES_X stepX, stepY = (upperRight - lowerLeft).tuple() stepX = stepX / ZONES_X stepY = stepY / ZONES_Y return (lowerLeft + Vector2(x * stepX, y * stepY), lowerLeft + Vector2( (x + 1) * stepX, (y + 1) * stepY))
def getBoundsFromHullPoints(hullPoints): coords0, coords1 = [], [] for hullPoint in hullPoints: coords0.append(hullPoint[0]) coords1.append(hullPoint[1]) coords0.sort() coords1.sort() bottomLeft = Vector2(coords0[0], coords1[0]) topRight = Vector2(coords0[-1], coords1[-1]) return (bottomLeft, topRight)
def segmentMayHitVolume(boundingRadius, center, segmentStart, segmentEnd): radiusSquared = boundingRadius radiusSquared *= radiusSquared segmentStart = segmentStart - center segmentEnd = segmentEnd - center ao = Vector2(-segmentStart.x, -segmentStart.z) bo = Vector2(-segmentEnd.x, -segmentEnd.z) ab = ao - bo e = ao.dot(ab) if e <= 0.0: return ao.lengthSquared <= radiusSquared return bo.lengthSquared <= radiusSquared if e >= ab.lengthSquared else ao.lengthSquared - e * e / ab.lengthSquared <= radiusSquared
def _VehicleGunRotator__getGunMarkerPosition(base, self, shotPos, shotVec, dispersionAngles): if not (config.get('sight/enabled', True) and battle.isBattleTypeSupported): return base(self, shotPos, shotVec, dispersionAngles) try: global timeFlight, currentDistance, timeAIM, cameraHeight shotDescr = player.getVehicleDescriptor().shot gravity = Vector3(0.0, -shotDescr.gravity, 0.0) testVehicleID = self.getAttachedVehicleID() collisionStrategy = CollisionStrategy.COLLIDE_DYNAMIC_AND_STATIC minBounds, maxBounds = player.arena.getSpaceBB() endPos, direction, collData, usedMaxDistance = getCappedShotTargetInfos( shotPos, shotVec, gravity, shotDescr, testVehicleID, minBounds, maxBounds, collisionStrategy) distance = shotDescr.maxDistance if usedMaxDistance else ( endPos - shotPos).length dispersAngle, idealDispersAngle = dispersionAngles doubleDistance = distance + distance markerDiameter = doubleDistance * dispersAngle idealMarkerDiameter = doubleDistance * idealDispersAngle replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying and replayCtrl.isClientReady: markerDiameter, endPos, direction = replayCtrl.getGunMarkerParams( endPos, direction) shotVecXZ = Vector2(shotVec.x, shotVec.z) delta = Vector2(endPos.x - shotPos.x, endPos.z - shotPos.z) timeFlight = delta.length / shotVecXZ.length aimingStartTime, aimingFactor, shotDispMultiplierFactor, _1, _2, _3, aimingTime = player._PlayerAvatar__aimingInfo # aimingStartTime = aimingInfo[0] # aimingFactor = aimingInfo[1] # shotDispMultiplierFactor = aimingInfo[2] # unShotDispersionFactorsTurretRotation = aimingInfo[3] # chassisShotDispersionFactorsMovement = aimingInfo[4] # chassisShotDispersionFactorsRotation = aimingInfo[5] # aimingTime = aimingInfo[6] aimingTimeAll = math.log( aimingFactor / shotDispMultiplierFactor) * aimingTime aimingFinishTime = aimingTimeAll + aimingStartTime timeAIM = max(0.0, aimingFinishTime - BigWorld.time()) cameraHeight = camera.position.y - endPos.y currentDistance = distance as_event('ON_MARKER_POSITION') if isDisplaySphere: update_sphere(endPos) except Exception as ex: err(traceback.format_exc()) return base(self, shotPos, shotVec, dispersionAngles) return endPos, direction, markerDiameter, idealMarkerDiameter, collData
def segmentMayHitVehicle(vehicleDescr, segmentStart, segmentEnd, vehicleCenter): radiusSquared = vehicleDescr.boundingRadius radiusSquared *= radiusSquared segmentStart = segmentStart - vehicleCenter segmentEnd = segmentEnd - vehicleCenter ao = Vector2(-segmentStart.x, -segmentStart.z) bo = Vector2(-segmentEnd.x, -segmentEnd.z) ab = ao - bo e = ao.dot(ab) if e <= 0.0: return ao.lengthSquared <= radiusSquared if e >= ab.lengthSquared: return bo.lengthSquared <= radiusSquared return ao.lengthSquared - e * e / ab.lengthSquared <= radiusSquared
def _VehicleGunRotator__getGunMarkerPosition(base, self, shotPos, shotVec, dispersionAngles): if not (config.get('sight/enabled', True) and battle.isBattleTypeSupported): return base(self, shotPos, shotVec, dispersionAngles) try: global timeFlight, currentDistance, cameraHeight prevTimeFlight, prevCurrentDistance, prevCameraHeight = timeFlight, currentDistance, cameraHeight shotDescr = self._avatar.getVehicleDescriptor().shot gravity = Vector3(0.0, -shotDescr.gravity, 0.0) testVehicleID = self.getAttachedVehicleID() collisionStrategy = CollisionStrategy.COLLIDE_DYNAMIC_AND_STATIC minBounds, maxBounds = BigWorld.player().arena.getSpaceBB() endPos, direction, collData, usedMaxDistance = getCappedShotTargetInfos( shotPos, shotVec, gravity, shotDescr, testVehicleID, minBounds, maxBounds, collisionStrategy) distance = shotDescr.maxDistance if usedMaxDistance else ( endPos - shotPos).length dispersAngle, idealDispersAngle = dispersionAngles doubleDistance = distance + distance markerDiameter = doubleDistance * dispersAngle idealMarkerDiameter = doubleDistance * idealDispersAngle replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying and replayCtrl.isClientReady: markerDiameter, endPos, direction = replayCtrl.getGunMarkerParams( endPos, direction) shotVecXZ = Vector2(shotVec.x, shotVec.z) delta = Vector2(endPos.x - shotPos.x, endPos.z - shotPos.z) timeFlight = delta.length / shotVecXZ.length cameraHeight = BigWorld.camera().position.y - endPos.y currentDistance = distance try: update = not (-0.01 < (prevTimeFlight - timeFlight) < 0.01) update = update or not (-0.01 < (prevCurrentDistance - currentDistance) < 0.01) update = update or not (-0.01 < (prevCameraHeight - cameraHeight) < 0.01) except Exception: update = True if update: as_event('ON_MARKER_POSITION') except Exception as ex: err(traceback.format_exc()) return base(self, shotPos, shotVec, dispersionAngles) return endPos, direction, markerDiameter, idealMarkerDiameter, collData
def __init__(self, position, equipment, direction=_DEFAULT_STRIKE_DIRECTION): super(_ArenaBoundsAreaStrikeSelector, self).__init__(position, equipment, direction) self.__arena = BigWorld.player().arena self.__wasInsideArenaBounds = True self.__outFromBoundsAimArea = None self.__insetRadius = 0 size = Vector2(equipment.areaWidth, equipment.areaLength) visualPath = equipment.areaVisual color = None if isinstance(equipment, ArcadeEquipmentConfigReader): aimLimits = equipment.arenaAimLimits if aimLimits: self.__insetRadius = aimLimits.insetRadius color = aimLimits.areaColor if aimLimits.areaSwitch: visualPath = aimLimits.areaSwitch else: LOG_WARNING( "Equipment:'{}' is using '{}' strike selector, but doesn't have '{}' params" .format(equipment, _ArenaBoundsAreaStrikeSelector.__name__, ArcadeEquipmentConfigReader.__name__)) self.__outFromBoundsAimArea = CombatSelectedArea() self.__outFromBoundsAimArea.setup(position, direction, size, visualPath, color, marker=None) self.__outFromBoundsAimArea.setGUIVisible(False) self.__updatePositionsAndVisibility(position) return
def getReducedPolygon(self, value): xVertexes = [vertex.x for vertex in self._vertexes2D] yvertexes = [vertex.y for vertex in self._vertexes2D] min_x = min(xVertexes) + value max_x = max(xVertexes) - value min_y = min(yvertexes) + value max_y = max(yvertexes) - value reducedPolygon = SectorGeometryPolygon(None) newVertexes2D = [ Vector2(min_x, min_y), Vector2(max_x, min_y), Vector2(max_x, max_y), Vector2(min_x, max_y) ] reducedPolygon.vertexes2D = newVertexes2D return reducedPolygon
def __init__(self, dataSec, defaultOffset=None, binoculars=None): CallbackDelayer.__init__(self) self.__impulseOscillator = None self.__movementOscillator = None self.__noiseOscillator = None self.__dynamicCfg = CameraDynamicConfig() self.__accelerationSmoother = None self.__readCfg(dataSec) if binoculars is None: return else: self.__cam = BigWorld.FreeCamera() self.__zoom = self.__cfg['zoom'] self.__curSense = 0 self.__curScrollSense = 0 self.__waitVehicleCallbackId = None self.__onChangeControlMode = None self.__aimingSystem = None self.__binoculars = binoculars self.__defaultAimOffset = defaultOffset or Vector2() self.__crosshairMatrix = createCrosshairMatrix( offsetFromNearPlane=self.__dynamicCfg['aimMarkerDistance']) self.__prevTime = BigWorld.time() self.__autoUpdateDxDyDz = Vector3(0, 0, 0) if BattleReplay.g_replayCtrl.isPlaying: BattleReplay.g_replayCtrl.setDataCallback( 'applyZoom', self.__applySerializedZoom) return
def __init__(self, dataSec, aim): CallbackDelayer.__init__(self) TimeDeltaMeter.__init__(self) self.__shiftKeySensor = None self.__movementOscillator = None self.__impulseOscillator = None self.__noiseOscillator = None self.__dynamicCfg = CameraDynamicConfig() self.__accelerationSmoother = None self.__readCfg(dataSec) if aim is None: return self.__aim = weakref.proxy(aim) self.__cam = BigWorld.HomingCamera() aimOffset = self.__aim.offset() self.__cam.aimPointClipCoords = Vector2(aimOffset) self.__curSense = 0 self.__curScrollSense = 0 self.__defaultAimOffset = (aimOffset[0], aimOffset[1]) self.__postmortemMode = False self.__modelsToCollideWith = [] self.__onChangeControlMode = None self.__aimingSystem = None self.__focalPointDist = 1.0 self.__autoUpdateDxDyDz = Vector3(0.0)
def _createTerrainSelectedArea(self, position, size, overTerrainHeight, color, terrainSelected=True): if self.__radiusModelName is None: return elif g_ctfManager.isNeedHideAll: return else: self.__fakeModel = BigWorld.Model('objects/fake_model.model') self.__fakeModel.position = position BigWorld.addModel(self.__fakeModel, BigWorld.player().spaceID) self.__fakeModel.addMotor( BigWorld.Servo(Math.Matrix(self.__fakeModel.matrix))) rootNode = self.__fakeModel.node('') self.__terrainSelectedArea = BigWorld.PyTerrainSelectedArea() self.__terrainSelectedArea.setup(self.__radiusModelName, Vector2(size, size), overTerrainHeight, color, terrainSelected) rootNode.attach(self.__terrainSelectedArea) self.__hideListener = _GlobalHideListener(self.__hideCheckPoint) return
def __init__(self, dataSec, defaultOffset=None): CallbackDelayer.__init__(self) TimeDeltaMeter.__init__(self) self.__shiftKeySensor = None self.__movementOscillator = None self.__impulseOscillator = None self.__noiseOscillator = None self.__dynamicCfg = CameraDynamicConfig() self.__accelerationSmoother = None self.__readCfg(dataSec) self.__onChangeControlMode = None self.__aimingSystem = None self.__curSense = 0 self.__curScrollSense = 0 self.__postmortemMode = False self.__vehiclesToCollideWith = set() self.__focalPointDist = 1.0 self.__autoUpdateDxDyDz = Vector3(0.0) self.__updatedByKeyboard = False if defaultOffset is not None: self.__defaultAimOffset = defaultOffset self.__cam = BigWorld.HomingCamera() self.__cam.aimPointClipCoords = defaultOffset else: self.__defaultAimOffset = Vector2() self.__cam = None return
def onEnterWorld(self, prereqs): self.model = prereqs[_g_stepRepairPointSettings.flagModel] self.model.position = self.position if _g_stepRepairPointSettings.flagAnim is not None: try: clipResource = self.model.deprecatedGetAnimationClipResource( _g_stepRepairPointSettings.flagAnim) if clipResource: loader = AnimationSequence.Loader( clipResource, BigWorld.player().spaceID) self.__animator = loader.loadSync() self.__animator.bindTo( AnimationSequence.ModelWrapperContainer(self.model)) self.__animator.start() except Exception: LOG_WARNING( 'Unable to start "%s" animation action for model "%s"' % (_g_stepRepairPointSettings.flagAnim, _g_stepRepairPointSettings.flagModel)) self.__terrainSelectedArea = BigWorld.PyTerrainSelectedArea() self.__terrainSelectedArea.setup( _g_stepRepairPointSettings.radiusModel, Vector2(self.radius * 2.0, self.radius * 2.0), self._OVER_TERRAIN_HEIGHT, self._COLOR) self.model.root.attach(self.__terrainSelectedArea) return
def __onProtectionZoneAdded(self, zoneId, position, bound): zone = self.__protectionZones[zoneId] protectionZone = self.__protectionZoneComponent.getProtectionZoneById( zoneId) zone.team = protectionZone.team zone.geometry = (Vector2(position.x, position.z), bound[0], bound[1], bound[1] - bound[0]) zone.mappedState = MAPPED_SECTOR_STATE.GOOD if self.__teamId == protectionZone.team else MAPPED_SECTOR_STATE.BAD
def center(self): """ :rtype: Vector2 """ x = self._boundingBox[2] - self._boundingBox[0] z = self._boundingBox[3] - self._boundingBox[1] return Vector2(self._boundingBox[0] + x / 2, self._boundingBox[1] + z / 2)
def processSelection(self, position, reset=False): direction = Vector2(self.direction.x, self.direction.z) direction.normalise() BigWorld.player().setEquipmentApplicationPoint(self.equipment.id[1], self.area.position, direction) self.writeStateToReplay() return True
def processSelection(self, position, reset=False): self.hitPosition = position if reset: return False BigWorld.player().setEquipmentApplicationPoint(self.equipment.id[1], self.hitPosition, Vector2(0, 1)) return True
def __calcAimOffset(self, aimLocalTransform=None): aimingSystemMatrix = self.__aimingSystem.matrix worldCrosshair = Matrix(self.__crosshairMatrix) if aimLocalTransform is not None: worldCrosshair.postMultiply(aimLocalTransform) worldCrosshair.postMultiply(aimingSystemMatrix) aimOffset = cameras.projectPoint(worldCrosshair.translation) return Vector2(math_utils.clamp(-0.95, 0.95, aimOffset.x), math_utils.clamp(-0.95, 0.95, aimOffset.y))
def __init__(self, section): readValue(self, section, 'ROLL_AXIS', 0) readValue(self, section, 'ALLOW_LEAD', 0) readValue(self, section, 'INVERT_ROLL', 0) readValue(self, section, 'ROLL_SENSITIVITY', 0.0) readValue(self, section, 'ROLL_DEAD_ZONE', 0.05) readValue(self, section, 'VERTICAL_AXIS', 2) readValue(self, section, 'INVERT_VERTICAL', 0) readValue(self, section, 'VERTICAL_SENSITIVITY', 0.0) readValue(self, section, 'VERTICAL_DEAD_ZONE', 0.05) readValue(self, section, 'FORCE_AXIS', 1) readValue(self, section, 'INVERT_FORCE', 0) readValue(self, section, 'FORCE_SENSITIVITY', 0.0) readValue(self, section, 'FORCE_DEAD_ZONE', 0.05) readValue(self, section, 'HORIZONTAL_AXIS', 3) readValue(self, section, 'INVERT_HORIZONTAL', 0) readValue(self, section, 'HORIZONTAL_SENSITIVITY', 0.0) readValue(self, section, 'HORIZONTAL_DEAD_ZONE', 0.05) readValueOnCondition(self, section, 'CAMERA_TYPE', cameraTypeCondition, default=0) readValue(self, section, 'MOUSE_SENSITIVITY', 1.0) readValue(self, section, 'MOUSE_INVERT_VERT', False) readValue(self, section, 'AUTOMATIC_FLAPS', True) readValue(self, section, 'RADIUS_OF_CONDUCTING', 1.0) readValue(self, section, 'CAMERA_FLEXIBILITY', 1.0) readValue(self, section, 'EQUALIZER_ZONE_SIZE', 0.75) readValue(self, section, 'ROLL_SPEED_CFC', 1.0) readValue(self, section, 'EQUALIZER_FORCE', 1.0) readValue(self, section, 'SHIFT_TURN', True) readValue(self, section, 'SAFE_ROLL_ON_LOW_ALTITUDE', True) readValueOnCondition( self, section, 'MOUSE_INTENSITY_SPLINE', curveCondition, default=Curve( [Vector2(0.0, 1.0), Vector2(1.0, 1.0)], MOUSE_INTENSITY_SPLINE_POINT_COUNT)) readValue(self, section, 'CAMERA_ROLL_SPEED', 0.5) readValue(self, section, 'CAMERA_ANGLE', 1.0) readValue(self, section, 'CAMERA_ACCELERATION', 0.0) readValue(self, section, 'METHOD_OF_MIXING', 1)
def getTurretZoneRectangle(self, direction): if self._turret is None: return Vector2(1, 1) else: normAngle = self._context.turretControlAimConeAngle ir = Quaternion(self._context.baseRotation) ir.invert() direction = ir.rotateVec(direction) return self._context.getOutNormZone(direction, normAngle)
def _createTerrainSelectedArea(self, position, size, overTerrainHeight, color): if self.__radiusModelName is None: return self.__fakeModel = BigWorld.Model('objects/fake_model.model') self.__fakeModel.position = position BigWorld.addModel(self.__fakeModel, BigWorld.player().spaceID) rootNode = self.__fakeModel.node('') self.__terrainSelectedArea = BigWorld.PyTerrainSelectedArea() self.__terrainSelectedArea.setup(self.__radiusModelName, Vector2(size, size), overTerrainHeight, color) rootNode.attach(self.__terrainSelectedArea)
def __calculateAimOffset(self, aimWorldPos): replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying and replayCtrl.isControllingCamera: aimOffset = replayCtrl.getAimClipPosition() else: aimOffset = cameras.projectPoint(aimWorldPos) aimOffset = Vector2(mathUtils.clamp(-0.95, 0.95, aimOffset.x), mathUtils.clamp(-0.95, 0.95, aimOffset.y)) if replayCtrl.isRecording: replayCtrl.setAimClipPosition(aimOffset) return aimOffset
def createEquipmentSelectedArea(pos, direction, equipment): area = CombatSelectedArea.CombatSelectedArea() size = Vector2(equipment.areaWidth, equipment.areaLength) visual = equipment.areaVisual color = equipment.areaColor if visual is None: visual = CombatSelectedArea.DEFAULT_RADIUS_MODEL if color is None: pass area.setup(pos, direction, size, visual, color, None) return area
def onEnterWorld(self, prereqs): self.model = prereqs[_g_stepRepairPointSettings.flagModel] self.model.position = self.position if _g_stepRepairPointSettings.flagAnim is not None: self.__animator = prereqs[_g_stepRepairPointSettings.flagAnim] self.__animator.bindTo(AnimationSequence.CompoundWrapperContainer(self.model)) self.__animator.start() self.__terrainSelectedArea = BigWorld.PyTerrainSelectedArea() self.__terrainSelectedArea.setup(_g_stepRepairPointSettings.radiusModel, Vector2(self.radius * 2.0, self.radius * 2.0), self._OVER_TERRAIN_HEIGHT, self._COLOR) self.model.root.attach(self.__terrainSelectedArea) return
def __calculateAimOffset(self, aimWorldPos): if not self.isAimOffsetEnabled: return Vector2(0.0, 0.0) replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying and replayCtrl.isControllingCamera: aimOffset = replayCtrl.getAimClipPosition() else: proj = BigWorld.projection() aimLocalPos = Matrix(self.__cam.matrix).applyPoint(aimWorldPos) if aimLocalPos.z < 0: aimLocalPos.z = max(0.0, proj.nearPlane - _OFFSET_FROM_NEAR_PLANE) aimWorldPos = Matrix( self.__cam.invViewMatrix).applyPoint(aimLocalPos) aimOffset = cameras.projectPoint(aimWorldPos) aimOffset = Vector2(math_utils.clamp(-0.95, 0.95, aimOffset.x), math_utils.clamp(-0.95, 0.95, aimOffset.y)) if replayCtrl.isRecording: replayCtrl.setAimClipPosition(aimOffset) return aimOffset
def __init__(self, radius): self.__areaVisual = visual = BigWorld.PyTerrainSelectedArea() visual.setup(g_inspireVisualSettings.modelPath, Vector2(radius + radius, radius + radius), g_inspireVisualSettings.overTerrainHeight, g_inspireVisualSettings.color) visual.enableAccurateCollision( g_inspireVisualSettings.enableAccurateCollision) self.__fakeModel = BigWorld.Model('') self.__fakeModel.node('').attach(self.__areaVisual) self.__callbackID = None return
def onEnterWorld(self, prereqs): self.capturePercentage = float(self.pointsPercentage) / 100 if self.__isCapturedOnStart != self.isCaptured: self.set_isCaptured(self.__isCapturedOnStart) teamParams = self.__getTeamParams() flagSettings = FlagSettings(prereqs[_g_sectorBaseSettings.flagStaffModelName], _g_sectorBaseSettings.flagNodeAliasName, prereqs[_g_sectorBaseSettings.flagAnim], _g_sectorBaseSettings.flagBackgroundTex, _g_sectorBaseSettings.flagEmblemTex, _g_sectorBaseSettings.flagEmblemTexCoords, self.spaceID) self.__flagModel.setupFlag(self.position, flagSettings, teamParams[0]) self.__terrainSelectedArea = BigWorld.PyTerrainSelectedArea() self.__terrainSelectedArea.setup(_g_sectorBaseSettings.radiusModel, Vector2(self.radius * 2.0, self.radius * 2.0), self._OVER_TERRAIN_HEIGHT, teamParams[0]) self.__flagModel.model.root.attach(self.__terrainSelectedArea) self.model = self.__flagModel.model self.__flagModel.startFlagAnimation()