def get_3D_version(self, pos): pos = convert_pos(pos) x, y, z = pos dx, dy = Vector.from_2_points(self.location, (x, y)) verts = deepcopy(self.vertices) self._convert_to3d([(x + dx, y + dy, 0) for x, y in self.vertices]) new = LowerDimensional(self) self.vertices = verts return new
def move(self, dt): if self.hitbox is not None: old_pos = self.hitbox.shape.location self.hitbox.velocity = self.velocity self.hitbox.update(dt) trans = Vector.from_2_points(old_pos, self.hitbox.shape.location) self.position = tuple(trans + self.position) self.velocity = self.hitbox.velocity else: self.velocity *= dt self.position = tuple(self.velocity + self.position)
def do_collision(self, other, dt: float): """ Check and apply collision between to objects :param other: other Physical object :param dt: time frame of movement :return: """ trans = self.velocity if trans.magnitude( ) == 0 or not self.collideable or not other.collideable: return new_pos = Vector(self.shape.location) + trans if self.shape.distance(other.shape) < 0: perp = Vector.from_2_points( self.shape.get_nearest_point(other.shape.location), other.shape.get_nearest_point( self.shape.location)) # this is vector up to wall dis_traveled = trans.magnitude( ) # full dis travelled in this increment theta = perp.angle_to(trans) perp2 = deepcopy( perp) # this is the perp compoent of the initial trans perp2.resize(cos(radians(theta)) * dis_traveled) # this resizes it to the prwoper length horizontal = Vector.from_2_points( perp2 + self.shape.location, new_pos ) # this find the component of initial trans parallel to wall # horizontal contains a dis, make into vector print(self.velocity) self.velocity = (perp + horizontal) / dt print("collide:", self, other, self.velocity) if self.do_momentum: acceleration = ( perp2 - perp) / dt # acceleration is change in velocity over time push_force = self.get_acceleration_force(acceleration) friction = push_force * self.friction_coefficient self.apply_force(friction, dt) other.apply_force(push_force, dt)
def get_nearest_point(self, pt): v = Vector.from_2_points(self.location, pt) v.resize(self.radius) return v + self.location