def __onDebugInfoReceived(self, argStr): from Math import Matrix, Vector3 positions = wgPickle.loads(wgPickle.FromServerToClient, argStr) for planeID, pos in positions: m = Matrix() m.setTranslate(pos) BigWorld.addPoint('spawnPoint%d' % planeID, m, 4278190335L, False)
class ArtyAimingSystem(StrategicAimingSystem): def __init__(self): super(ArtyAimingSystem, self).__init__(0.0, 0.0) self.__direction = Vector3(0.0, 0.0, 0.0) self.__aimMatrix = Matrix() @property def aimMatrix(self): return self.__aimMatrix @property def aimPoint(self): return self.__aimMatrix.translation @aimPoint.setter def aimPoint(self, point): self.__aimMatrix.setTranslate(point) @property def hitPoint(self): return self._matrix.translation @property def direction(self): return self.__direction def getDesiredShotPoint(self, terrainOnlyCheck=False): return self.__aimMatrix.translation def _updateMatrix(self): vehiclePosition = Vector3( BigWorld.player().getVehicleAttached().position) vehiclePosition.y = self._planePosition.y diff = self._planePosition - vehiclePosition if diff.lengthSquared < _MINIMAL_AIMING_RADIUS_SQ: diff.normalise() self._planePosition = vehiclePosition + diff * _MINIMAL_AIMING_RADIUS self._clampToArenaBB() hitPoint = BigWorld.wg_collideSegment( BigWorld.player().spaceID, self._planePosition + Vector3(0.0, 1000.0, 0.0), self._planePosition + Vector3(0.0, -250.0, 0.0), 128, 8) aimPoint = Vector3(self._planePosition) if hitPoint is not None: aimPoint.y = hitPoint.closestPoint[1] r0, v0, g0 = BigWorld.player().gunRotator.getShotParams(aimPoint, True) hitPoint = BigWorld.wg_simulateProjectileTrajectory( r0, v0, g0, SERVER_TICK_LENGTH, SHELL_TRAJECTORY_EPSILON_CLIENT, 128) if hitPoint is not None: time = (aimPoint.x - r0.x) / v0.x self.__direction = v0 + g0 * time self.__direction.normalise() self._matrix = mathUtils.createRTMatrix( (self.__direction.yaw, -self.__direction.pitch, 0.0), hitPoint[1]) self.__aimMatrix.setTranslate(aimPoint) return
def decodeHitPoints(encodedPoints, collisionComponent): resultPoints = [] maxHitEffectCode = None maxDamagedComponentName = None for encodedPoint in encodedPoints: compIdx, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment( encodedPoint, collisionComponent) if startPoint == endPoint or compIdx < 0: continue if hitEffectCode > maxHitEffectCode: maxHitEffectCode = hitEffectCode maxDamagedComponentName = TankPartIndexes.getName(compIdx) hitTestRes = collisionComponent.collideLocal( compIdx, startPoint, endPoint) bbox = collisionComponent.getBoundingBox(compIdx) if not hitTestRes or hitTestRes < 0.0: width, height, depth = (bbox[1] - bbox[0]) / 256.0 directions = [ Math.Vector3(0.0, -height, 0.0), Math.Vector3(0.0, height, 0.0), Math.Vector3(-width, 0.0, 0.0), Math.Vector3(width, 0.0, 0.0), Math.Vector3(0.0, 0.0, -depth), Math.Vector3(0.0, 0.0, depth) ] for direction in directions: hitTestRes = collisionComponent.collideLocal( compIdx, startPoint + direction, endPoint + direction) if hitTestRes >= 0.0: break if hitTestRes is None or hitTestRes < 0.0: newPoint = collisionComponent.collideLocalPoint( compIdx, startPoint, MAX_FALLBACK_CHECK_DISTANCE) if newPoint.length > 0.0: hitRay = endPoint - startPoint hitTestRes = hitRay.length endPoint = newPoint startPoint = endPoint - hitRay if hitTestRes is None or hitTestRes < 0.0: continue minDist = hitTestRes hitDir = endPoint - startPoint hitDir.normalise() rot = Matrix() rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0)) matrix = Matrix() matrix.setTranslate(startPoint + hitDir * minDist) matrix.preMultiply(rot) effectGroup = DamageFromShotDecoder.__hitEffectCodeToEffectGroup[ hitEffectCode] componentName = TankPartIndexes.getName(compIdx) resultPoints.append( DamageFromShotDecoder.ShotPoint(componentName, matrix, effectGroup)) return (maxHitEffectCode, resultPoints, maxDamagedComponentName)
def _setMarkerPosition(self, markerID, position): """Sets position of marker. :param markerID: integer containing unique ID of marker. :param position: Math.Vector3 containing new position. :return: """ matrix = Matrix() matrix.setTranslate(position) self._parentObj.setMarkerMatrix(markerID, matrix)
def decodeHitPoints(encodedPoints, vehicleDescr): resultPoints = [] maxHitEffectCode = None maxDamagedComponentName = None for encodedPoint in encodedPoints: compName, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment( encodedPoint, vehicleDescr) if startPoint == endPoint: continue if hitEffectCode > maxHitEffectCode: maxHitEffectCode = hitEffectCode maxDamagedComponentName = compName hitTester = getattr(vehicleDescr, compName).hitTester hitTestRes = hitTester.localHitTest(startPoint, endPoint) if not hitTestRes: width, height, depth = (hitTester.bbox[1] - hitTester.bbox[0]) / 256.0 directions = [ Math.Vector3(0.0, -height, 0.0), Math.Vector3(0.0, height, 0.0), Math.Vector3(-width, 0.0, 0.0), Math.Vector3(width, 0.0, 0.0), Math.Vector3(0.0, 0.0, -depth), Math.Vector3(0.0, 0.0, depth) ] for direction in directions: hitTestRes = hitTester.localHitTest( startPoint + direction, endPoint + direction) if hitTestRes is not None: break if hitTestRes is None: continue minDist = hitTestRes[0][0] for i in xrange(1, len(hitTestRes)): dist = hitTestRes[i][0] if dist < minDist: minDist = dist hitDir = endPoint - startPoint hitDir.normalise() rot = Matrix() rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0)) matrix = Matrix() matrix.setTranslate(startPoint + hitDir * minDist) matrix.preMultiply(rot) effectGroup = DamageFromShotDecoder.__hitEffectCodeToEffectGroup[ hitEffectCode] resultPoints.append( DamageFromShotDecoder.ShotPoint(compName, matrix, effectGroup)) return (maxHitEffectCode, resultPoints, maxDamagedComponentName)
def decodeHitPoints(encodedPoints, vehicleDescr): resultPoints = [] maxHitEffectCode = None for encodedPoint in encodedPoints: compName, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment( encodedPoint, vehicleDescr ) if startPoint == endPoint: continue maxHitEffectCode = max(hitEffectCode, maxHitEffectCode) hitTester = getattr(vehicleDescr, compName)["hitTester"] hitTestRes = hitTester.localHitTest(startPoint, endPoint) if not hitTestRes: width, height, depth = (hitTester.bbox[1] - hitTester.bbox[0]) / 256.0 directions = [ Math.Vector3(0.0, -height, 0.0), Math.Vector3(0.0, height, 0.0), Math.Vector3(-width, 0.0, 0.0), Math.Vector3(width, 0.0, 0.0), Math.Vector3(0.0, 0.0, -depth), Math.Vector3(0.0, 0.0, depth), ] for direction in directions: hitTestRes = hitTester.localHitTest(startPoint + direction, endPoint + direction) if hitTestRes is not None: break if hitTestRes is None: continue minDist = hitTestRes[0][0] for i in xrange(1, len(hitTestRes)): dist = hitTestRes[i][0] if dist < minDist: minDist = dist hitDir = endPoint - startPoint hitDir.normalise() rot = Matrix() rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0)) matrix = Matrix() matrix.setTranslate(startPoint + hitDir * minDist) matrix.preMultiply(rot) effectGroup = DamageFromShotDecoder.__hitEffectCodeToEffectGroup[hitEffectCode] resultPoints.append(DamageFromShotDecoder.ShotPoint(compName, matrix, effectGroup)) return (maxHitEffectCode, resultPoints)
def findTargets(self, actor, source, target): self.calculatedTargets = [] origin = source.position + Vector3(0, 0.5, 0) yaw = source.yaw + math.pi / 2.0 basis = Vector3(math.sin(yaw), 0, math.cos(yaw)) left = [] right = [] leftOver = self.maxNodes victims = [] if hasattr(self, 'victims'): victims = self.victims elif self.findTeam == 1: team = BigWorld.player().team() for i in team.members.keys(): entity = BigWorld.entity(i) if entity: if (entity.position - origin).length < self.maxRange: victims.append(entity) entity = BigWorld.player() if entity: if (entity.position - origin).length < self.maxRange: victims.append(entity) for e in victims: if e.inWorld: dpos = e.position - origin dpos.normalise() dotp = basis.dot(dpos) leftOver -= 2 try: self.calculatedTargets.append(e.model.node('biped Spine')) except: self.calculatedTargets.append(e.model.node('Scene Root')) while leftOver > 0: m = Matrix() if leftOver % 2 == 0: m.setTranslate(self.randomStrike(source, basis, origin, 1)) self.calculatedTargets.append(m) else: m.setTranslate(self.randomStrike(source, basis, origin, 0)) self.calculatedTargets.append(m) leftOver -= 1
class _DeathZoneMarkerHandler(object): sessionProvider = dependency.descriptor(IBattleSessionProvider) def __init__(self, zone): self._zone = zone self._matrix = None self._markerId = None areaMarkerCtrl = self.sessionProvider.shared.areaMarker if areaMarkerCtrl: self._matrix = Matrix() marker = areaMarkerCtrl.createMarker(self._matrix, MarkerItem.DEATHZONE) self._markerId = areaMarkerCtrl.addMarker(marker) areaMarkerCtrl.onTickUpdate += self._tickUpdate return def destroy(self): areaMarkerCtrl = self.sessionProvider.shared.areaMarker if areaMarkerCtrl and self._markerId is not None: areaMarkerCtrl.onTickUpdate -= self._tickUpdate areaMarkerCtrl.removeMarker(self._markerId) self._zone = None self._updateTI = None self._matrix = None self._markerId = None return def setVisible(self, visible): areaMarkerCtrl = self.sessionProvider.shared.areaMarker if areaMarkerCtrl and self._markerId is not None: if visible: areaMarkerCtrl.showMarkersById(self._markerId) else: areaMarkerCtrl.hideMarkersById(self._markerId) return def _tickUpdate(self): player = BigWorld.player() if player and self._matrix is not None: self._matrix.setTranslate( self._zone.getClosestPoint(player.getOwnVehiclePosition())) return
def setupFlag(self, position, flagSettings, color): self.__spaceID = flagSettings.spaceID self.__flagCompoundModel = flagSettings.flagCompounModel self.__flagCompoundModel.position = position self.__flagStaffFashion = BigWorld.WGAlphaFadeCompoundFashion() self.__flagFashion = BigWorld.WGFlagAlphaFadeFashion() self.__flagFashion.setColor(color) self.__flagFashion.setFlagBackgroundTexture( flagSettings.flagBackgroundTex) self.__flagFashion.setEmblemTexture(flagSettings.flagEmblemTex, flagSettings.flagEmblemTexCoords) translationMatrix = Matrix() translationMatrix.setTranslate(position) self.__flagFashion.overridePosition(translationMatrix) self.__flagCompoundModel.setupFashions( (self.__flagStaffFashion, self.__flagFashion)) self.__flagAnimator = flagSettings.flagAnim if self.__flagAnimator is not None: self.__flagAnimator.bindTo( AnimationSequence.PartWrapperContainer( self.__flagCompoundModel, self.__spaceID, flagSettings.flagAlias)) return
def createTranslationMatrix(translation): result = Matrix() result.setTranslate(translation) return result
def _setMarkerPos(self, handle, pos): matrix = Matrix() matrix.setTranslate(pos) self._parentObj.setMarkerMatrix(handle, matrix)
def decodeHitPoints(cls, encodedPoints, collisionComponent, maxComponentIdx=TankPartIndexes.ALL[-1], vehicleDesc=None): resultPoints = [] for encodedPoint in encodedPoints: compIdx, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment( encodedPoint, collisionComponent, maxComponentIdx, vehicleDesc) if startPoint == endPoint or compIdx < 0: continue convertedCompIdx = DamageFromShotDecoder.convertComponentIndex( compIdx, vehicleDesc) hitTestRes = collisionComponent.collideLocal( convertedCompIdx, startPoint, endPoint) bbox = collisionComponent.getBoundingBox(convertedCompIdx) if not hitTestRes or hitTestRes < 0.0: width, height, depth = (bbox[1] - bbox[0]) / 256.0 directions = [ Math.Vector3(0.0, -height, 0.0), Math.Vector3(0.0, height, 0.0), Math.Vector3(-width, 0.0, 0.0), Math.Vector3(width, 0.0, 0.0), Math.Vector3(0.0, 0.0, -depth), Math.Vector3(0.0, 0.0, depth) ] for direction in directions: hitTestRes = collisionComponent.collideLocal( convertedCompIdx, startPoint + direction, endPoint + direction) if hitTestRes >= 0.0: break if hitTestRes is None or hitTestRes < 0.0: newPoint = collisionComponent.collideLocalPoint( convertedCompIdx, startPoint, MAX_FALLBACK_CHECK_DISTANCE) if newPoint.length > 0.0: hitRay = endPoint - startPoint hitTestRes = hitRay.length endPoint = newPoint startPoint = endPoint - hitRay if hitTestRes is None or hitTestRes < 0.0: continue minDist = hitTestRes hitDir = endPoint - startPoint hitDir.normalise() rot = Matrix() rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0)) matrix = Matrix() matrix.setTranslate(startPoint + hitDir * minDist) matrix.preMultiply(rot) effectGroup = cls._HIT_EFFECT_CODE_TO_EFFECT_GROUP[hitEffectCode] componentName = TankPartIndexes.getName(compIdx) if not componentName and convertedCompIdx < 0: componentName = collisionComponent.getPartName( convertedCompIdx) if not componentName: componentName = TankPartNames.CHASSIS resultPoints.append( DamageFromShotDecoder.ShotPoint(componentName, matrix, hitEffectCode, effectGroup)) return resultPoints
def _setMarkerPosition(self, markerID, position): matrix = Matrix() matrix.setTranslate(position) self._parentObj.setMarkerMatrix(markerID, matrix)