def worldHitTest(self, start, stop, worldMatrix, value=0): worldToLocal = Matrix(worldMatrix) worldToLocal.invert() testRes = self.__getBspModel(value).collideSegment( worldToLocal.applyPoint(start), worldToLocal.applyPoint(stop)) if testRes is None: return else: res = [] for dist, normal, hitAngleCos, matKind in testRes: res.append((dist, worldMatrix.applyVector(normal), hitAngleCos, matKind)) return res
def worldHitTest(self, start, stop, worldMatrix): worldToLocal = Matrix(worldMatrix) worldToLocal.invert() testRes = self.__bspModel.collideSegment(worldToLocal.applyPoint(start), worldToLocal.applyPoint(stop)) if testRes is None: return res = [] for dist, normal, hitAngleCos, matKind in testRes: res.append((dist, worldMatrix.applyVector(normal), hitAngleCos, matKind)) return res
def __pickVehicle(self): if self.__boundVehicleMProv is not None: return else: x, y = GUI.mcursor().position from AvatarInputHandler import cameras dir, start = cameras.getWorldRayAndPoint(x, y) end = start + dir.scale(100000.0) pos, colldata = collideDynamicAndStatic(start, end, (), 0) vehicle = None if colldata is not None: entity = colldata[0] from Vehicle import Vehicle if isinstance(entity, Vehicle): vehMatProv = entity.matrix vehMatInv = Matrix(vehMatProv) vehMatInv.invert() localPos = vehMatInv.applyPoint(pos) result = Math.MatrixProduct() localTransMat = Matrix() localTransMat.translation = localPos result.a = localTransMat result.b = vehMatProv return result return
def bind(self, vehicle, bindWorldPos = None): self.__vehicle = vehicle if vehicle is None: self.matrix = mathUtils.createIdentityMatrix() self.__lookAtProvider = None return toLocalMat = Matrix(vehicle.matrix) toLocalMat.invert() self.__boundLocalPos = None if bindWorldPos is None else toLocalMat.applyPoint(bindWorldPos) self.selectPlacement(_VehicleBounder.SELECT_CHASSIS)
def bind(self, vehicle, bindWorldPos = None): self.__vehicle = vehicle if vehicle is None: self.matrix = mathUtils.createIdentityMatrix() self.__lookAtProvider = None return else: toLocalMat = Matrix(vehicle.matrix) toLocalMat.invert() self.__boundLocalPos = None if bindWorldPos is None else toLocalMat.applyPoint(bindWorldPos) self.selectPlacement(_VehicleBounder.SELECT_CHASSIS) return
def collideSegment(self, startPoint, endPoint, skipGun=False): res = None filterMethod = getattr(self.filter, 'segmentMayHitEntity', lambda: True) if not filterMethod(startPoint, endPoint, 0): return res modelsToCheck = (self.model, ) if skipGun else (self.model, self.__gunModel) for model, desc in zip(modelsToCheck, self.__componentsDesc): toModel = Matrix(model.matrix) toModel.invert() collisions = desc['hitTester'].localHitTest( toModel.applyPoint(startPoint), toModel.applyPoint(endPoint)) if collisions is None: continue for dist, _, hitAngleCos, matKind in collisions: if res is None or res.dist >= dist: matInfo = desc['materials'].get(matKind) res = SegmentCollisionResult( dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res
def collideSegment(self, startPoint, endPoint, skipGun = False): res = None filterMethod = getattr(self.filter, 'segmentMayHitEntity', lambda : True) if not filterMethod(startPoint, endPoint, 0): return res modelsToCheck = (self.model,) if skipGun else (self.model, self.__gunModel) for model, desc in zip(modelsToCheck, self.__componentsDesc): toModel = Matrix(model.matrix) toModel.invert() collisions = desc['hitTester'].localHitTest(toModel.applyPoint(startPoint), toModel.applyPoint(endPoint)) if collisions is None: continue for dist, _, hitAngleCos, matKind in collisions: if res is None or res.dist >= dist: matInfo = desc['materials'].get(matKind) res = SegmentCollisionResult(dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res
def getVisibilityCheckPointsGen(vehicle): matrix = Matrix(vehicle.matrix) return chain( (vehicle.position, ), (matrix.applyPoint(pt) for pt in getVehiclePointsGen(vehicle)))
def new_showDamageFromShot(self, attackerID, points, effectsIndex, damageFactor, *a, **k): if LOG_EVENTS and attackerID > 0: player = BigWorld.player() #Initial info points_count = len(points) if points else 0 timeLeft, timeLeftSec = getTimeLeft() eventInfo = [ '%s' % player.arenaUniqueID, timeLeft, timeLeftSec, '"Vehicle.showDamageFromShot"', '%s' % player.arena.vehicles[self.id].get('accountDBID', '-'), '%s' % player.arena.vehicles[attackerID].get('accountDBID', '-'), json.dumps({ 'points': points_count, 'effectsIndex': effectsIndex, 'damageFactor': damageFactor }) ] #Decode info shellInfo = {} for shot in player.arena.vehicles[attackerID][ 'vehicleType'].gun.shots: if effectsIndex == shot.shell.effectsIndex: shellInfo['name'] = shot.shell.name shellInfo['kind'] = shellTypeAbb(shot.shell.kind) shellInfo['damage'] = str(shot.shell.damage) shellInfo['caliber'] = shot.shell.caliber shellInfo['piercingPower'] = str(shot.piercingPower) shellInfo['speed'] = round(shot.speed / 0.8, 3) shellInfo['gravity'] = round(shot.gravity / 0.64, 3) shellInfo['maxDistance'] = shot.maxDistance if shot.shell.kind == 'HIGH_EXPLOSIVE': shellInfo[ 'explosionRadius'] = shot.shell.type.explosionRadius break eventInfo.append(json.dumps(shellInfo) if shellInfo else '') maxHitEffectCode, decodedPoints, maxDamagedComponent = DamageFromShotDecoder.decodeHitPoints( points, self.appearance.collisions) hasPiercedHit = DamageFromShotDecoder.hasDamaged(maxHitEffectCode) attacker = BigWorld.entities.get(attackerID, None) attackerPos = attacker.position if isinstance( attacker, Vehicle ) and attacker.inWorld and attacker.isStarted else player.arena.positions.get( attackerID) eventInfo.append( json.dumps({ 'maxHitEffectCode': VEHICLE_HIT_EFFECT_NAMES.get(maxHitEffectCode), 'maxDamagedComponent': maxDamagedComponent, 'hasPiercedHit': hasPiercedHit, 'distance': round(self.position.distTo(attackerPos), 3) if attackerPos else None, 'hitPoints': [{ 'componentName': point.componentName, 'hitEffectGroup': point.hitEffectGroup } for point in decodedPoints] if decodedPoints else None })) for num, encodedPoint in enumerate(points, 1): hitsInfo = [] #[[Dir1-Layer1, ...], [Dir2-Layer1, ...], ...] hitsScheme = None compIdx, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment( encodedPoint, self.appearance.collisions, TankPartIndexes.ALL[-1]) if compIdx >= 0 and startPoint != endPoint: convertedCompIdx = DamageFromShotDecoder.convertComponentIndex( compIdx) bbox = self.appearance.collisions.getBoundingBox( convertedCompIdx) width, height, depth = (bbox[1] - bbox[0]) / 256.0 if COLLIDE_MULTI: if COLLIDE_SCHEME == 'hexahedron': hitsScheme = _CSHexahedron(width, height, depth, COLLIDE_SCALE) elif COLLIDE_SCHEME == 'cross': hitsScheme = _CSCross(width, height, depth, COLLIDE_SCALE) else: hitsScheme = _CSCenter() else: hitsScheme = _CSCenter() compMatrix = Matrix( self.appearance.compoundModel.node( TankPartIndexes.getName(convertedCompIdx))) firstHitDir = endPoint - startPoint firstHitDir.normalise() firstHitDir = compMatrix.applyVector(firstHitDir) firstHitPos = compMatrix.applyPoint(startPoint) for direction in hitsScheme.directions: hitInfo = [] collisions = self.appearance.collisions.collideAllWorld( firstHitPos - firstHitDir.scale(COLLIDE_INDENT) + direction, firstHitPos + firstHitDir.scale(COLLIDE_LENGTH) + direction) if collisions: base = None testPointAdded = collidePointAdded = False for collision in collisions: if collision[3] in TankPartIndexes.ALL: if base is None: base = collision[0] if not testPointAdded: if collision[0] > COLLIDE_INDENT: hitInfo.append( 'TestPoint%s(distance=%s, tankPart=%s)' % (num if points_count > 1 else '', round(COLLIDE_INDENT - base, 4), TankPartIndexes.getName( convertedCompIdx))) testPointAdded = True material = self.getMatinfo( collision[3], collision[2]) hitInfo.append({ 'distance': round(collision[0] - base, 4), 'angleCos': round(collision[1], 4), 'tankPart': TankPartIndexes.getName(collision[3]), 'armor': round(material.armor, 4) if material else None }) if not collidePointAdded: collidePointAdded = True if material and material.vehicleDamageFactor > 0 and collision[ 3] in (TankPartIndexes.HULL, TankPartIndexes.TURRET): break if collidePointAdded: if not testPointAdded and base is not None: hitInfo.append( 'TestPoint%s(distance=%s, tankPart=%s)' % (num if points_count > 1 else '', round(COLLIDE_INDENT - base, 4), TankPartIndexes.getName( convertedCompIdx))) hitsInfo.append(hitInfo) eventInfo.append(json.dumps('%s: %s' % ('TestPoint%d' % num if points_count > 1 else 'layers' if hitsScheme.NAME == 'center' else 'TestPoint', \ hitsScheme.format(hitsInfo[0] if hitsScheme.NAME == 'center' else hitsInfo) if hitsScheme else '[]'))) printStrings(LOG_EVENTS_FILENAME, eventInfo)