Esempio n. 1
0
    def get_cursor_id_from_self_and_kids(self, xy, absolute=False) -> str:
        if absolute:
            xy = util.sub(xy, self.get_xy(absolute=True))

        if not util.rect_contains((0, 0, *self.get_size()), xy):
            return None

        for c in self._children:
            r = c.get_rect()
            if util.rect_contains(r, xy):
                cursor_id = c.get_cursor_id_from_self_and_kids(util.sub(
                    xy, (r[0], r[1])),
                                                               absolute=False)
                if cursor_id is not None:
                    return cursor_id

        return self.get_cursor_id_at(xy)
Esempio n. 2
0
 def get_option_idx_at(self, xy, absolute=False):
     rel_xy = xy if not absolute else util.sub(xy, self.get_xy(
         absolute=True))
     for idx, opt in enumerate(self.options):
         rect = opt[0]
         if util.rect_contains(rect, rel_xy):
             return idx
     return None
Esempio n. 3
0
 def get_effective_rotation(self, camera_pos=(0, 0, 0)):
     towards_camera = util.set_length(util.sub(camera_pos, self.position()),
                                      1)
     rot_to_camera = matutils.get_xyz_rot_to_face_direction(
         towards_camera,
         do_pitch=self._vert_billboard,
         do_yaw=self._horz_billboard)
     return util.add(self.rotation(), rot_to_camera)
Esempio n. 4
0
    def send_click_to_self_and_kids(self,
                                    xy,
                                    absolute=False,
                                    button=1) -> bool:
        """returns: whether anything consumed the click"""
        if absolute:
            xy = util.sub(xy, self.get_xy(absolute=True))

        if not util.rect_contains((0, 0, *self.get_size()), xy):
            return False

        for c in self._children:
            r = c.get_rect()
            if util.rect_contains(r, xy):
                new_xy = util.sub(xy, (r[0], r[1]))
                if c.send_click_to_self_and_kids(new_xy,
                                                 absolute=False,
                                                 button=button):
                    return True

        return self.handle_click(xy, button=button)
Esempio n. 5
0
def get_matrix_looking_at2(eye_xyz, target_xyz, up_vec):
    n = util.set_length(util.sub(eye_xyz, target_xyz), 1)
    u = util.set_length(util.cross_prod(up_vec, n), 1)
    v = util.cross_prod(n, u)
    res = numpy.array(
        [[u[0], u[1], u[2],
          util.dot_prod(util.negate(u), eye_xyz)],
         [v[0], v[1], v[2],
          util.dot_prod(util.negate(v), eye_xyz)],
         [n[0], n[1], n[2],
          util.dot_prod(util.negate(n), eye_xyz)], [0, 0, 0, 1]],
        dtype=numpy.float32)
    return res
Esempio n. 6
0
 def cam_direction(t):
     target = (0, y(t), 10)  # a little ahead of the ship's position, with some vertical offset
     return util.set_length(util.sub(target, cam_position(t)), 1)  # point at ship