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 catch(self): # noinspection PyProtectedMember if self.player._PlayerAvatar__autoAimVehID: return if BigWorld.target() is not None: return if self.player.isObserver(): return playerPosition = self.player.getOwnVehiclePosition() minRadian = 100000.0 result = None result_len = None for vId, vData in self.player.arena.vehicles.iteritems(): if vData['team'] != self.player.team and vData['isAlive']: vehicle = BigWorld.entity(vId) if vehicle is not None and vehicle.isStarted and vehicle.isAlive( ): radian = self.calc_radian( vehicle.position, self.angle) # 1.289 градуса в радианах if radian: length = Math.Vector3(vehicle.position - playerPosition).length if result_len is None: result_len = length result = vehicle if radian < minRadian and result_len >= length: minRadian = radian result = vehicle if config.data['catchHiddenTarget']: self.player.autoAim(result) return result if result is not None else None if result is not None and BigWorld.wg_collideSegment( self.player.spaceID, result.position, cameras.getWorldRayAndPoint(0, 0)[1], 128) is None: self.player.autoAim(result) return result if result is not None else None return
def calcVisibleAreaRatio(self): points = [ Math.Vector2(1, 1), Math.Vector2(1, -1), Math.Vector2(-1, -1), Math.Vector2(-1, 1) ] dirsPos = [getWorldRayAndPoint(point.x, point.y) for point in points] planeXZ = Plane(Math.Vector3(0, 1, 0), 0) collisionPoints = [] for dir, begPos in dirsPos: endPos = begPos + dir * 1000 testResult = BigWorld.wg_collideSegment(BigWorld.player().spaceID, begPos, endPos, 3) collPoint = Math.Vector3(0, 0, 0) if collPoint is not None: collPoint = testResult[0] else: collPoint = planeXZ.intersectSegment(begPos, endPos) collisionPoints.append(collPoint) x0 = abs(collisionPoints[1].x - collisionPoints[2].x) x1 = abs(collisionPoints[0].x - collisionPoints[3].x) z0 = abs(collisionPoints[0].z - collisionPoints[1].z) z1 = abs(collisionPoints[3].z - collisionPoints[2].z) bb = BigWorld.player().arena.arenaType.boundingBox arenaBottomLeft = bb[0] arenaUpperRight = bb[1] arenaX = arenaUpperRight[0] - arenaBottomLeft[0] arenaZ = arenaUpperRight[1] - arenaBottomLeft[1] return ((x0 + x1) * 0.5 / arenaX, (z0 + z1) * 0.5 / arenaZ)
def find_autoaim_target(self): auto_aim_vehicle = property(lambda self_other: BigWorld.entities.get(self_other.__autoAimVehID, None)) print('find_autoaim_target', auto_aim_vehicle) if auto_aim_vehicle is None and BigWorld.target() is not None: return BigWorld.target() player = BigWorld.player() vehicles = player.arena.vehicles camera_dir, camera_pos = cameras.getWorldRayAndPoint(0, 0) camera_dir.normalise() result_len = None las_vehicle = None min_radian = 100000.0 for vId, vData in vehicles.items(): if vData['team'] == player.team: continue vehicle = BigWorld.entity(vId) if vehicle is None or not vehicle.isStarted or not vehicle.isAlive(): continue temp1, radian = self._calc_radian(vehicle.position, self.angle_autoaim) #1.289 градуса в радианах if not temp1 and temp1 is not None: continue length = self._calc_length(vehicle.position, BigWorld.player().position) if radian: if result_len is None: result_len = length las_vehicle = vehicle if radian < min_radian and result_len >= length: min_radian = radian las_vehicle = vehicle result = las_vehicle if result is not None: if BigWorld.wg_collideSegment(BigWorld.player().spaceID, BigWorld.entity(result.id).appearance.modelsDesc['gun']['model'].position, camera_pos, False) is None: return result return BigWorld.target()
def calcVisibleAreaRatio(self): points = [Math.Vector2(1, 1), Math.Vector2(1, -1), Math.Vector2(-1, -1), Math.Vector2(-1, 1)] dirsPos = [ getWorldRayAndPoint(point.x, point.y) for point in points ] planeXZ = Plane(Math.Vector3(0, 1, 0), 0) collisionPoints = [] for dir, begPos in dirsPos: endPos = begPos + dir * 1000 testResult = BigWorld.wg_collideSegment(BigWorld.player().spaceID, begPos, endPos, 3) collPoint = Math.Vector3(0, 0, 0) if collPoint is not None: collPoint = testResult[0] else: collPoint = planeXZ.intersectSegment(begPos, endPos) collisionPoints.append(collPoint) x0 = abs(collisionPoints[1].x - collisionPoints[2].x) x1 = abs(collisionPoints[0].x - collisionPoints[3].x) z0 = abs(collisionPoints[0].z - collisionPoints[1].z) z1 = abs(collisionPoints[3].z - collisionPoints[2].z) bb = BigWorld.player().arena.arenaType.boundingBox arenaBottomLeft = bb[0] arenaUpperRight = bb[1] arenaX = arenaUpperRight[0] - arenaBottomLeft[0] arenaZ = arenaUpperRight[1] - arenaBottomLeft[1] return ((x0 + x1) * 0.5 / arenaX, (z0 + z1) * 0.5 / arenaZ)
def calc_radian(target_position, angle): cameraDir, cameraPos = cameras.getWorldRayAndPoint(0, 0) cameraDir.normalise() cameraToTarget = target_position - cameraPos dot = cameraToTarget.dot(cameraDir) if dot < 0: return targetRadian = cameraToTarget.lengthSquared radian = 1.0 - dot * dot / targetRadian if radian > angle: return return radian
def find_autoaimtarget(self): #AutoaimSelf._PlayerAvatar__autoAimVehID autoAimVehicle = property( lambda self: BigWorld.entities.get(self.__autoAimVehID, None)) if autoAimVehicle is None and BigWorld.target() is not None: return BigWorld.target() player = BigWorld.player() vehicles = player.arena.vehicles cameraDir, cameraPos = cameras.getWorldRayAndPoint(0, 0) cameraDir.normalise() result = None result_len = None las_vehicle = None minRadian = 100000.0 for vId, vData in vehicles.items(): if vData['team'] == player.team: continue vehicle = BigWorld.entity(vId) if vehicle is None or not vehicle.isStarted or not vehicle.isAlive(): continue temp1, Radian = calc_radian(vehicle.position, radians_angle_autoaim, minRadian) #1.289 градуса в радианах if temp1 == False: continue len = cacl_lengh(vehicle.position, BigWorld.player().position) if Radian: debugs('%s, distance: %dm., Angle = %.2f degrees' % (vehicle.id, len, math.degrees(Radian))) if result_len is None: result_len = len las_vehicle = vehicle if Radian < minRadian and result_len >= len: minRadian = Radian las_vehicle = vehicle debugs( 'Set priority: %s, distance: %dm., Angle = %.2f degrees' % (las_vehicle.id, result_len, math.degrees(minRadian))) result = las_vehicle #if BigWorld.wg_collideSegment(BigWorld.player().spaceID, result.position, cameraPos,False) == None: # debugs('get visible target: %s' % (result.id)) # return result if result is not None: if BigWorld.wg_collideSegment( BigWorld.player().spaceID, BigWorld.entity( result.id).appearance.modelsDesc['gun']['model'].position, cameraPos, False) == None: debugs('get visible gun target: %s' % (result.id)) return result debugs('target gun: %s not visible' % (result.id)) return BigWorld.target()
def pick(self): x, y = GUI.mcursor().position from AvatarInputHandler import cameras dir, start = cameras.getWorldRayAndPoint(x, y) end = start + dir.scale(100000.0) posColldata = collideDynamicAndStatic(start, end, (), 0) if posColldata is None: return (None, None) pos, collData = posColldata if collData is None or not collData.isVehicle(): return (None, None) return (collData[0], pos)
def _calc_radian(target_position, angle): camera_dir, camera_pos = cameras.getWorldRayAndPoint(0, 0) camera_dir.normalise() camera_to_target = target_position - camera_pos a = camera_to_target.dot(camera_dir) if a < 0: return False, None target_radian = camera_to_target.lengthSquared radian = 1.0 - a * a / target_radian if radian > angle: return False, None return True, radian
def calc_radian(target_position, angle, minRadian): cameraDir, cameraPos = cameras.getWorldRayAndPoint(0, 0) cameraDir.normalise() CameraToTarget = target_position - cameraPos a = CameraToTarget.dot(cameraDir) if a < 0: return False, None targetRadian = CameraToTarget.lengthSquared Radian = 1.0 - a * a / targetRadian if Radian > angle: return False, None return True, Radian
def pick(self): x, y = GUI.mcursor().position from AvatarInputHandler import cameras dir, start = cameras.getWorldRayAndPoint(x, y) end = start + dir.scale(100000.0) posColldata = collideDynamicAndStatic(start, end, (), 0) if posColldata is None: return (None, None) else: pos, collData = posColldata if collData is None or not collData.isVehicle(): return (None, None) return (collData[0], pos)
def getDistance(): global distance, getDistanceID if ownVehicle is not None: pos = GUI.mcursor().position direction, start = getWorldRayAndPoint(*pos) end = start + direction.scale(100000.0) point = collideDynamicAndStatic(start, end, (ownVehicle.id, ), 0) aimingPoint = point[0] if point is not None else shootInSkyPoint( start, direction) prevDistance = distance distance = int((aimingPoint - ownVehicle.position).length) if prevDistance != distance: as_event('ON_CROSSHAIR') getDistanceID = callback(0.1, getDistance)
def find_autoaimtarget(self): #AutoaimSelf._PlayerAvatar__autoAimVehID autoAimVehicle = property(lambda self: BigWorld.entities.get(self.__autoAimVehID, None)) if autoAimVehicle is None and BigWorld.target() is not None: return BigWorld.target() player = BigWorld.player() vehicles = player.arena.vehicles cameraDir, cameraPos = cameras.getWorldRayAndPoint(0, 0) cameraDir.normalise() result = None result_len = None las_vehicle = None minRadian = 100000.0 for vId, vData in vehicles.items(): if vData['team'] == player.team: continue vehicle = BigWorld.entity(vId) if vehicle is None or not vehicle.isStarted or not vehicle.isAlive(): continue temp1, Radian = calc_radian(vehicle.position, radians_angle_autoaim, minRadian) #1.289 градуса в радианах if temp1 == False: continue len = cacl_lengh(vehicle.position, BigWorld.player().position) if Radian: debugs('%s, distance: %dm., Angle = %.2f degrees' % (vehicle.id, len, math.degrees(Radian))) if result_len is None: result_len = len las_vehicle = vehicle if Radian < minRadian and result_len >= len: minRadian = Radian las_vehicle = vehicle debugs('Set priority: %s, distance: %dm., Angle = %.2f degrees' % (las_vehicle.id, result_len, math.degrees(minRadian))) result = las_vehicle #if BigWorld.wg_collideSegment(BigWorld.player().spaceID, result.position, cameraPos,False) == None: # debugs('get visible target: %s' % (result.id)) # return result if result is not None: if BigWorld.wg_collideSegment(BigWorld.player().spaceID, BigWorld.entity(result.id).appearance.modelsDesc['gun']['model'].position, cameraPos,False) == None: debugs('get visible gun target: %s' % (result.id)) return result debugs('target gun: %s not visible' % (result.id)) return BigWorld.target()
def getAimedAtPositionWithinBorders(aimOffsetX, aimOffsetY): ray, _ = getWorldRayAndPoint(aimOffsetX, aimOffsetY) player = BigWorld.player() staticHitPoint = BigWorld.wg_collideSegment( player.spaceID, BigWorld.camera().position, BigWorld.camera().position + ray * 100000, 128) if staticHitPoint is not None: staticHitPoint = staticHitPoint.closestPoint boundingBox = player.arena.arenaType.boundingBox if not boundingBox[0][0] <= staticHitPoint.x <= boundingBox[1][ 0] or not boundingBox[0][1] <= staticHitPoint.z <= boundingBox[ 1][1]: return return staticHitPoint else: return return
def find_autoaim_target(self): auto_aim_vehicle = property(lambda self_other: BigWorld.entities.get( self_other.__autoAimVehID, None)) print('find_autoaim_target', auto_aim_vehicle) if auto_aim_vehicle is None and BigWorld.target() is not None: return BigWorld.target() player = BigWorld.player() vehicles = player.arena.vehicles camera_dir, camera_pos = cameras.getWorldRayAndPoint(0, 0) camera_dir.normalise() result_len = None las_vehicle = None min_radian = 100000.0 for vId, vData in vehicles.items(): if vData['team'] == player.team: continue vehicle = BigWorld.entity(vId) if vehicle is None or not vehicle.isStarted or not vehicle.isAlive( ): continue temp1, radian = self._calc_radian( vehicle.position, self.angle_autoaim) #1.289 градуса в радианах if not temp1 and temp1 is not None: continue length = self._calc_length(vehicle.position, BigWorld.player().position) if radian: if result_len is None: result_len = length las_vehicle = vehicle if radian < min_radian and result_len >= length: min_radian = radian las_vehicle = vehicle result = las_vehicle if result is not None: if BigWorld.wg_collideSegment( BigWorld.player().spaceID, BigWorld.entity(result.id).appearance.modelsDesc['gun'] ['model'].position, camera_pos, False) is None: return result return BigWorld.target()
def tick(self): if not self.__enabled or not GUI.mcursor().inWindow or not GUI.mcursor( ).inFocus or not self._hangarSpace.isCursorOver3DScene: return else: cursorPosition = GUI.mcursor().position ray, wpoint = cameras.getWorldRayAndPoint(cursorPosition.x, cursorPosition.y) collidedId = None res = BigWorld.wg_collideDynamicStatic(self.spaceID, wpoint, wpoint + ray * 1000, 0, 0, -1, ColliderTypes.HANGAR_FLAG) if res is not None: collidedId = res[2] gameObjects = CGF.Query(self.spaceID, CGF.GameObject) for gameObject in gameObjects: if gameObject.id == collidedId: self._updateHoverComponent(gameObject, True) self._updateHoverComponent(gameObject, False) return
def getCursorWorldPos(self): x, y = GUI.mcursor().position dir, start = cameras.getWorldRayAndPoint(x, y) end = start + dir.scale(100000.0) return collideDynamicAndStatic(start, end, (), 0)