예제 #1
0
    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)
예제 #2
0
    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)