87 lines
2.2 KiB
Python
87 lines
2.2 KiB
Python
from math import atan2, hypot, pi
|
|
|
|
|
|
class Vec:
|
|
def __init__(self, x: int | float | None = None, y: int | float | None = None, z: int | float | None = None) -> None:
|
|
if x != None:
|
|
self.new(x, y, z)
|
|
else:
|
|
self.x = 0
|
|
self.y = 0
|
|
self.z = 0
|
|
|
|
def new(self, x: int | float, y: int | float | None, z: int | float | None) -> None:
|
|
# Determine type of class
|
|
self.type = int
|
|
if type(x) == float:
|
|
self.type = float
|
|
|
|
# Verify other type
|
|
if type(y) != self.type:
|
|
raise TypeError
|
|
if y != None:
|
|
if type(y) != self.type:
|
|
raise TypeError
|
|
|
|
# At this point, they can't be None
|
|
if y == None:
|
|
raise TypeError
|
|
|
|
self.x = self.type(x)
|
|
self.y = self.type(y)
|
|
|
|
if z == None:
|
|
self.z = None
|
|
else:
|
|
self.z = self.type(z)
|
|
|
|
def plus(self, other: 'Vec') -> 'Vec':
|
|
x = self.x + other.x
|
|
y = self.y + other.y
|
|
|
|
if self.z == None or other.z == None:
|
|
return Vec(x, y)
|
|
|
|
return Vec(x, y, self.z + other.z)
|
|
|
|
def minus(self, other: 'Vec') -> 'Vec':
|
|
x = self.x - other.x
|
|
y = self.y - other.y
|
|
|
|
if self.z == None or other.z == None:
|
|
return Vec(x, y)
|
|
|
|
return Vec(x, y, self.z - other.z)
|
|
|
|
def div(self, val: float) -> 'Vec':
|
|
x = self.x / val
|
|
y = self.y / val
|
|
|
|
if self.z == None:
|
|
return Vec(x, y)
|
|
|
|
return Vec(x, y, self.z / val)
|
|
|
|
def to_angle(self):
|
|
if self.z == None:
|
|
raise TypeError
|
|
|
|
deg_to_rad = (180. / pi)
|
|
|
|
return Vec(
|
|
atan2(-self.z, hypot(self.x, self.y)) * deg_to_rad,
|
|
atan2(self.y, self.x) * deg_to_rad,
|
|
0
|
|
)
|
|
|
|
def is_zero(self):
|
|
xy = float(self.x) == 0. and float(self.y) == 0.
|
|
if self.z == None:
|
|
return xy
|
|
|
|
return xy and float(self.z) == 0.
|
|
|
|
|
|
def calculate_angle(local_pos: Vec, ennemy_pos: Vec, angles: Vec) -> Vec:
|
|
"""Angle calculation for aimbot"""
|
|
return ((ennemy_pos.minus(local_pos).to_angle().minus(angles)))
|