class BilliardTable: def __init__(self, width=450, length=300, height=2*BALL_RADIUS, center = [0.0, 0.0, 0.0]): self.width = width self.length = length self.height = height half_width = self.width/2. half_length = self.length/2. top_left_corner = [center[0] - half_width, -0.01, center[0] + half_length] top_right_corner = [center[0] + half_width, -0.01, center[0] + half_length] bottom_right_corner = [center[0] + half_width, -0.01, center[0] - half_length] bottom_left_corner = [center[0] - half_width, -0.01, center[0] - half_length] self.corners = [top_left_corner, bottom_left_corner, bottom_right_corner, top_right_corner] self.table = Quad(self.corners, billiard_green) # Calculates the balls collisions with the table def wallCollisionUpdate(self,ball): speed_module = ball.velToPolar()[0] dist_x = self.width/2. - abs(ball.coord[0]) dist_y = self.length/2. - abs(ball.coord[2]) if speed_module != 0: if dist_x/speed_module <= 1: ball.vel[0] = -ball.vel[0] if dist_y/speed_module <= 1: ball.vel[2] = -ball.vel[2] def isBallInPocket(self,ball): if ball.type is not BBallType.whitey and ball.type is not BBallType.black: for corner in self.corners: if distance(ball.coord,corner) <= 2*ball.radius: return True return False def draw(self): self.table.draw()
def __init__(self, width=450, length=300, height=2*BALL_RADIUS, center = [0.0, 0.0, 0.0]): self.width = width self.length = length self.height = height half_width = self.width/2. half_length = self.length/2. top_left_corner = [center[0] - half_width, -0.01, center[0] + half_length] top_right_corner = [center[0] + half_width, -0.01, center[0] + half_length] bottom_right_corner = [center[0] + half_width, -0.01, center[0] - half_length] bottom_left_corner = [center[0] - half_width, -0.01, center[0] - half_length] self.corners = [top_left_corner, bottom_left_corner, bottom_right_corner, top_right_corner] self.table = Quad(self.corners, billiard_green)