def update(self): """Update the rotation of the label to always be pointing to the camera. """ context = Context.get_instance() c_pos = context.camera.position direction = Vec(c_pos.x, c_pos.y, c_pos.z, 1) direction.norm() z_axis = Vec(0, 0, 1) # Find the angle between the camera and the health bar, then rotate it. # NOTE: also scaling and tranlsation are applied here. angle = math.acos(z_axis.dot(direction)) t = self.node.transform t.identity() t.translate(self.translation) t.rotate(Vec(1, 0, 0), angle) t.scale(self.scale)
def update(self, dt): """Updates the health bar. :param dt: Time delta from last update. :type dt: float """ context = Context.get_instance() c_pos = context.camera.position direction = Vec(c_pos.x, c_pos.y, c_pos.z, 1) direction.norm() z_axis = Vec(0, 0, 1) # Find the angle between the camera and the health bar, then rotate it. angle = math.acos(z_axis.dot(direction)) t = self[Renderable].transform t.identity() t.translate(Vec(-self.w / 2, self.y_offset, 0)) t.rotate(Vec(1, 0, 0), angle)
def in_triangle(point, triangle): """Checks if a specified point is inside a triangle using the barycenter technique. :param point: The point to be checked :type point: list :param triangle: The triangle :type triangle: list :returns: True if the point is inside the triangle. :rtype: bool """ A, B, C = map(lambda t: Vec(*t), triangle) P = Vec(*point) u = B - A v = C - A w = P - A vxw = v.cross(w) vxu = v.cross(u) if vxw.dot(vxu) < 0: return False uxw = u.cross(w) uxv = u.cross(v) if uxw.dot(uxv) < 0: return False denom = uxv.mag() r = vxw.mag() / denom t = uxw.mag() / denom return (r + t <= 1)
def is_degenerate(triangle): """Checks if the triangle is degenerate. :param triangle: The triangle to be checked. :type triangle: list :returns: Wether the triangle is degenerate or not :rtype: bool """ A, B, C = map(lambda t: Vec(*t), triangle) u = B - A v = C - A uxv = u.cross(v) return uxv.mag() == 0